Skip to content

Commit

Permalink
refactor: filter to find and index to includes (#9398)
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jul 31, 2024
1 parent a342c11 commit 8bad9d2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/compile/selection/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const inputBindings: SelectionCompiler<'point'> = {
signals: (model, selCmpt, signals) => {
const name = selCmpt.name;
const proj = selCmpt.project;
const signal: NewSignal = signals.filter(s => s.name === name + TUPLE)[0];
const signal: NewSignal = signals.find(s => s.name === name + TUPLE);
const fields = name + TUPLE_FIELDS;
const values = proj.items.map(p => varName(`${name}_${p.field}`));
const valid = values.map(v => `${v} !== null`).join(' && ');
Expand Down
2 changes: 1 addition & 1 deletion src/compile/selection/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const interval: SelectionCompiler<'interval'> = {
}

const filters = array((evt.between[0].filter ??= []));
if (filters.indexOf(filterExpr) < 0) {
if (!filters.includes(filterExpr)) {
filters.push(filterExpr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/selection/nearest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const nearest: SelectionCompiler<'point'> = {
const name = mark.name ?? '';
if (name === model.component.mark[0].name) {
index = i;
} else if (name.indexOf(VORONOI) >= 0) {
} else if (name.includes(VORONOI)) {
exists = true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/compile/selection/scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const scaleBindings: SelectionCompiler<'interval'> = {
// state is captured by the top-level signals that we insert and "push
// outer" to from within the units. We need to reassemble this state into
// the top-level named signal, except no single selCmpt has a global view.
const namedSg: NewSignal = signals.filter(s => s.name === selCmpt.name)[0];
const namedSg: NewSignal = signals.find(s => s.name === selCmpt.name);
let update = namedSg.update;
if (update.indexOf(VL_SELECTION_RESOLVE) >= 0) {
if (update.includes(VL_SELECTION_RESOLVE)) {
namedSg.update = `{${bound
.map(proj => `${stringValue(replacePathInField(proj.field))}: ${proj.signals.data}`)
.join(', ')}}`;
Expand Down
2 changes: 1 addition & 1 deletion src/compile/selection/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function onDelta(
const delta = name + DELTA;
const channel = proj.channel as ScaleChannel;
const boundScales = scalesCompiler.defined(selCmpt);
const signal = signals.filter(s => s.name === proj.signals[boundScales ? 'data' : 'visual'])[0];
const signal = signals.find(s => s.name === proj.signals[boundScales ? 'data' : 'visual']);
const sizeSg = model.getSizeSignalRef(size).signal;
const scaleCmpt = model.getScaleComponent(channel);
const scaleType = scaleCmpt && scaleCmpt.get('type');
Expand Down
2 changes: 1 addition & 1 deletion src/compile/selection/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function onDelta(
const name = selCmpt.name;
const channel = proj.channel as ScaleChannel;
const boundScales = scalesCompiler.defined(selCmpt);
const signal = signals.filter(s => s.name === proj.signals[boundScales ? 'data' : 'visual'])[0];
const signal = signals.find(s => s.name === proj.signals[boundScales ? 'data' : 'visual']);
const sizeSg = model.getSizeSignalRef(size).signal;
const scaleCmpt = model.getScaleComponent(channel);
const scaleType = scaleCmpt && scaleCmpt.get('type');
Expand Down

0 comments on commit 8bad9d2

Please sign in to comment.