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

Commit 918c92d

Browse files
author
Eunjae Lee
authored
feat(InfiniteHits): support cache (#804)
* feat(InfiniteHits): support cache * test: add test accepting a cache prop
1 parent 0528b55 commit 918c92d

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/components/InfiniteHits.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ export default {
8585
return items;
8686
},
8787
},
88+
cache: {
89+
type: Object,
90+
default: undefined,
91+
},
8892
},
8993
computed: {
9094
widgetParams() {
9195
return {
9296
showPrevious: this.showPrevious,
9397
escapeHTML: this.escapeHTML,
9498
transformItems: this.transformItems,
99+
cache: this.cache,
95100
};
96101
},
97102
items() {

src/components/__tests__/InfiniteHits.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ it('accepts a showPrevious prop', () => {
8080
expect(wrapper.vm.widgetParams.showPrevious).toBe(true);
8181
});
8282

83+
it('accepts a cache prop', () => {
84+
__setState({
85+
...defaultState,
86+
});
87+
88+
const cache = {
89+
read: () => {},
90+
write: () => {},
91+
};
92+
93+
const wrapper = mount(InfiniteHits, {
94+
propsData: {
95+
cache,
96+
},
97+
});
98+
99+
expect(wrapper.vm.widgetParams.cache).toEqual(cache);
100+
});
101+
83102
it('renders correctly', () => {
84103
__setState({
85104
...defaultState,

stories/InfiniteHits.stories.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { storiesOf } from '@storybook/vue';
22
import { action } from '@storybook/addon-actions';
3+
import { createInfiniteHitsSessionStorageCache } from 'instantsearch.js/es/lib/infiniteHitsCache';
34
import { simple } from 'instantsearch.js/es/lib/stateMappings';
45
import { previewWrapper } from './utils';
56
import { MemoryRouter } from './MemoryRouter';
@@ -169,4 +170,17 @@ storiesOf('ais-infinite-hits', module)
169170
</ais-infinite-hits>
170171
</div>
171172
`,
173+
}))
174+
.add('with sessionStorage cache enabled', () => ({
175+
template: `
176+
<ais-infinite-hits :cache="cache">
177+
<div slot="item" slot-scope="{ item, insights }">
178+
custom objectID: {{item.objectID}}
179+
<a href="https://google.com">Go to the detail</a>
180+
</div>
181+
</ais-infinite-hits>
182+
`,
183+
data: () => ({
184+
cache: createInfiniteHitsSessionStorageCache(),
185+
}),
172186
}));

0 commit comments

Comments
 (0)