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 | var prototype = inherits(TupleIndex, Transform);
|
16 |
|
17 | prototype.transform = function(_, pulse) {
|
18 | var df = pulse.dataflow,
|
19 | field = _.field,
|
20 | index = this.value,
|
21 | mod = true;
|
22 |
|
23 | function set(t) { index.set(field(t), t); }
|
24 |
|
25 | if (_.modified('field') || pulse.modified(field.fields)) {
|
26 | index.clear();
|
27 | pulse.visit(pulse.SOURCE, set);
|
28 | } else if (pulse.changed()) {
|
29 | pulse.visit(pulse.REM, function(t) { index.delete(field(t)); });
|
30 | pulse.visit(pulse.ADD, set);
|
31 | } else {
|
32 | mod = false;
|
33 | }
|
34 |
|
35 | this.modified(mod);
|
36 | if (index.empty > df.cleanThreshold) df.runAfter(index.clean);
|
37 | return pulse.fork();
|
38 | };
|