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

Commit

Permalink
feat(store): do not automatically refresh when using start()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rayrutjes committed Aug 8, 2017
1 parent 6370bd1 commit cda198c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/__tests__/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ describe('Store', () => {
return { clearCache };
},
};
store.start();
store.disableCache();
store.refresh();
expect(clearCache).toHaveBeenCalledTimes(1);
Expand Down
1 change: 1 addition & 0 deletions src/components/Clear.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default {
this.searchStore.clearRefinements();
}
this.searchStore.start();
this.searchStore.refresh();
},
},
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default {
// without triggering in between ghost queries.
this.$nextTick(function() {
this.searchStore.start();
this.searchStore.refresh();
});
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/components/PriceRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
}
this.searchStore.start();
this.searchStore.refresh();
},
},
to: {
Expand Down Expand Up @@ -125,6 +126,7 @@ export default {
this.searchStore.addNumericRefinement(this.attributeName, '<', value);
}
this.searchStore.start();
this.searchStore.refresh();
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/components/Rating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default {
this.searchStore.addFacetRefinement(this.attributeName, val);
}
this.searchStore.start();
this.searchStore.refresh();
return undefined;
},
clear() {
Expand Down
6 changes: 6 additions & 0 deletions src/components/__tests__/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ describe('Clear component', () => {
const stop = jest.fn();
const start = jest.fn();
const clearRefinements = jest.fn();
const refresh = jest.fn();

const searchStore = {
query: 'whatever',
activeRefinements: ['whatever'],
stop,
start,
clearRefinements,
refresh,
};

beforeEach(() => {
stop.mockClear();
start.mockClear();
clearRefinements.mockClear();
refresh.mockClear();
searchStore.query = 'whatever';
searchStore.activeRefinements = ['whatever'];
});
Expand All @@ -34,6 +37,7 @@ describe('Clear component', () => {
expect(stop).toHaveBeenCalledTimes(1);
expect(clearRefinements).toHaveBeenCalledTimes(1);
expect(start).toHaveBeenCalledTimes(1);
expect(refresh).toHaveBeenCalledTimes(1);
});

test('can disable query clearing', () => {
Expand All @@ -46,6 +50,7 @@ describe('Clear component', () => {
expect(stop).toHaveBeenCalledTimes(1);
expect(clearRefinements).toHaveBeenCalledTimes(1);
expect(start).toHaveBeenCalledTimes(1);
expect(refresh).toHaveBeenCalledTimes(1);
});

test('can disable facets clearing', () => {
Expand All @@ -58,6 +63,7 @@ describe('Clear component', () => {
expect(stop).toHaveBeenCalledTimes(1);
expect(clearRefinements).not.toHaveBeenCalled();
expect(start).toHaveBeenCalledTimes(1);
expect(refresh).toHaveBeenCalledTimes(1);
});

test('has proper HTML rendering', () => {
Expand Down
13 changes: 6 additions & 7 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ export class Store {
} else {
this._stoppedCounter--;
}

if (this._stoppedCounter === 0) {
this.refresh();
}
}

stop() {
Expand Down Expand Up @@ -228,6 +224,7 @@ export class Store {
this._helper.setState(state);
}
this.start();
this.refresh();
}

removeFacet(attribute) {
Expand Down Expand Up @@ -343,6 +340,7 @@ export class Store {
delete params.page;
}
this.start();
this.refresh();
}

get queryParameters() {
Expand Down Expand Up @@ -374,6 +372,9 @@ export class Store {
}

refresh() {
if (this._stoppedCounter !== 0) {
return;
}
if (this._cacheEnabled === false) {
this.clearCache();
}
Expand Down Expand Up @@ -424,9 +425,7 @@ export const assertValidFacetType = function(type) {
};

const onHelperChange = function() {
if (this._stoppedCounter === 0) {
this.refresh();
}
this.refresh();
};

const onHelperResult = function(response) {
Expand Down

0 comments on commit cda198c

Please sign in to comment.