@@ -4,7 +4,7 @@ Elm.Native.Signal = function(elm) {
5 elm.Native = elm.Native || {};
5 elm.Native = elm.Native || {};
6 if (elm.Native.Signal) return elm.Native.Signal;
6 if (elm.Native.Signal) return elm.Native.Signal;
8 var Utils = Elm.Native.Utils(elm);
8 var Utils = Elm.Native.Utils(elm);
9 var Either = Elm.Either(elm);
9 var Either = Elm.Either(elm);
10 var foldl1 = Elm.List(elm).foldl1;
10 var foldl1 = Elm.List(elm).foldl1;
@@ -44,45 +44,45 @@ Elm.Native.Signal = function(elm) {
45 if (changed) { isChanged = true; }
45 if (changed) { isChanged = true; }
46 if (count == n) {
46 if (count == n) {
47− if (isChanged) { this.value = update() }
47+ if (isChanged) { this.value = update(); }
48− send(this, timestep, isChanged);
48+ send(this, timestep, isChanged);
49− isChanged = false;
49+ isChanged = false;
50− count = 0;
50+ count = 0;
53 for (var i = n; i--; ) { args[i].kids.push(this); }
53 for (var i = n; i--; ) { args[i].kids.push(this); }
56 function lift(func, a) {
56 function lift(func, a) {
57− function update() { return func(a.value) }
57+ function update() { return func(a.value); }
58 return new LiftN(update, [a]);
58 return new LiftN(update, [a]);
60 function lift2(func, a, b) {
60 function lift2(func, a, b) {
61− function update() { return A2( func, a.value, b.value ) }
61+ function update() { return A2( func, a.value, b.value ); }
62 return new LiftN(update, [a,b]);
62 return new LiftN(update, [a,b]);
64 function lift3(func, a, b, c) {
64 function lift3(func, a, b, c) {
65− function update() { return A3( func, a.value, b.value, c.value ) }
65+ function update() { return A3( func, a.value, b.value, c.value ); }
66 return new LiftN(update, [a,b,c]);
66 return new LiftN(update, [a,b,c]);
68 function lift4(func, a, b, c, d) {
68 function lift4(func, a, b, c, d) {
69− function update() { return A4( func, a.value, b.value, c.value, d.value ) }
69+ function update() { return A4( func, a.value, b.value, c.value, d.value ); }
70 return new LiftN(update, [a,b,c,d]);
70 return new LiftN(update, [a,b,c,d]);
72 function lift5(func, a, b, c, d, e) {
72 function lift5(func, a, b, c, d, e) {
73− function update() { return A5( func, a.value, b.value, c.value, d.value, e.value ) }
73+ function update() { return A5( func, a.value, b.value, c.value, d.value, e.value ); }
74 return new LiftN(update, [a,b,c,d,e]);
74 return new LiftN(update, [a,b,c,d,e]);
76 function lift6(func, a, b, c, d, e, f) {
76 function lift6(func, a, b, c, d, e, f) {
77− function update() { return A6( func, a.value, b.value, c.value, d.value, e.value, f.value ) }
77+ function update() { return A6( func, a.value, b.value, c.value, d.value, e.value, f.value ); }
78 return new LiftN(update, [a,b,c,d,e,f]);
78 return new LiftN(update, [a,b,c,d,e,f]);
80 function lift7(func, a, b, c, d, e, f, g) {
80 function lift7(func, a, b, c, d, e, f, g) {
81− function update() { return A7( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value ) }
81+ function update() { return A7( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value ); }
82 return new LiftN(update, [a,b,c,d,e,f,g]);
82 return new LiftN(update, [a,b,c,d,e,f,g]);
84 function lift8(func, a, b, c, d, e, f, g, h) {
84 function lift8(func, a, b, c, d, e, f, g, h) {
85− function update() { return A8( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value ) }
85+ function update() { return A8( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value ); }
86 return new LiftN(update, [a,b,c,d,e,f,g,h]);
86 return new LiftN(update, [a,b,c,d,e,f,g,h]);
@@ -95,38 +95,38 @@ Elm.Native.Signal = function(elm) {
95 return new LiftN(update, [input]);
95 return new LiftN(update, [input]);
98− function dropIf(pred,base,input) {
98+ function DropIf(pred,base,input) {
99 this.id = Utils.guid();
99 this.id = Utils.guid();
100 this.value = pred(input.value) ? base : input.value;
100 this.value = pred(input.value) ? base : input.value;
101 this.kids = [];
101 this.kids = [];
102 this.recv = function(timestep, changed, parentID) {
102 this.recv = function(timestep, changed, parentID) {
103− var chng = changed && !pred(input.value);
103+ var chng = changed && !pred(input.value);
104− if (chng) { this.value = input.value; }
104+ if (chng) { this.value = input.value; }
105− send(this, timestep, chng);
105+ send(this, timestep, chng);
107 input.kids.push(this);
107 input.kids.push(this);
110− function dropRepeats(input) {
110+ function DropRepeats(input) {
111 this.id = Utils.guid();
111 this.id = Utils.guid();
112 this.value = input.value;
112 this.value = input.value;
113 this.kids = [];
113 this.kids = [];
114 this.recv = function(timestep, changed, parentID) {
114 this.recv = function(timestep, changed, parentID) {
115− var chng = changed && !Utils.eq(this.value,input.value);
115+ var chng = changed && !Utils.eq(this.value,input.value);
116− if (chng) { this.value = input.value; }
116+ if (chng) { this.value = input.value; }
117− send(this, timestep, chng);
117+ send(this, timestep, chng);
119 input.kids.push(this);
119 input.kids.push(this);
122 function dropWhen(s1,b,s2) {
122 function dropWhen(s1,b,s2) {
123− var pairs = lift2( F2(function(x,y){return {x:x,y:y}}), s1, s2 );
123+ var pairs = lift2( F2(function(x,y){return {x:x,y:y};}), s1, s2 );
124− var dropped = new dropIf(function(p){return p.x},{x:true,y:b},pairs);
124+ var dropped = new DropIf(function(p){return p.x;},{x:true,y:b},pairs);
125− return lift(function(p){return p.y}, dropped)
125+ return lift(function(p){return p.y;}, dropped);
128 function timestamp(a) {
128 function timestamp(a) {
129− function update() { return Utils.Tuple2(Date.now(), a.value) }
129+ function update() { return Utils.Tuple2(Date.now(), a.value); }
130 return new LiftN(update, [a]);
130 return new LiftN(update, [a]);
@@ -134,69 +134,69 @@ Elm.Native.Signal = function(elm) {
134 this.id = Utils.guid();
134 this.id = Utils.guid();
135 this.value = s2.value;
135 this.value = s2.value;
136 this.kids = [];
136 this.kids = [];
138 var count = 0;
138 var count = 0;
139 var isChanged = false;
139 var isChanged = false;
141 this.recv = function(timestep, changed, parentID) {
141 this.recv = function(timestep, changed, parentID) {
142− if (parentID === s1.id) isChanged = changed;
142+ if (parentID === s1.id) isChanged = changed;
143− ++count;
143+ ++count;
144− if (count == 2) {
144+ if (count == 2) {
145− if (isChanged) { this.value = s2.value; }
145+ if (isChanged) { this.value = s2.value; }
146− send(this, timestep, isChanged);
146+ send(this, timestep, isChanged);
147− count = 0;
147+ count = 0;
148− isChanged = false;
148+ isChanged = false;
151 s1.kids.push(this);
151 s1.kids.push(this);
152 s2.kids.push(this);
152 s2.kids.push(this);
155− function sampleOn(s1,s2) { return new SampleOn(s1,s2) }
155+ function sampleOn(s1,s2) { return new SampleOn(s1,s2); }
157 function delay(t,s) {
157 function delay(t,s) {
158 var delayed = new Input(s.value);
158 var delayed = new Input(s.value);
159 var firstEvent = true;
159 var firstEvent = true;
160 function update(v) {
160 function update(v) {
161− if (firstEvent) { firstEvent = false; return; }
161+ if (firstEvent) { firstEvent = false; return; }
162− setTimeout(function() { elm.notify(delayed.id, v) }, t);
162+ setTimeout(function() { elm.notify(delayed.id, v); }, t);
164− function first(a,b) { return a }
164+ function first(a,b) { return a; }
165 return new SampleOn(delayed, lift2(F2(first), delayed, lift(update,s)));
165 return new SampleOn(delayed, lift2(F2(first), delayed, lift(update,s)));
168 function Merge(s1,s2) {
168 function Merge(s1,s2) {
169 this.id = Utils.guid();
169 this.id = Utils.guid();
170 this.value = s1.value;
170 this.value = s1.value;
171 this.kids = [];
171 this.kids = [];
173 var next = null;
173 var next = null;
174 var count = 0;
174 var count = 0;
175 var isChanged = false;
175 var isChanged = false;
177 this.recv = function(timestep, changed, parentID) {
177 this.recv = function(timestep, changed, parentID) {
178− ++count;
178+ ++count;
179− if (changed) {
179+ if (changed) {
180− isChanged = true;
180+ isChanged = true;
181− if (parentID == s2.id && next === null) { next = s2.value; }
181+ if (parentID == s2.id && next === null) { next = s2.value; }
182− if (parentID == s1.id) { next = s1.value; }
182+ if (parentID == s1.id) { next = s1.value; }
185− if (count == 2) {
185+ if (count == 2) {
186− if (isChanged) { this.value = next; next = null; }
186+ if (isChanged) { this.value = next; next = null; }
187− send(this, timestep, isChanged);
187+ send(this, timestep, isChanged);
188− isChanged = false;
188+ isChanged = false;
189− count = 0;
189+ count = 0;
192 s1.kids.push(this);
192 s1.kids.push(this);
193 s2.kids.push(this);
193 s2.kids.push(this);
196− function merge(s1,s2) { return new Merge(s1,s2) }
196+ function merge(s1,s2) { return new Merge(s1,s2); }
197− function merges(ss) { return A2(foldl1, F2(merge), ss) }
197+ function merges(ss) { return A2(foldl1, F2(merge), ss); }
198 function mergeEither(s1,s2) { return new Merge(lift(Either.Left, s1),
198 function mergeEither(s1,s2) { return new Merge(lift(Either.Left, s1),
199− lift(Either.Right,s2)) }
199+ lift(Either.Right,s2)); }
201 function average(sampleSize, s) {
201 function average(sampleSize, s) {
202 var sample = new Array(sampleSize);
202 var sample = new Array(sampleSize);
@@ -206,13 +206,13 @@ Elm.Native.Signal = function(elm) {
206 var full = false;
206 var full = false;
207 var total = 0;
207 var total = 0;
208 function f(n) {
208 function f(n) {
209− total += n - sample[i];
209+ total += n - sample[i];
210− sample[i] = n;
210+ sample[i] = n;
211− var avg = total / Math.max(1, full ? sampleSize : i);
211+ var avg = total / Math.max(1, full ? sampleSize : i);
212− if (++i == sampleSize) { full = true; i = 0; }
212+ if (++i == sampleSize) { full = true; i = 0; }
213− return avg;
213+ return avg;
215− return lift(f,s);pp
215+ return lift(f,s);
218 return elm.Native.Signal = {
218 return elm.Native.Signal = {
@@ -231,17 +231,18 @@ Elm.Native.Signal = function(elm) {
231 merges : merges,
231 merges : merges,
232 mergeEither : F2(mergeEither),
232 mergeEither : F2(mergeEither),
233 average : F2(average),
233 average : F2(average),
234− count : function(s) { return foldp(F2(function(_,c) { return c+1 }), 0, s) },
234+ count : function(s) { return foldp(F2(function(_,c) { return c+1; }), 0, s); },
235 countIf : F2(function(pred,s) {
235 countIf : F2(function(pred,s) {
236− return foldp(F2(function(x,c){return pred(x) ? c+1 : c}), 0, s)}),
236+ return foldp(F2(function(x,c){
237+ return pred(x) ? c+1 : c; }), 0, s)}),
237 keepIf : F3(function(pred,base,sig) {
238 keepIf : F3(function(pred,base,sig) {
238− return new dropIf(function(x) {return !pred(x)},base,sig) }),
239+ return new DropIf(function(x) {return !pred(x);},base,sig); }),
239− dropIf : F3(function(pred,base,sig) { return new dropIf(pred,base,sig) }),
240+ dropIf : F3(function(pred,base,sig) { return new DropIf(pred,base,sig); }),
240 keepWhen : F3(function(s1,b,s2) {
241 keepWhen : F3(function(s1,b,s2) {
241− return dropWhen(lift(function(b){return !b;},s1), b, s2) }),
242+ return dropWhen(lift(function(b){return !b;},s1), b, s2); }),
242 dropWhen : F3(dropWhen),
243 dropWhen : F3(dropWhen),
243− dropRepeats : function(s) { return new dropRepeats(s);},
244+ dropRepeats : function(s) { return new DropRepeats(s);},
244 sampleOn : F2(sampleOn),
245 sampleOn : F2(sampleOn),
245 timestamp : timestamp
246 timestamp : timestamp