Skip to content

Commit

Permalink
fix: refetch after context update (#143)
Browse files Browse the repository at this point in the history
* fix: refetch after context update

* chore: v2.4.3
  • Loading branch information
Tymek committed Feb 21, 2023
1 parent c4f5056 commit 47bd1df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unleash-proxy-client",
"version": "2.4.2",
"version": "2.4.3",
"description": "A browser client that can be used together with the unleash-proxy.",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,3 +1407,19 @@ test('Should be able to configure UnleashClient with a URL instance', () => {
const client = new UnleashClient(config);
expect(client).toHaveProperty('url', url);
});

test("Should update toggles even when refresh interval is set to '0'", async () => {
fetchMock.mockResponse(JSON.stringify(data));
const config: IConfig = {
url: 'http://localhost/test',
clientKey: '12',
appName: 'web',
refreshInterval: 0,
};
const client = new UnleashClient(config);
await client.start();
expect(fetchMock).toHaveBeenCalledTimes(1);

await client.updateContext({ userId: '123' });
expect(fetchMock).toHaveBeenCalledTimes(2);
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ export class UnleashClient extends TinyEmitter {
};
this.context = { ...staticContext, ...context };

if (this.timerRef) {
if (this.timerRef || this.readyEventEmitted) {
await this.fetchToggles();
} else if(this.started) {
} else if (this.started) {
await new Promise<void>((resolve) => {
const listener = () => {
this.fetchToggles().then(() => {
Expand Down

0 comments on commit 47bd1df

Please sign in to comment.