Skip to content

Commit

Permalink
add queue to InsightsClient type
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee committed Nov 12, 2020
1 parent fa7ea26 commit 5ddedee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/middlewares/createInsightsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const createInsightsMiddleware: CreateInsightsMiddleware = props => {
const [appId, apiKey] = getAppIdAndApiKey(instantSearchInstance.client);
let queuedUserToken: string | undefined = undefined;
let userTokenBeforeInit: string | undefined = undefined;
if (Array.isArray((insightsClient as any).queue)) {

if (Array.isArray(insightsClient.queue)) {
// Context: The umd build of search-insights is asynchronously loaded by the snippet.
//
// When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
Expand All @@ -53,7 +54,7 @@ export const createInsightsMiddleware: CreateInsightsMiddleware = props => {
// we still want to read the token from the queue.
// Otherwise, the first search call will be fired without the token.
[, queuedUserToken] =
(insightsClient as any).queue
insightsClient.queue
.slice()
.reverse()
.find(([method]) => method === 'setUserToken') || [];
Expand Down
4 changes: 3 additions & 1 deletion src/types/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export type InsightsClient = InsightsSendEvent &
InsightsOnUserTokenChange &
InsightsGet &
InsightsInit &
InsightsSetUserToken;
InsightsSetUserToken & {
queue?: Array<[string, any]>;
};

export type InsightsClientWrapper = (
method: InsightsClientMethod,
Expand Down

0 comments on commit 5ddedee

Please sign in to comment.