@@ -4,7 +4,7 @@ Elm.Native.Signal = function(elm) {
44
55 elm.Native = elm.Native || {};
66 if (elm.Native.Signal) return elm.Native.Signal;
7−
7+
88 var Utils = Elm.Native.Utils(elm);
99 var Either = Elm.Either(elm);
1010 var foldl1 = Elm.List(elm).foldl1;
@@ -44,45 +44,45 @@ Elm.Native.Signal = function(elm) {
4444 ++count;
4545 if (changed) { isChanged = true; }
4646 if (count == n) {
47− if (isChanged) { this.value = update() }
48− send(this, timestep, isChanged);
49− isChanged = false;
50− count = 0;
47+ if (isChanged) { this.value = update(); }
48+ send(this, timestep, isChanged);
49+ isChanged = false;
50+ count = 0;
5151 }
5252 };
5353 for (var i = n; i--; ) { args[i].kids.push(this); }
5454 }
5555
5656 function lift(func, a) {
57− function update() { return func(a.value) }
57+ function update() { return func(a.value); }
5858 return new LiftN(update, [a]);
5959 }
6060 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 ); }
6262 return new LiftN(update, [a,b]);
6363 }
6464 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 ); }
6666 return new LiftN(update, [a,b,c]);
6767 }
6868 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 ); }
7070 return new LiftN(update, [a,b,c,d]);
7171 }
7272 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 ); }
7474 return new LiftN(update, [a,b,c,d,e]);
7575 }
7676 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 ); }
7878 return new LiftN(update, [a,b,c,d,e,f]);
7979 }
8080 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 ); }
8282 return new LiftN(update, [a,b,c,d,e,f,g]);
8383 }
8484 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 ); }
8686 return new LiftN(update, [a,b,c,d,e,f,g,h]);
8787 }
8888
@@ -95,38 +95,38 @@ Elm.Native.Signal = function(elm) {
9595 return new LiftN(update, [input]);
9696 }
9797
98− function dropIf(pred,base,input) {
98+ function DropIf(pred,base,input) {
9999 this.id = Utils.guid();
100100 this.value = pred(input.value) ? base : input.value;
101101 this.kids = [];
102102 this.recv = function(timestep, changed, parentID) {
103− var chng = changed && !pred(input.value);
104− if (chng) { this.value = input.value; }
105− send(this, timestep, chng);
103+ var chng = changed && !pred(input.value);
104+ if (chng) { this.value = input.value; }
105+ send(this, timestep, chng);
106106 };
107107 input.kids.push(this);
108108 }
109109
110− function dropRepeats(input) {
110+ function DropRepeats(input) {
111111 this.id = Utils.guid();
112112 this.value = input.value;
113113 this.kids = [];
114114 this.recv = function(timestep, changed, parentID) {
115− var chng = changed && !Utils.eq(this.value,input.value);
116− if (chng) { this.value = input.value; }
117− send(this, timestep, chng);
115+ var chng = changed && !Utils.eq(this.value,input.value);
116+ if (chng) { this.value = input.value; }
117+ send(this, timestep, chng);
118118 };
119119 input.kids.push(this);
120120 }
121−
121+
122122 function dropWhen(s1,b,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);
125− return lift(function(p){return p.y}, dropped)
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);
125+ return lift(function(p){return p.y;}, dropped);
126126 }
127127
128128 function timestamp(a) {
129− function update() { return Utils.Tuple2(Date.now(), a.value) }
129+ function update() { return Utils.Tuple2(Date.now(), a.value); }
130130 return new LiftN(update, [a]);
131131 }
132132
@@ -134,69 +134,69 @@ Elm.Native.Signal = function(elm) {
134134 this.id = Utils.guid();
135135 this.value = s2.value;
136136 this.kids = [];
137−
137+
138138 var count = 0;
139139 var isChanged = false;
140−
140+
141141 this.recv = function(timestep, changed, parentID) {
142− if (parentID === s1.id) isChanged = changed;
143− ++count;
144− if (count == 2) {
145− if (isChanged) { this.value = s2.value; }
146− send(this, timestep, isChanged);
147− count = 0;
148− isChanged = false;
149− }
142+ if (parentID === s1.id) isChanged = changed;
143+ ++count;
144+ if (count == 2) {
145+ if (isChanged) { this.value = s2.value; }
146+ send(this, timestep, isChanged);
147+ count = 0;
148+ isChanged = false;
149+ }
150150 };
151151 s1.kids.push(this);
152152 s2.kids.push(this);
153153 }
154154
155− function sampleOn(s1,s2) { return new SampleOn(s1,s2) }
155+ function sampleOn(s1,s2) { return new SampleOn(s1,s2); }
156156
157157 function delay(t,s) {
158158 var delayed = new Input(s.value);
159159 var firstEvent = true;
160160 function update(v) {
161− if (firstEvent) { firstEvent = false; return; }
162− setTimeout(function() { elm.notify(delayed.id, v) }, t);
161+ if (firstEvent) { firstEvent = false; return; }
162+ setTimeout(function() { elm.notify(delayed.id, v); }, t);
163163 }
164− function first(a,b) { return a }
164+ function first(a,b) { return a; }
165165 return new SampleOn(delayed, lift2(F2(first), delayed, lift(update,s)));
166166 }
167−
167+
168168 function Merge(s1,s2) {
169169 this.id = Utils.guid();
170170 this.value = s1.value;
171171 this.kids = [];
172−
172+
173173 var next = null;
174174 var count = 0;
175175 var isChanged = false;
176−
176+
177177 this.recv = function(timestep, changed, parentID) {
178− ++count;
179− if (changed) {
180− isChanged = true;
181− if (parentID == s2.id && next === null) { next = s2.value; }
182− if (parentID == s1.id) { next = s1.value; }
183− }
184−
185− if (count == 2) {
186− if (isChanged) { this.value = next; next = null; }
187− send(this, timestep, isChanged);
188− isChanged = false;
189− count = 0;
190− }
178+ ++count;
179+ if (changed) {
180+ isChanged = true;
181+ if (parentID == s2.id && next === null) { next = s2.value; }
182+ if (parentID == s1.id) { next = s1.value; }
183+ }
184+
185+ if (count == 2) {
186+ if (isChanged) { this.value = next; next = null; }
187+ send(this, timestep, isChanged);
188+ isChanged = false;
189+ count = 0;
190+ }
191191 };
192192 s1.kids.push(this);
193193 s2.kids.push(this);
194194 }
195195
196− function merge(s1,s2) { return new Merge(s1,s2) }
197− function merges(ss) { return A2(foldl1, F2(merge), ss) }
196+ function merge(s1,s2) { return new Merge(s1,s2); }
197+ function merges(ss) { return A2(foldl1, F2(merge), ss); }
198198 function mergeEither(s1,s2) { return new Merge(lift(Either.Left, s1),
199− lift(Either.Right,s2)) }
199+ lift(Either.Right,s2)); }
200200
201201 function average(sampleSize, s) {
202202 var sample = new Array(sampleSize);
@@ -206,13 +206,13 @@ Elm.Native.Signal = function(elm) {
206206 var full = false;
207207 var total = 0;
208208 function f(n) {
209− total += n - sample[i];
210− sample[i] = n;
211− var avg = total / Math.max(1, full ? sampleSize : i);
212− if (++i == sampleSize) { full = true; i = 0; }
213− return avg;
209+ total += n - sample[i];
210+ sample[i] = n;
211+ var avg = total / Math.max(1, full ? sampleSize : i);
212+ if (++i == sampleSize) { full = true; i = 0; }
213+ return avg;
214214 }
215− return lift(f,s);pp
215+ return lift(f,s);
216216 }
217217
218218 return elm.Native.Signal = {
@@ -231,17 +231,18 @@ Elm.Native.Signal = function(elm) {
231231 merges : merges,
232232 mergeEither : F2(mergeEither),
233233 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); },
235235 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)}),
237238 keepIf : F3(function(pred,base,sig) {
238− return new dropIf(function(x) {return !pred(x)},base,sig) }),
239− dropIf : F3(function(pred,base,sig) { return new dropIf(pred,base,sig) }),
239+ return new DropIf(function(x) {return !pred(x);},base,sig); }),
240+ dropIf : F3(function(pred,base,sig) { return new DropIf(pred,base,sig); }),
240241 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); }),
242243 dropWhen : F3(dropWhen),
243− dropRepeats : function(s) { return new dropRepeats(s);},
244+ dropRepeats : function(s) { return new DropRepeats(s);},
244245 sampleOn : F2(sampleOn),
245246 timestamp : timestamp
246247 };
247−};
248+};