Skip to content

Commit

Permalink
feat: adds support for setting offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpagtakhan committed Dec 18, 2023
1 parent 52bfee1 commit 4e4817f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/analytics-browser/src/browser-client-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export const createInstance = (): BrowserClient => {
getClientLogConfig(client),
getClientStates(client, ['config']),
),
setOffline: debugWrapper(
client.setOffline.bind(client),
'setOffline',
getClientLogConfig(client),
getClientStates(client, ['config']),
),
};
};

Expand Down
2 changes: 2 additions & 0 deletions packages/analytics-browser/test/browser-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,11 @@ describe('browser-client', () => {
defaultTracking: false,
offline: true,
}).promise;
const flush = jest.spyOn(client, 'flush');

client.setOffline(false);
expect(client.config.offline).toBe(false);
expect(flush).toHaveBeenCalledTimes(1);
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/analytics-types/src/client/web-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export interface BrowserClient extends Client {
* ```
*/
add(plugin: Plugin<BrowserClient, BrowserConfig>): AmplitudeReturn<void>;

setOffline(offline: boolean): void;
}

export interface ReactNativeClient extends Client {
Expand Down

0 comments on commit 4e4817f

Please sign in to comment.