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

Commit cda198c

Browse files
committed
feat(store): do not automatically refresh when using start()
this allows users to start watching the store without actually triggering a search operation. BREAKING CHANGE: using `store.start()` will no longer trigger an Algolia call. if you are were using `store.stop()`/`store.start()` you should now also call `store.refresh()` if you want your store to in sync with Algolia.
1 parent 6370bd1 commit cda198c

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

src/__tests__/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ describe('Store', () => {
421421
return { clearCache };
422422
},
423423
};
424+
store.start();
424425
store.disableCache();
425426
store.refresh();
426427
expect(clearCache).toHaveBeenCalledTimes(1);

src/components/Clear.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default {
5555
this.searchStore.clearRefinements();
5656
}
5757
this.searchStore.start();
58+
this.searchStore.refresh();
5859
},
5960
},
6061
};

src/components/Input.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
// without triggering in between ghost queries.
3333
this.$nextTick(function() {
3434
this.searchStore.start();
35+
this.searchStore.refresh();
3536
});
3637
},
3738
},

src/components/PriceRange.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default {
9595
}
9696
9797
this.searchStore.start();
98+
this.searchStore.refresh();
9899
},
99100
},
100101
to: {
@@ -125,6 +126,7 @@ export default {
125126
this.searchStore.addNumericRefinement(this.attributeName, '<', value);
126127
}
127128
this.searchStore.start();
129+
this.searchStore.refresh();
128130
},
129131
},
130132
},

src/components/Rating.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default {
141141
this.searchStore.addFacetRefinement(this.attributeName, val);
142142
}
143143
this.searchStore.start();
144+
this.searchStore.refresh();
144145
return undefined;
145146
},
146147
clear() {

src/components/__tests__/clear.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ describe('Clear component', () => {
77
const stop = jest.fn();
88
const start = jest.fn();
99
const clearRefinements = jest.fn();
10+
const refresh = jest.fn();
1011

1112
const searchStore = {
1213
query: 'whatever',
1314
activeRefinements: ['whatever'],
1415
stop,
1516
start,
1617
clearRefinements,
18+
refresh,
1719
};
1820

1921
beforeEach(() => {
2022
stop.mockClear();
2123
start.mockClear();
2224
clearRefinements.mockClear();
25+
refresh.mockClear();
2326
searchStore.query = 'whatever';
2427
searchStore.activeRefinements = ['whatever'];
2528
});
@@ -34,6 +37,7 @@ describe('Clear component', () => {
3437
expect(stop).toHaveBeenCalledTimes(1);
3538
expect(clearRefinements).toHaveBeenCalledTimes(1);
3639
expect(start).toHaveBeenCalledTimes(1);
40+
expect(refresh).toHaveBeenCalledTimes(1);
3741
});
3842

3943
test('can disable query clearing', () => {
@@ -46,6 +50,7 @@ describe('Clear component', () => {
4650
expect(stop).toHaveBeenCalledTimes(1);
4751
expect(clearRefinements).toHaveBeenCalledTimes(1);
4852
expect(start).toHaveBeenCalledTimes(1);
53+
expect(refresh).toHaveBeenCalledTimes(1);
4954
});
5055

5156
test('can disable facets clearing', () => {
@@ -58,6 +63,7 @@ describe('Clear component', () => {
5863
expect(stop).toHaveBeenCalledTimes(1);
5964
expect(clearRefinements).not.toHaveBeenCalled();
6065
expect(start).toHaveBeenCalledTimes(1);
66+
expect(refresh).toHaveBeenCalledTimes(1);
6167
});
6268

6369
test('has proper HTML rendering', () => {

src/store.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ export class Store {
131131
} else {
132132
this._stoppedCounter--;
133133
}
134-
135-
if (this._stoppedCounter === 0) {
136-
this.refresh();
137-
}
138134
}
139135

140136
stop() {
@@ -228,6 +224,7 @@ export class Store {
228224
this._helper.setState(state);
229225
}
230226
this.start();
227+
this.refresh();
231228
}
232229

233230
removeFacet(attribute) {
@@ -343,6 +340,7 @@ export class Store {
343340
delete params.page;
344341
}
345342
this.start();
343+
this.refresh();
346344
}
347345

348346
get queryParameters() {
@@ -374,6 +372,9 @@ export class Store {
374372
}
375373

376374
refresh() {
375+
if (this._stoppedCounter !== 0) {
376+
return;
377+
}
377378
if (this._cacheEnabled === false) {
378379
this.clearCache();
379380
}
@@ -424,9 +425,7 @@ export const assertValidFacetType = function(type) {
424425
};
425426

426427
const onHelperChange = function() {
427-
if (this._stoppedCounter === 0) {
428-
this.refresh();
429-
}
428+
this.refresh();
430429
};
431430

432431
const onHelperResult = function(response) {

0 commit comments

Comments
 (0)