@@ -1,8 +1,9 @@
2var Elm = function() {
2var Elm = function() {
3− var send = function(kids, timestep, changed) {
3+ var send = function(node, timestep, changed) {
4 for (var i = kids.length; i--; ) {
5 for (var i = kids.length; i--; ) {
5− kids[i].recv(timestep, changed);
6+ kids[i].recv(timestep, changed, node.id);
8 var input = function(base) {
9 var input = function(base) {
@@ -12,7 +13,7 @@ var Elm = function() {
12 this.recv = function(timestep, eid, v) {
13 this.recv = function(timestep, eid, v) {
13 var changed = eid === this.id;
14 var changed = eid === this.id;
14 if (changed) { this.value = v; }
15 if (changed) { this.value = v; }
15− send(this.kids, timestep, changed);
16+ send(this, timestep, changed);
17 Dispatcher.inputs.push(this);
18 Dispatcher.inputs.push(this);
@@ -32,7 +33,7 @@ var Elm = function() {
33 this.recalc();
34 this.recalc();
35− this.recv = function(timestep, changed) {
36+ this.recv = function(timestep, changed, parentID) {
36 if (!this.inbox.hasOwnProperty(timestep)) {
37 if (!this.inbox.hasOwnProperty(timestep)) {
37 this.inbox[timestep] = { changed: false, count: 0 };
38 this.inbox[timestep] = { changed: false, count: 0 };
@@ -41,7 +42,7 @@ var Elm = function() {
41 if (changed) { box.changed = true; }
42 if (changed) { box.changed = true; }
42 if (box.count == args.length) {
43 if (box.count == args.length) {
43 if (box.changed) { this.recalc() }
44 if (box.changed) { this.recalc() }
44− send(this.kids, timestep, box.changed);
45+ send(this, timestep, box.changed);
45 delete this.inbox[timestep];
46 delete this.inbox[timestep];
@@ -53,9 +54,9 @@ var Elm = function() {
53 this.id = Guid.guid();
54 this.id = Guid.guid();
54 this.value = base;
55 this.value = base;
55 this.kids = [];
56 this.kids = [];
56− this.recv = function(timestep, changed) {
57+ this.recv = function(timestep, changed, parentID) {
57 if (changed) { this.value = func(input.value)(this.value); }
58 if (changed) { this.value = func(input.value)(this.value); }
58− send(this.kids, timestep, changed);
59+ send(this, timestep, changed);
60 input.kids.push(this);
61 input.kids.push(this);
@@ -64,10 +65,10 @@ var Elm = function() {
64 this.id = Guid.guid();
65 this.id = Guid.guid();
65 this.value = pred(input.value) ? base : input.value;
66 this.value = pred(input.value) ? base : input.value;
66 this.kids = [];
67 this.kids = [];
67− this.recv = function(timestep, changed) {
68+ this.recv = function(timestep, changed, parentID) {
68 var chng = changed && !pred(input.value);
69 var chng = changed && !pred(input.value);
69 if (chng) { this.value = input.value; }
70 if (chng) { this.value = input.value; }
70− send(this.kids, timestep, chng);
71+ send(this, timestep, chng);
72 input.kids.push(this);
73 input.kids.push(this);
@@ -75,10 +76,10 @@ var Elm = function() {
75 this.id = Guid.guid();
76 this.id = Guid.guid();
76 this.value = input.value;
77 this.value = input.value;
77 this.kids = [];
78 this.kids = [];
78− this.recv = function(timestep, changed) {
79+ this.recv = function(timestep, changed, parentID) {
79 var chng = changed && !eq(this.value,input.value);
80 var chng = changed && !eq(this.value,input.value);
80 if (chng) { this.value = input.value; }
81 if (chng) { this.value = input.value; }
81− send(this.kids, timestep, chng);
82+ send(this, timestep, chng);
83 input.kids.push(this);
84 input.kids.push(this);
@@ -89,6 +90,21 @@ var Elm = function() {
89 return new lift(function(p){return p[1];},[dropped]); }; };
90 return new lift(function(p){return p[1];},[dropped]); }; };
93+ var sampleOn = function(s1,s2) {
94+ this.id = Guid.guid();
95+ this.value = s2.value;
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);
92 return {Input: function(x) {return new input(x);},
108 return {Input: function(x) {return new input(x);},
93 Lift: function(f,xs){return new lift(f,xs);},
109 Lift: function(f,xs){return new lift(f,xs);},
94 Fold: function(f,b,x){return new fold(f,b,x);},
110 Fold: function(f,b,x){return new fold(f,b,x);},
@@ -98,7 +114,8 @@ var Elm = function() {
98 return new dropIf(pred,base,sig); }; }; },
114 return new dropIf(pred,base,sig); }; }; },
99 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
115 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
100 dropWhen : dropWhen,
116 dropWhen : dropWhen,
101− dropRepeats : function(s) { return new dropRepeats(s);}
117+ dropRepeats : function(s) { return new dropRepeats(s);},