1 | import SortedList from './util/SortedList';
|
2 | import {Transform, stableCompare, tupleid} from 'vega-dataflow';
|
3 | import {inherits} from 'vega-util';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export default function Collect(params) {
|
13 | Transform.call(this, [], params);
|
14 | }
|
15 |
|
16 | Collect.Definition = {
|
17 | 'type': 'Collect',
|
18 | 'metadata': {'source': true},
|
19 | 'params': [
|
20 | { 'name': 'sort', 'type': 'compare' }
|
21 | ]
|
22 | };
|
23 |
|
24 | inherits(Collect, Transform, {
|
25 | transform(_, pulse) {
|
26 | const out = pulse.fork(pulse.ALL),
|
27 | list = SortedList(tupleid, this.value, out.materialize(out.ADD).add),
|
28 | sort = _.sort,
|
29 | mod = pulse.changed() || (sort &&
|
30 | (_.modified('sort') || pulse.modified(sort.fields)));
|
31 |
|
32 | out.visit(out.REM, list.remove);
|
33 |
|
34 | this.modified(mod);
|
35 | this.value = out.source = list.data(stableCompare(sort), mod);
|
36 |
|
37 |
|
38 | if (pulse.source && pulse.source.root) {
|
39 | this.value.root = pulse.source.root;
|
40 | }
|
41 |
|
42 | return out;
|
43 | }
|
44 | });
|