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

Commit

Permalink
fix(store): better handle facet addition and removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed May 28, 2017
1 parent 8660a26 commit bda4dc1
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,53 @@ export class Store {
assertValidFacetType(type);

this.stop();
this.removeFacet(attribute);

let state = null;
if (type === FACET_AND) {
state = this._helper.state.addFacet(attribute);
if (!this._helper.state.isConjunctiveFacet(attribute)) {
this.removeFacet(attribute);
state = this._helper.state.addFacet(attribute);
}
} else if (type === FACET_OR) {
state = this._helper.state.addDisjunctiveFacet(attribute);
if (!this._helper.state.isDisjunctiveFacet(attribute)) {
this.removeFacet(attribute);
state = this._helper.state.addDisjunctiveFacet(attribute);
}
} else if (type === FACET_TREE) {
state = this._helper.state.addHierarchicalFacet(attribute);
if (!this._helper.state.isHierarchicalFacet(attribute.name)) {
this.removeFacet(attribute.name);
state = this._helper.state.addHierarchicalFacet(attribute);
}
}

this._helper.setState(state);
if (state !== null) {
this._helper.setState(state);
}
this.start();
}

removeFacet(attribute) {
let state = null;

if (this._helper.state.isConjunctiveFacet(attribute)) {
this._helper.state.removeFacet(attribute);
state = this._helper.state.removeFacet(attribute);
} else if (this._helper.state.isDisjunctiveFacet(attribute)) {
this._helper.state.removeDisjunctiveFacet(attribute);
} else if (this._helper.state.isDisjunctiveFacet(attribute)) {
this._helper.state.removeHierarchicalFacet(attribute);
state = this._helper.state.removeDisjunctiveFacet(attribute);
} else if (this._helper.state.isHierarchicalFacet(attribute)) {
state = this._helper.state.removeHierarchicalFacet(attribute);
} else {
return;
}

this._helper.setState(state);
}

addFacetRefinement(attribute, value) {
if (this._helper.state.isConjunctiveFacet(attribute)) {
this._helper.addFacetRefinement(attribute, value);
} else if (this._helper.state.isDisjunctiveFacet(attribute)) {
this._helper.addDisjunctiveFacetRefinement(attribute, value);
} else if (this._helper.state.isDisjunctiveFacet(attribute)) {
} else if (this._helper.state.isHierarchicalFacet(attribute)) {
this._helper.addHierarchicalFacetRefinement(attribute, value);
}
}
Expand Down

0 comments on commit bda4dc1

Please sign in to comment.