1 | import {Transform} from 'vega-dataflow';
|
2 | import {fastmap, inherits} from 'vega-util';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export default function TupleIndex(params) {
|
12 | Transform.call(this, fastmap(), params);
|
13 | }
|
14 |
|
15 | inherits(TupleIndex, Transform, {
|
16 | transform(_, pulse) {
|
17 | const df = pulse.dataflow,
|
18 | field = _.field,
|
19 | index = this.value,
|
20 | set = t => index.set(field(t), t);
|
21 |
|
22 | let mod = true;
|
23 |
|
24 | if (_.modified('field') || pulse.modified(field.fields)) {
|
25 | index.clear();
|
26 | pulse.visit(pulse.SOURCE, set);
|
27 | } else if (pulse.changed()) {
|
28 | pulse.visit(pulse.REM, t => index.delete(field(t)));
|
29 | pulse.visit(pulse.ADD, set);
|
30 | } else {
|
31 | mod = false;
|
32 | }
|
33 |
|
34 | this.modified(mod);
|
35 | if (index.empty > df.cleanThreshold) df.runAfter(index.clean);
|
36 | return pulse.fork();
|
37 | }
|
38 | });
|