-
Notifications
You must be signed in to change notification settings - Fork 529
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
feat(insights): introduce insights
middleware (1/4)
#4446
Merged
Merged
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3963956
feat: update userToken automatically
eunjae-lee 4331d24
chore: fix bug where it gets token before rendering the custom widget
eunjae-lee 77996c9
chore: add access modifier
eunjae-lee 467a648
chore: use custom widget and helper
eunjae-lee ec3f7bb
Update src/lib/InstantSearch.ts
3ab96a2
chore: update token to helper directly
eunjae-lee 020381e
chore: move setupUserTokenUpdater to start()
eunjae-lee a0cc96f
chore: move to middleware
eunjae-lee c642234
Update src/middleware/insights.ts
03e52c7
export middleware
eunjae-lee 0ae09e2
fix lint error
eunjae-lee 2417c50
export for umd build
eunjae-lee 090fe28
Update src/middleware/insights.ts
c262700
Merge branch 'master' into feat/automatic-user-token
2a49909
update token automatically
eunjae-lee 20254cf
chore: update error message
eunjae-lee 10ce292
inline functions
eunjae-lee 5a1fc34
initialize insightsClient earlier
eunjae-lee 963d305
add warning message if userToken is set before creating the middleware
eunjae-lee daca533
accept `false` for `insightsClient`
eunjae-lee 000d708
clean up types
eunjae-lee 602037a
fix wrong import
eunjae-lee 8fd4698
Update src/middleware/insights.ts
b0b7add
accept null as insightsClient
eunjae-lee e2a2743
Merge branch 'master' into feat/automatic-user-token
21faadb
Update src/types/insights.ts
7f49f25
add test for getAppIdAndApiKey
eunjae-lee 94e394b
Update src/types/insights.ts
ad0dafb
bring back exports
eunjae-lee f34170d
rename middleware to middlewares
eunjae-lee ef95a87
Merge branch 'master' into feat/automatic-user-token
eunjae-lee 183b1ca
chore: rename files for better alignment
eunjae-lee e7c7e58
chore: export all types related to insights middleware
eunjae-lee 60af9e0
feat(insights): send events from hits and refinementList (2/4) (#4456)
5067ec7
Merge branch 'master' into feat/automatic-user-token
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ export type Middleware = ({ | |
}) => MiddlewareDefinition; | ||
|
||
export { createRouter, RouterProps } from './createRouter'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if anyone uses this, but this changes the API There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
export { createInsightsMiddleware } from './insights'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Middleware } from '.'; | ||
import { InsightsClient } from '../types'; | ||
|
||
export type InsightsProps = { | ||
insightsClient: InsightsClient; | ||
}; | ||
|
||
export type CreateInsightsMiddleware = (props: InsightsProps) => Middleware; | ||
|
||
export const createInsightsMiddleware: CreateInsightsMiddleware = props => { | ||
const { insightsClient } = props; | ||
if (!insightsClient) { | ||
eunjae-lee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error( | ||
'passing insightsClient to instantsearch is required for insightsMiddleware' | ||
); | ||
} | ||
return ({ instantSearchInstance }) => { | ||
eunjae-lee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
onStateChange() {}, | ||
subscribe() { | ||
instantSearchInstance.mainIndex | ||
.getHelper() | ||
.setQueryParameter('clickAnalytics', true); | ||
|
||
insightsClient( | ||
'onUserTokenChange', | ||
userToken => { | ||
instantSearchInstance.mainIndex | ||
.getHelper() | ||
.setQueryParameter('userToken', userToken); | ||
}, | ||
{ immediate: true } | ||
); | ||
}, | ||
unsubscribe() { | ||
insightsClient('onUserTokenChange', () => {}); | ||
eunjae-lee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
middleware vs middlewares
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.
"middlewares" is not proper English.
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.
https://en.wiktionary.org/wiki/middleware
I don't think I've seen
s
at the end ofmiddleware
before, though.So you agree it's natural to have
middleware
although we haverouters, stateMappings, connectors, widgets
, right?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 think it should be middlewares, at least for the object containing all possible middlewares. Interestingly my spell-checker only accepts singular "middleware" as correct, and not "middlewares"
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.
https://www.wordhippo.com/what-is/the-plural-of/middleware.html
While
middleware
is more common, it's also safe to usemiddlewares
if we want to explicitly indicate it's a collection.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.
f34170d