@@ -1,8 +1,9 @@
11
22var Elm = function() {
3− var send = function(kids, timestep, changed) {
3+ var send = function(node, timestep, changed) {
4+ var kids = node.kids;
45 for (var i = kids.length; i--; ) {
5− kids[i].recv(timestep, changed);
6+ kids[i].recv(timestep, changed, node.id);
67 }
78 };
89 var input = function(base) {
@@ -12,7 +13,7 @@ var Elm = function() {
1213 this.recv = function(timestep, eid, v) {
1314 var changed = eid === this.id;
1415 if (changed) { this.value = v; }
15− send(this.kids, timestep, changed);
16+ send(this, timestep, changed);
1617 };
1718 Dispatcher.inputs.push(this);
1819 };
@@ -32,7 +33,7 @@ var Elm = function() {
3233 };
3334 this.recalc();
3435
35− this.recv = function(timestep, changed) {
36+ this.recv = function(timestep, changed, parentID) {
3637 if (!this.inbox.hasOwnProperty(timestep)) {
3738 this.inbox[timestep] = { changed: false, count: 0 };
3839 }
@@ -41,7 +42,7 @@ var Elm = function() {
4142 if (changed) { box.changed = true; }
4243 if (box.count == args.length) {
4344 if (box.changed) { this.recalc() }
44− send(this.kids, timestep, box.changed);
45+ send(this, timestep, box.changed);
4546 delete this.inbox[timestep];
4647 }
4748 };
@@ -53,9 +54,9 @@ var Elm = function() {
5354 this.id = Guid.guid();
5455 this.value = base;
5556 this.kids = [];
56− this.recv = function(timestep, changed) {
57+ this.recv = function(timestep, changed, parentID) {
5758 if (changed) { this.value = func(input.value)(this.value); }
58− send(this.kids, timestep, changed);
59+ send(this, timestep, changed);
5960 };
6061 input.kids.push(this);
6162 };
@@ -64,10 +65,10 @@ var Elm = function() {
6465 this.id = Guid.guid();
6566 this.value = pred(input.value) ? base : input.value;
6667 this.kids = [];
67− this.recv = function(timestep, changed) {
68+ this.recv = function(timestep, changed, parentID) {
6869 var chng = changed && !pred(input.value);
6970 if (chng) { this.value = input.value; }
70− send(this.kids, timestep, chng);
71+ send(this, timestep, chng);
7172 };
7273 input.kids.push(this);
7374 };
@@ -75,10 +76,10 @@ var Elm = function() {
7576 this.id = Guid.guid();
7677 this.value = input.value;
7778 this.kids = [];
78− this.recv = function(timestep, changed) {
79+ this.recv = function(timestep, changed, parentID) {
7980 var chng = changed && !eq(this.value,input.value);
8081 if (chng) { this.value = input.value; }
81− send(this.kids, timestep, chng);
82+ send(this, timestep, chng);
8283 };
8384 input.kids.push(this);
8485 };
@@ -89,6 +90,21 @@ var Elm = function() {
8990 return new lift(function(p){return p[1];},[dropped]); }; };
9091 };
9192
93+ var sampleOn = function(s1,s2) {
94+ this.id = Guid.guid();
95+ this.value = s2.value;
96+ this.kids = [];
97+ this.inbox = {};
98+
99+ this.recv = function(timestep, changed, parentID) {
100+ var chng = changed && parentID === s1.id;
101+ if (chng) { this.value = s2.value; }
102+ send(this, timestep, chng);
103+ };
104+ s1.kids.push(this);
105+ s2.kids.push(this);
106+ };
107+
92108 return {Input: function(x) {return new input(x);},
93109 Lift: function(f,xs){return new lift(f,xs);},
94110 Fold: function(f,b,x){return new fold(f,b,x);},
@@ -98,7 +114,8 @@ var Elm = function() {
98114 return new dropIf(pred,base,sig); }; }; },
99115 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
100116 dropWhen : dropWhen,
101− dropRepeats : function(s) { return new dropRepeats(s);}
117+ dropRepeats : function(s) { return new dropRepeats(s);},
118+ sampleOn : sampleOn
102119 };
103120}();
104121