Skip to content

Commit

Permalink
feat(bling.ts): add logic to prevent multiple instantiations of the s…
Browse files Browse the repository at this point in the history
…ame entity
  • Loading branch information
vitorsanc-beuni committed Oct 19, 2021
1 parent ed37024 commit 4ec9211
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import axios, { AxiosInstance } from 'axios'
import createError from './core/createError'

export default class Bling {
private api: AxiosInstance
#api: AxiosInstance
#products: Products | undefined
#orders: Orders | undefined

constructor (apiKey: string) {
if (!apiKey || typeof apiKey !== 'string') {
Expand All @@ -28,18 +30,23 @@ export default class Bling {
apikey: apiKey,
...config.params
}

return config
})

this.api = api
this.#api = api
}

public products () {
return new Products(this.api)
if (!this.#products) {
this.#products = new Products(this.#api)
}
return this.#products
}

public orders () {
return new Orders(this.api)
if (!this.#orders) {
this.#orders = new Orders(this.#api)
}
return this.#orders
}
}
11 changes: 8 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"allowJs": true
},
"include": ["src"],
"exclude": ["node_modules", "test/*"]
"include": [
"src"
],
"exclude": [
"node_modules",
"test/*"
]
}

0 comments on commit 4ec9211

Please sign in to comment.