on master help sign in
Fix bug in `sampleOn` which caused it to send two messages per event instead of one. Really bad behavior!
bd9dc47evancz
core-js/runtime/Dispatcher.js+15−13
@@ -23,7 +23,8 @@ var Elm = function() {
23 this.id = Guid.guid();
23 this.id = Guid.guid();
24 this.value = null;
24 this.value = null;
25 this.kids = [];
25 this.kids = [];
26− this.inbox = {};
26+ this.count = 0;
27+ this.changed = false;
27
28
28 args.reverse();
29 args.reverse();
29 this.recalc = function() {
30 this.recalc = function() {
@@ -36,16 +37,13 @@ var Elm = function() {
36 this.recalc();
37 this.recalc();
37
38
38 this.recv = function(timestep, changed, parentID) {
39 this.recv = function(timestep, changed, parentID) {
39− if (!this.inbox.hasOwnProperty(timestep)) {
40− this.inbox[timestep] = { changed: false, count: 0 };
41− }
42− var box = this.inbox[timestep];
43− box.count += 1;
40+ this.count += 1;
44− if (changed) { box.changed = true; }
41+ if (changed) { this.changed = true; }
45− if (box.count == args.length) {
42+ if (this.count == args.length) {
46− if (box.changed) { this.recalc() }
43+ if (this.changed) { this.recalc() }
47− send(this, timestep, box.changed);
44+ send(this, timestep, this.changed);
48− delete this.inbox[timestep];
45+ this.changed = false;
46+ this.count = 0;
49 }
47 }
50 };
48 };
51 for (var i = args.length; i--; ) {
49 for (var i = args.length; i--; ) {
@@ -96,12 +94,16 @@ var Elm = function() {
96 this.id = Guid.guid();
94 this.id = Guid.guid();
97 this.value = s2.value;
95 this.value = s2.value;
98 this.kids = [];
96 this.kids = [];
99− this.inbox = {};
97+ this.count = 0;
100
98
101 this.recv = function(timestep, changed, parentID) {
99 this.recv = function(timestep, changed, parentID) {
102 var chng = changed && parentID === s1.id;
100 var chng = changed && parentID === s1.id;
103 if (chng) { this.value = s2.value; }
101 if (chng) { this.value = s2.value; }
102+ this.count += 1;
103+ if (this.count == 2) {
104− send(this, timestep, chng);
104+ send(this, timestep, chng);
105+ this.count = 0;
106+ }
105 };
107 };
106 s1.kids.push(this);
108 s1.kids.push(this);
107 s2.kids.push(this);
109 s2.kids.push(this);