Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat(InfiniteHits): support cache (#804)
Browse files Browse the repository at this point in the history
* feat(InfiniteHits): support cache

* test: add test accepting a cache prop
  • Loading branch information
Eunjae Lee authored Jun 19, 2020
1 parent 0528b55 commit 918c92d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/InfiniteHits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ export default {
return items;
},
},
cache: {
type: Object,
default: undefined,
},
},
computed: {
widgetParams() {
return {
showPrevious: this.showPrevious,
escapeHTML: this.escapeHTML,
transformItems: this.transformItems,
cache: this.cache,
};
},
items() {
Expand Down
19 changes: 19 additions & 0 deletions src/components/__tests__/InfiniteHits.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ it('accepts a showPrevious prop', () => {
expect(wrapper.vm.widgetParams.showPrevious).toBe(true);
});

it('accepts a cache prop', () => {
__setState({
...defaultState,
});

const cache = {
read: () => {},
write: () => {},
};

const wrapper = mount(InfiniteHits, {
propsData: {
cache,
},
});

expect(wrapper.vm.widgetParams.cache).toEqual(cache);
});

it('renders correctly', () => {
__setState({
...defaultState,
Expand Down
14 changes: 14 additions & 0 deletions stories/InfiniteHits.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { storiesOf } from '@storybook/vue';
import { action } from '@storybook/addon-actions';
import { createInfiniteHitsSessionStorageCache } from 'instantsearch.js/es/lib/infiniteHitsCache';
import { simple } from 'instantsearch.js/es/lib/stateMappings';
import { previewWrapper } from './utils';
import { MemoryRouter } from './MemoryRouter';
Expand Down Expand Up @@ -169,4 +170,17 @@ storiesOf('ais-infinite-hits', module)
</ais-infinite-hits>
</div>
`,
}))
.add('with sessionStorage cache enabled', () => ({
template: `
<ais-infinite-hits :cache="cache">
<div slot="item" slot-scope="{ item, insights }">
custom objectID: {{item.objectID}}
<a href="https://google.com">Go to the detail</a>
</div>
</ais-infinite-hits>
`,
data: () => ({
cache: createInfiniteHitsSessionStorageCache(),
}),
}));

0 comments on commit 918c92d

Please sign in to comment.