UNPKG

1.66 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 * @param {Transform} target - A transform that receives the subflow of tuples.
11 */
12export default function Subflow(pulse, parent) {
13 Operator.call(this, pulse);
14 this.parent = parent;
15}
16
17var prototype = inherits(Subflow, Operator);
18
19prototype.connect = function(target) {
20 this.targets().add(target);
21 return (target.source = this);
22};
23
24/**
25 * Add an 'add' tuple to the subflow pulse.
26 * @param {Tuple} t - The tuple being added.
27 */
28prototype.add = function(t) {
29 this.value.add.push(t);
30};
31
32/**
33 * Add a 'rem' tuple to the subflow pulse.
34 * @param {Tuple} t - The tuple being removed.
35 */
36prototype.rem = function(t) {
37 this.value.rem.push(t);
38};
39
40/**
41 * Add a 'mod' tuple to the subflow pulse.
42 * @param {Tuple} t - The tuple being modified.
43 */
44prototype.mod = function(t) {
45 this.value.mod.push(t);
46};
47
48/**
49 * Re-initialize this operator's pulse value.
50 * @param {Pulse} pulse - The pulse to copy from.
51 * @see Pulse.init
52 */
53prototype.init = function(pulse) {
54 this.value.init(pulse, pulse.NO_SOURCE);
55};
56
57/**
58 * Evaluate this operator. This method overrides the
59 * default behavior to simply return the contained pulse value.
60 * @return {Pulse}
61 */
62prototype.evaluate = function() {
63 // assert: this.value.stamp === pulse.stamp
64 return this.value;
65};