UNPKG

1.79 kBJavaScriptView Raw
1import {Operator} from 'vega-dataflow';
2import {inherits} from 'vega-util';
3
4/**
5 * Provides a bridge between a parent transform and a target subflow that
6 * consumes only a subset of the tuples that pass through the parent.
7 * @constructor
8 * @param {Pulse} pulse - A pulse to use as the value of this operator.
9 * @param {Transform} parent - The parent transform (typically a Facet instance).
10 */
11export default function Subflow(pulse, parent) {
12 Operator.call(this, pulse);
13 this.parent = parent;
14 this.count = 0;
15}
16
17inherits(Subflow, Operator, {
18 /**
19 * Routes pulses from this subflow to a target transform.
20 * @param {Transform} target - A transform that receives the subflow of tuples.
21 */
22 connect(target) {
23 this.detachSubflow = target.detachSubflow;
24 this.targets().add(target);
25 return (target.source = this);
26 },
27
28 /**
29 * Add an 'add' tuple to the subflow pulse.
30 * @param {Tuple} t - The tuple being added.
31 */
32 add(t) {
33 this.count += 1;
34 this.value.add.push(t);
35 },
36
37 /**
38 * Add a 'rem' tuple to the subflow pulse.
39 * @param {Tuple} t - The tuple being removed.
40 */
41 rem(t) {
42 this.count -= 1;
43 this.value.rem.push(t);
44 },
45
46 /**
47 * Add a 'mod' tuple to the subflow pulse.
48 * @param {Tuple} t - The tuple being modified.
49 */
50 mod(t) {
51 this.value.mod.push(t);
52 },
53
54 /**
55 * Re-initialize this operator's pulse value.
56 * @param {Pulse} pulse - The pulse to copy from.
57 * @see Pulse.init
58 */
59 init(pulse) {
60 this.value.init(pulse, pulse.NO_SOURCE);
61 },
62
63 /**
64 * Evaluate this operator. This method overrides the
65 * default behavior to simply return the contained pulse value.
66 * @return {Pulse}
67 */
68 evaluate() {
69 // assert: this.value.stamp === pulse.stamp
70 return this.value;
71 }
72});