-
Notifications
You must be signed in to change notification settings - Fork 522
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(types): allow typed access to properties added to entry #4814
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import instantsearch from '../index.es'; | ||
|
||
describe('instantsearch()', () => { | ||
it('includes a version', () => { | ||
expect(instantsearch.version).toMatch( | ||
/^(\d+\.)?(\d+\.)?(\*|\d+)(-beta.\d+)?$/ | ||
); | ||
}); | ||
|
||
it('does not include the widget functions', () => { | ||
// @ts-expect-error | ||
expect(() => instantsearch.widgets).toThrowErrorMatchingInlineSnapshot(` | ||
"\\"instantsearch.widgets\\" are not available from the ES build. | ||
|
||
To import the widgets: | ||
|
||
import { searchBox } from 'instantsearch.js/es/widgets'" | ||
`); | ||
}); | ||
|
||
it('does not include the connectors functions', () => { | ||
// @ts-expect-error | ||
expect(() => instantsearch.connectors).toThrowErrorMatchingInlineSnapshot(` | ||
"\\"instantsearch.connectors\\" are not available from the ES build. | ||
|
||
To import the connectors: | ||
|
||
import { connectSearchBox } from 'instantsearch.js/es/connectors'" | ||
`); | ||
}); | ||
|
||
it('includes the helper functions', () => { | ||
expect(Object.keys(instantsearch)).toMatchInlineSnapshot(` | ||
Array [ | ||
"version", | ||
"createInfiniteHitsSessionStorageCache", | ||
"highlight", | ||
"reverseHighlight", | ||
"snippet", | ||
"reverseSnippet", | ||
"insights", | ||
"getInsightsAnonymousUserToken", | ||
] | ||
`); | ||
}); | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
src/connectors/configure-related-items/__tests__/connectConfigureRelatedItems-test.ts
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
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 |
---|---|---|
@@ -1,3 +1,70 @@ | ||
import instantsearch from './lib/main'; | ||
import InstantSearch, { InstantSearchOptions } from './lib/InstantSearch'; | ||
import { Expand, UiState } from './types'; | ||
|
||
import version from './lib/version'; | ||
|
||
import * as connectors from './connectors/index'; | ||
import * as widgets from './widgets/index'; | ||
import * as helpers from './helpers/index'; | ||
import * as middlewares from './middlewares/index'; | ||
|
||
import * as routers from './lib/routers/index'; | ||
import * as stateMappings from './lib/stateMappings/index'; | ||
import { createInfiniteHitsSessionStorageCache } from './lib/infiniteHitsCache/index'; | ||
|
||
type InstantSearchModule = { | ||
<TUiState = Record<string, unknown>, TRouteState = TUiState>( | ||
options: InstantSearchOptions<Expand<UiState & TUiState>, TRouteState> | ||
): InstantSearch<Expand<UiState & TUiState>, TRouteState>; | ||
version: string; | ||
|
||
connectors: typeof connectors; | ||
widgets: typeof widgets; | ||
middlewares: typeof middlewares; | ||
|
||
routers: typeof routers; | ||
stateMappings: typeof stateMappings; | ||
|
||
createInfiniteHitsSessionStorageCache: typeof createInfiniteHitsSessionStorageCache; | ||
highlight: typeof helpers.highlight; | ||
reverseHighlight: typeof helpers.reverseHighlight; | ||
snippet: typeof helpers.snippet; | ||
reverseSnippet: typeof helpers.reverseSnippet; | ||
insights: typeof helpers.insights; | ||
}; | ||
|
||
/** | ||
* InstantSearch is the main component of InstantSearch.js. This object | ||
* manages the widget and lets you add new ones. | ||
* | ||
* Two parameters are required to get you started with InstantSearch.js: | ||
* - `indexName`: the main index that you will use for your new search UI | ||
* - `searchClient`: the search client to plug to InstantSearch.js | ||
* | ||
* The [search client provided by Algolia](algolia.com/doc/api-client/getting-started/what-is-the-api-client/javascript/) | ||
* needs an `appId` and an `apiKey`. Those parameters can be found in your | ||
* [Algolia dashboard](https://www.algolia.com/api-keys). | ||
* | ||
* If you want to get up and running quickly with InstantSearch.js, have a | ||
* look at the [getting started](https://www.algolia.com/doc/guides/building-search-ui/getting-started/js/). | ||
*/ | ||
const instantsearch: InstantSearchModule = options => | ||
new InstantSearch(options); | ||
|
||
instantsearch.version = version; | ||
|
||
instantsearch.connectors = connectors; | ||
instantsearch.widgets = widgets; | ||
instantsearch.middlewares = middlewares; | ||
|
||
instantsearch.routers = routers; | ||
instantsearch.stateMappings = stateMappings; | ||
|
||
instantsearch.createInfiniteHitsSessionStorageCache = createInfiniteHitsSessionStorageCache; | ||
instantsearch.highlight = helpers.highlight; | ||
instantsearch.reverseHighlight = helpers.reverseHighlight; | ||
instantsearch.snippet = helpers.snippet; | ||
instantsearch.reverseSnippet = helpers.reverseSnippet; | ||
instantsearch.insights = helpers.insights; | ||
|
||
export default instantsearch; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
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.
@francoischalifour suggested not deprecating these yet, as we aren't sure where the export should best be from. At the moment it's /es/helpers, but that could change?
Personally I'm more of the opinion to deprecate them with /es/helpers as a workaround, still leaving the option open for a more thorough review of what's exported where in a major version
wdyt @tkrugg / @shortcuts
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.
As long as we have clear warnings etc., I don't see any issue deprecating them