Skip to content

Commit

Permalink
fix: optimize useage of removeState
Browse files Browse the repository at this point in the history
  • Loading branch information
xile611 committed May 28, 2024
1 parent 462598a commit 4e4a3ad
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions packages/vgrammar-core/src/interactions/brush-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export class BrushHighlight extends BrushBase<BrushHighlightOptions> {
const elements: (IElement | IGlyphElement)[] = [];

if (event.type === IOperateType.brushClear) {
const states = [this.options.blurState, this.options.highlightState];

this._marks.forEach(mark => {
mark.elements.forEach(el => {
el.removeState(this.options.blurState);
el.removeState(this.options.highlightState);
el.removeState(states);
});
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export class ElementHighlightByGroup extends BaseInteraction<ElementHighlightOpt
}

clearPrevElements() {
const states = [this.options.highlightState, this.options.blurState];

this._marks.forEach(mark => {
mark.elements.forEach(el => {
el.removeState(this.options.highlightState);
el.removeState(this.options.blurState);
el.removeState(states);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export class ElementHighlightByKey extends BaseInteraction<ElementHighlightOptio
}

clearPrevElements() {
const states = [this.options.highlightState, this.options.blurState];

this._marks.forEach(mark => {
mark.elements.forEach(el => {
el.removeState(this.options.highlightState);
el.removeState(this.options.blurState);
el.removeState(states);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export class ElementHighlightByLegend extends BaseInteraction<ElementHighlightBy
}

reset() {
const states = [this.options.blurState, this.options.highlightState];
this._marks.forEach(mark => {
mark.elements.forEach(el => {
el.removeState(this.options.blurState);
el.removeState(this.options.highlightState);
el.removeState(states);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ export class ElementHighlightByName extends BaseInteraction<ElementHighlightByNa
}

reset() {
const states = [this.options.blurState, this.options.highlightState];

this._marks.forEach(mark => {
mark.elements.forEach(el => {
el.removeState(this.options.blurState);
el.removeState(this.options.highlightState);
el.removeState(states);
});
});
}
Expand Down

0 comments on commit 4e4a3ad

Please sign in to comment.