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 register facet if already existing
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed Aug 8, 2017
1 parent 4db0720 commit 6370bd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/__tests__/refinement-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('renders proper HTML', () => {
expect(vm.$el.outerHTML).toMatchSnapshot();
});

test('should add a facet to the store when mounted', () => {
test('should add a facet to the store when created', () => {
const Component = Vue.extend(RefinementList);
const addFacetMock = jest.fn();
const store = Object.assign({}, searchStore, { addFacet: addFacetMock });
Expand Down
19 changes: 18 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ export class Store {
}

addFacet(attribute, type = FACET_AND) {
assertValidFacetType(type);
if (this.hasFacet(attribute, type)) {
return;
}

this.stop();

Expand Down Expand Up @@ -244,6 +246,21 @@ export class Store {
this._helper.setState(state);
}

hasFacet(attribute, type = FACET_AND) {
assertValidFacetType(type);

switch (type) {
case FACET_AND:
return this._helper.state.isConjunctiveFacet(attribute);
case FACET_OR:
return this._helper.state.isDisjunctiveFacet(attribute);
case FACET_TREE:
return this._helper.state.isHierarchicalFacet(attribute);
default:
throw new TypeError(`${type} could not be handled.`);
}
}

addFacetRefinement(attribute, value) {
if (this._helper.state.isConjunctiveFacet(attribute)) {
this._helper.addFacetRefinement(attribute, value);
Expand Down

0 comments on commit 6370bd1

Please sign in to comment.