-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.0.0] feat(Singleton): implement the API wrapper as a singleton #88
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👏🏼
README.md
Outdated
|
||
Instead of creating an instance of the `IncogniaApi` class using your API credentials, just initialize the `IncogniaApi` with your credentials using the `init()` method. Initializing the `IncogniaApi` is a required step and must be done before calling any of the other `IncogniaApi` methods. | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```js |
if (!installationId) { | ||
throw new IncogniaError('No installationId provided') | ||
} | ||
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking: it would be nice to have a decorator function that performs this check. I think we could avoid a lot of repetition. But I realize there are not a lot of functions and the check is simple. Do you think it would be worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pensei em não fazer só pelo código de check ser simples mesmo. Acho que seria parecido em termos de complexidade.
Esse PR modifica a classe
IncogniaApi
para usar um singleton e ter métodos estáticos.Por limitar o acesso à instância, tive que refatorar a classe para extrair as lógicas de gestão de token e de request para arquivos próprios, permitindo que essa lógica fosse testada direitinho.
O novo uso vai ficar assim:
Essa mudança é quebrante, e o release deve ser feito em um major release na
v6.0.0
.