on master help sign in
Merge pull request #155 from perplexes/lint
4f9ddacEvan Czaplicki
libraries/Dict.elm+22−22
@@ -24,7 +24,7 @@ empty = RBEmpty
24{-- Helpers for checking invariants
24{-- Helpers for checking invariants
25
25
26-- Check that the tree has an equal number of black nodes on each path
26-- Check that the tree has an equal number of black nodes on each path
27−equal_pathLen t =
27+equal_pathLen t =
28 let path_numBlacks t =
28 let path_numBlacks t =
29 case t of
29 case t of
30 RBEmpty -> 1
30 RBEmpty -> 1
@@ -35,14 +35,14 @@ equal_pathLen t =
35 else bl + (if col == Red then 0 else 1)
35 else bl + (if col == Red then 0 else 1)
36 in 0-1 /= path_numBlacks t
36 in 0-1 /= path_numBlacks t
37
37
38−rootBlack t =
38+rootBlack t =
39 case t of
39 case t of
40 RBEmpty -> True
40 RBEmpty -> True
41 RBNode Black _ _ _ _ -> True
41 RBNode Black _ _ _ _ -> True
42 _ -> False
42 _ -> False
43
43
44−redBlack_children t =
44+redBlack_children t =
45− case t of
45+ case t of
46 { RBNode Red _ _ (RBNode Red _ _ _ _) _ -> False
46 { RBNode Red _ _ (RBNode Red _ _ _ _) _ -> False
47 ; RBNode Red _ _ _ (RBNode Red _ _ _ _) -> False
47 ; RBNode Red _ _ _ (RBNode Red _ _ _ _) -> False
48 ; RBEmpty -> True
48 ; RBEmpty -> True
@@ -57,7 +57,7 @@ findExtreme f t =
57 { Nothing -> Just k
57 { Nothing -> Just k
58 ; Just k' -> Just k' }
58 ; Just k' -> Just k' }
59 }
59 }
60−
60+
61findminRbt t = findExtreme fst t
61findminRbt t = findExtreme fst t
62findmaxRbt t = findExtreme snd t
62findmaxRbt t = findExtreme snd t
63
63
@@ -83,7 +83,7 @@ ordered t =
83 }
83 }
84
84
85-- Check that there aren't any right red nodes in the tree *)
85-- Check that there aren't any right red nodes in the tree *)
86−leftLeaning t =
86+leftLeaning t =
87 case t of
87 case t of
88 { RBEmpty -> True
88 { RBEmpty -> True
89 ; RBNode _ _ _ (RBNode Black _ _ _ _) (RBNode Red _ _ _ _) -> False
89 ; RBNode _ _ _ (RBNode Black _ _ _ _) (RBNode Red _ _ _ _) -> False
@@ -92,7 +92,7 @@ leftLeaning t =
92 }
92 }
93
93
94invariants_hold t =
94invariants_hold t =
95− ordered t && rootBlack t && redBlack_children t &&
95+ ordered t && rootBlack t && redBlack_children t &&
96 equal_pathLen t && leftLeaning t
96 equal_pathLen t && leftLeaning t
97
97
98--** End invariant helpers *****
98--** End invariant helpers *****
@@ -101,14 +101,14 @@ invariants_hold t =
101
101
102min : Dict k v -> (k,v)
102min : Dict k v -> (k,v)
103min t =
103min t =
104− case t of
104+ case t of
105 RBNode _ k v RBEmpty _ -> (k,v)
105 RBNode _ k v RBEmpty _ -> (k,v)
106 RBNode _ _ _ l _ -> min l
106 RBNode _ _ _ l _ -> min l
107 RBEmpty -> Error.raise "(min Empty) is not defined"
107 RBEmpty -> Error.raise "(min Empty) is not defined"
108
108
109{--
109{--
110max t =
110max t =
111− case t of
111+ case t of
112 { RBNode _ k v _ RBEmpty -> (k,v)
112 { RBNode _ k v _ RBEmpty -> (k,v)
113 ; RBNode _ _ _ _ r -> max r
113 ; RBNode _ _ _ _ r -> max r
114 ; RBEmpty -> Error.raise "(max Empty) is not defined"
114 ; RBEmpty -> Error.raise "(max Empty) is not defined"
@@ -162,7 +162,7 @@ rotateLeft t =
162 RBNode cy ky vy a (RBNode cz kz vz b c) -> RBNode cy kz vz (RBNode Red ky vy a b) c
162 RBNode cy ky vy a (RBNode cz kz vz b c) -> RBNode cy kz vz (RBNode Red ky vy a b) c
163 _ -> Error.raise "rotateLeft of a node without enough children"
163 _ -> Error.raise "rotateLeft of a node without enough children"
164
164
165−-- rotateRight -- the reverse, and
165+-- rotateRight -- the reverse, and
166-- makes Y have Z's color, and makes Z Red.
166-- makes Y have Z's color, and makes Z Red.
167rotateRight : Dict k v -> Dict k v
167rotateRight : Dict k v -> Dict k v
168rotateRight t =
168rotateRight t =
@@ -172,13 +172,13 @@ rotateRight t =
172
172
173rotateLeftIfNeeded : Dict k v -> Dict k v
173rotateLeftIfNeeded : Dict k v -> Dict k v
174rotateLeftIfNeeded t =
174rotateLeftIfNeeded t =
175− case t of
175+ case t of
176 RBNode _ _ _ _ (RBNode Red _ _ _ _) -> rotateLeft t
176 RBNode _ _ _ _ (RBNode Red _ _ _ _) -> rotateLeft t
177 _ -> t
177 _ -> t
178
178
179rotateRightIfNeeded : Dict k v -> Dict k v
179rotateRightIfNeeded : Dict k v -> Dict k v
180rotateRightIfNeeded t =
180rotateRightIfNeeded t =
181− case t of
181+ case t of
182 RBNode _ _ _ (RBNode Red _ _ (RBNode Red _ _ _ _) _) _ -> rotateRight t
182 RBNode _ _ _ (RBNode Red _ _ (RBNode Red _ _ _ _) _) _ -> rotateRight t
183 _ -> t
183 _ -> t
184
184
@@ -187,14 +187,14 @@ otherColor c = case c of { Red -> Black ; Black -> Red }
187color_flip : Dict k v -> Dict k v
187color_flip : Dict k v -> Dict k v
188color_flip t =
188color_flip t =
189 case t of
189 case t of
190− RBNode c1 bk bv (RBNode c2 ak av la ra) (RBNode c3 ck cv lc rc) ->
190+ RBNode c1 bk bv (RBNode c2 ak av la ra) (RBNode c3 ck cv lc rc) ->
191 RBNode (otherColor c1) bk bv
191 RBNode (otherColor c1) bk bv
192 (RBNode (otherColor c2) ak av la ra)
192 (RBNode (otherColor c2) ak av la ra)
193 (RBNode (otherColor c3) ck cv lc rc)
193 (RBNode (otherColor c3) ck cv lc rc)
194 _ -> Error.raise "color_flip called on a Empty or Node with a Empty child"
194 _ -> Error.raise "color_flip called on a Empty or Node with a Empty child"
195
195
196color_flipIfNeeded : Dict k v -> Dict k v
196color_flipIfNeeded : Dict k v -> Dict k v
197−color_flipIfNeeded t =
197+color_flipIfNeeded t =
198 case t of
198 case t of
199 RBNode _ _ _ (RBNode Red _ _ _ _) (RBNode Red _ _ _ _) -> color_flip t
199 RBNode _ _ _ (RBNode Red _ _ _ _) (RBNode Red _ _ _ _) -> color_flip t
200 _ -> t
200 _ -> t
@@ -202,11 +202,11 @@ color_flipIfNeeded t =
202fixUp t = color_flipIfNeeded (rotateRightIfNeeded (rotateLeftIfNeeded t))
202fixUp t = color_flipIfNeeded (rotateRightIfNeeded (rotateLeftIfNeeded t))
203
203
204ensureBlackRoot : Dict k v -> Dict k v
204ensureBlackRoot : Dict k v -> Dict k v
205−ensureBlackRoot t =
205+ensureBlackRoot t =
206 case t of
206 case t of
207 RBNode Red k v l r -> RBNode Black k v l r
207 RBNode Red k v l r -> RBNode Black k v l r
208 _ -> t
208 _ -> t
209−
209+
210-- Insert a key-value pair into a dictionary. Replaces value when there is
210-- Insert a key-value pair into a dictionary. Replaces value when there is
211-- a collision.
211-- a collision.
212insert : Comparable k -> v -> Dict (Comparable k) v -> Dict (Comparable k) v
212insert : Comparable k -> v -> Dict (Comparable k) v -> Dict (Comparable k) v
@@ -265,7 +265,7 @@ isRedRightLeft t =
265 _ -> False
265 _ -> False
266
266
267moveRedLeft : Dict k v -> Dict k v
267moveRedLeft : Dict k v -> Dict k v
268−moveRedLeft t =
268+moveRedLeft t =
269 let t' = color_flip t in
269 let t' = color_flip t in
270 case t' of
270 case t' of
271 RBNode c k v l r ->
271 RBNode c k v l r ->
@@ -289,9 +289,9 @@ moveRedRightIfNeeded t =
289 if isRedRight t || isRedRightLeft t then t else moveRedRight t
289 if isRedRight t || isRedRightLeft t then t else moveRedRight t
290
290
291deleteMin : Dict k v -> Dict k v
291deleteMin : Dict k v -> Dict k v
292−deleteMin t =
292+deleteMin t =
293 let del t =
293 let del t =
294− case t of
294+ case t of
295 RBNode _ _ _ RBEmpty _ -> RBEmpty
295 RBNode _ _ _ RBEmpty _ -> RBEmpty
296 _ -> case moveRedLeftIfNeeded t of
296 _ -> case moveRedLeftIfNeeded t of
297 RBNode c k v l r -> fixUp (RBNode c k v (del l) r)
297 RBNode c k v l r -> fixUp (RBNode c k v (del l) r)
@@ -314,11 +314,11 @@ deleteMax t =
314-- Remove a key-value pair from a dictionary. If the key is not found,
314-- Remove a key-value pair from a dictionary. If the key is not found,
315-- no changes are made.
315-- no changes are made.
316remove : Comparable k -> Dict (Comparable k) v -> Dict (Comparable k) v
316remove : Comparable k -> Dict (Comparable k) v -> Dict (Comparable k) v
317−remove k t =
317+remove k t =
318 let eq_and_noRightNode t =
318 let eq_and_noRightNode t =
319 case t of { RBNode _ k' _ _ RBEmpty -> k == k' ; _ -> False }
319 case t of { RBNode _ k' _ _ RBEmpty -> k == k' ; _ -> False }
320 eq t = case t of { RBNode _ k' _ _ _ -> k == k' ; _ -> False }
320 eq t = case t of { RBNode _ k' _ _ _ -> k == k' ; _ -> False }
321− delLT t = case moveRedLeftIfNeeded t of
321+ delLT t = case moveRedLeftIfNeeded t of
322 RBNode c k' v l r -> fixUp (RBNode c k' v (del l) r)
322 RBNode c k' v l r -> fixUp (RBNode c k' v (del l) r)
323 RBEmpty -> Error.raise "delLT on Empty"
323 RBEmpty -> Error.raise "delLT on Empty"
324 delEQ t = case t of -- Replace with successor
324 delEQ t = case t of -- Replace with successor
@@ -328,7 +328,7 @@ remove k t =
328 delGT t = case t of
328 delGT t = case t of
329 RBNode c k' v l r -> fixUp (RBNode c k' v l (del r))
329 RBNode c k' v l r -> fixUp (RBNode c k' v l (del r))
330 RBEmpty -> Error.raise "delGT called on a Empty"
330 RBEmpty -> Error.raise "delGT called on a Empty"
331− del t = case t of
331+ del t = case t of
332 RBEmpty -> RBEmpty
332 RBEmpty -> RBEmpty
333 RBNode _ k' _ _ _ ->
333 RBNode _ k' _ _ _ ->
334 if k < k' then delLT t else
334 if k < k' then delLT t else
libraries/Maybe.elm+1−1
@@ -30,4 +30,4 @@ cons mx xs = maybe xs (\x -> x :: xs) mx
30
30
31-- Filters out Nothings and extracts the remaining values.
31-- Filters out Nothings and extracts the remaining values.
32justs : [Maybe a] -> [a]
32justs : [Maybe a] -> [a]
33−justs = List.foldr cons []
33+justs = List.foldr cons []
libraries/Native/Graphics/Input.js+2−2
@@ -57,7 +57,7 @@ Elm.Native.Graphics.Input = function(elm) {
57 btn.elmUp = Render.render(model.up);
57 btn.elmUp = Render.render(model.up);
58 btn.elmHover = Render.render(model.hover);
58 btn.elmHover = Render.render(model.hover);
59 btn.elmDown = Render.render(model.down);
59 btn.elmDown = Render.render(model.down);
60−
60+
61 function replace(node) {
61 function replace(node) {
62 if (node !== btn.firstChild) btn.replaceChild(node, btn.firstChild);
62 if (node !== btn.firstChild) btn.replaceChild(node, btn.firstChild);
63 }
63 }
@@ -218,4 +218,4 @@ Elm.Native.Graphics.Input = function(elm) {
218 passwords:mkTextPool('password')
218 passwords:mkTextPool('password')
219 };
219 };
220
220
221−};
221+};
libraries/Native/Matrix2D.js+9−9
@@ -5,7 +5,7 @@ Elm.Native.Matrix2D = function(elm) {
5 elm.Native = elm.Native || {};
5 elm.Native = elm.Native || {};
6 if (elm.Native.Matrix2D) return elm.Native.Matrix2D;
6 if (elm.Native.Matrix2D) return elm.Native.Matrix2D;
7
7
8− try { Float32Array; } catch(e) { Float32Array = Array; }
8+ if (typeof Float32Array === 'undefined'){ Float32Array = Array; }
9 var A = Float32Array;
9 var A = Float32Array;
10
10
11 // layout of matrix in an array is
11 // layout of matrix in an array is
@@ -26,12 +26,12 @@ Elm.Native.Matrix2D = function(elm) {
26 var s = Math.sin(t);
26 var s = Math.sin(t);
27 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
27 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
28 return new A([m11*c + m12*s, -m11*s + m12*c, m[2],
28 return new A([m11*c + m12*s, -m11*s + m12*c, m[2],
29− m21*c + m22*s, -m21*s + m22*c, m[5]]);
29+ m21*c + m22*s, -m21*s + m22*c, m[5]]);
30 }
30 }
31 function move(x,y,m) {
31 function move(x,y,m) {
32 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
32 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
33 return new A([m11, m12, m11*x + m12*y + m[2],
33 return new A([m11, m12, m11*x + m12*y + m[2],
34− m21, m22, m21*x + m22*y + m[5]]);
34+ m21, m22, m21*x + m22*y + m[5]]);
35 }
35 }
36 function scale(s,m) { return new A([m[0]*s, m[1]*s, m[2], m[3]*s, m[4]*s, m[5]]); }
36 function scale(s,m) { return new A([m[0]*s, m[1]*s, m[2], m[3]*s, m[4]*s, m[5]]); }
37 function scaleX(x,m) { return new A([m[0]*x, m[1], m[2], m[3]*x, m[4], m[5]]); }
37 function scaleX(x,m) { return new A([m[0]*x, m[1], m[2], m[3]*x, m[4], m[5]]); }
@@ -42,11 +42,11 @@ Elm.Native.Matrix2D = function(elm) {
42 function transform(m11, m21, m12, m22, mdx, mdy, n) {
42 function transform(m11, m21, m12, m22, mdx, mdy, n) {
43 var n11 = n[0], n12 = n[1], n21 = n[3], n22 = n[4], ndx = n[2], ndy = n[5];
43 var n11 = n[0], n12 = n[1], n21 = n[3], n22 = n[4], ndx = n[2], ndy = n[5];
44 return new A([m11*n11 + m12*n21,
44 return new A([m11*n11 + m12*n21,
45− m11*n12 + m12*n22,
45+ m11*n12 + m12*n22,
46− m11*ndx + m12*ndy + mdx,
46+ m11*ndx + m12*ndy + mdx,
47− m21*n11 + m22*n21,
47+ m21*n11 + m22*n21,
48− m21*n12 + m22*n22,
48+ m21*n12 + m22*n22,
49− m21*ndx + m22*ndy + mdy]);
49+ m21*ndx + m22*ndy + mdy]);
50 }
50 }
51
51
52 function multiply(m, n) {
52 function multiply(m, n) {
@@ -68,4 +68,4 @@ Elm.Native.Matrix2D = function(elm) {
68 reflectY:reflectY
68 reflectY:reflectY
69 };
69 };
70
70
71−};
71+};
libraries/Native/Prelude.js+36−35
@@ -8,62 +8,63 @@ Elm.Native.Prelude = function(elm) {
8 var Utils = Elm.Native.Utils(elm);
8 var Utils = Elm.Native.Utils(elm);
9 var Char = Elm.Char(elm);
9 var Char = Elm.Char(elm);
10
10
11− function div(a,b) { return (a/b)|0 }
11+ function div(a,b) { return (a/b)|0; }
12− function rem(a,b) { return a % b }
12+ function rem(a,b) { return a % b; }
13 function mod(a,b) {
13 function mod(a,b) {
14 var r = a % b;
14 var r = a % b;
15 var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
15 var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
16+
16 return m === b ? 0 : m;
17 return m === b ? 0 : m;
17 }
18 }
18− function abs(x) { return x < 0 ? -x : x }
19+ function abs(x) { return x < 0 ? -x : x; }
19− function logBase(base,n) { return Math.log(n) / Math.log(base) }
20+ function logBase(base,n) { return Math.log(n) / Math.log(base); }
20− function min(a,b) { return a < b ? a : b }
21+ function min(a,b) { return a < b ? a : b; }
21− function max(a,b) { return a > b ? a : b }
22+ function max(a,b) { return a > b ? a : b; }
22− function clamp(lo,hi,n) { return n < lo ? lo : n > hi ? hi : n }
23+ function clamp(lo,hi,n) { return n < lo ? lo : n > hi ? hi : n; }
23− function xor(a,b) { return a !== b }
24+ function xor(a,b) { return a !== b; }
24− function not(b) { return !b }
25+ function not(b) { return !b; }
25−
26+
26− function truncate(n) { return n|0 }
27+ function truncate(n) { return n|0; }
27−
28+
28− function id(n) { return n }
29+ function id(n) { return n; }
29− function flip(f,a,b) { return A2(f,b,a) }
30+ function flip(f,a,b) { return A2(f,b,a); }
30− function curry(f,a,b) { return f(Utils.Tuple2(a,b)) }
31+ function curry(f,a,b) { return f(Utils.Tuple2(a,b)); }
31− function uncurry(f,v) { return A2(f,v._0,v._1) }
32+ function uncurry(f,v) { return A2(f,v._0,v._1); }
32− function fst(t) { return t._0 }
33+ function fst(t) { return t._0; }
33− function snd(t) { return t._1 }
34+ function snd(t) { return t._1; }
34
35
35 function readInt(str) {
36 function readInt(str) {
36 var s = JS.fromString(str);
37 var s = JS.fromString(str);
37 var len = s.length;
38 var len = s.length;
38− if (len === 0) { return Maybe.Nothing }
39+ if (len === 0) { return Maybe.Nothing; }
39 var start = 0;
40 var start = 0;
40 if (s[0] == '-') {
41 if (s[0] == '-') {
41− if (len === 1) { return Maybe.Nothing }
42+ if (len === 1) { return Maybe.Nothing; }
42− start = 1;
43+ start = 1;
43 }
44 }
44 for (var i = start; i < len; ++i) {
45 for (var i = start; i < len; ++i) {
45− if (!Char.isDigit(s[i])) { return Maybe.Nothing }
46+ if (!Char.isDigit(s[i])) { return Maybe.Nothing; }
46 }
47 }
47− return Maybe.Just(parseInt(s));
48+ return Maybe.Just(parseInt(s, 10));
48 }
49 }
49−
50+
50 function readFloat(str) {
51 function readFloat(str) {
51 var s = JS.fromString(str);
52 var s = JS.fromString(str);
52 var len = s.length;
53 var len = s.length;
53 if (len === 0) { return Maybe.Nothing; }
54 if (len === 0) { return Maybe.Nothing; }
54 var start = 0;
55 var start = 0;
55 if (s[0] == '-') {
56 if (s[0] == '-') {
56− if (len === 1) { return Maybe.Nothing; }
57+ if (len === 1) { return Maybe.Nothing; }
57− start = 1;
58+ start = 1;
58 }
59 }
59 var dotCount = 0;
60 var dotCount = 0;
60 for (var i = start; i < len; ++i) {
61 for (var i = start; i < len; ++i) {
61− if (Char.isDigit(s[i])) { continue; }
62+ if (Char.isDigit(s[i])) { continue; }
62− if (s[i] === '.') {
63+ if (s[i] === '.') {
63− dotCount += 1;
64+ dotCount += 1;
64− if (dotCount <= 1) { continue; }
65+ if (dotCount <= 1) { continue; }
65− }
66+ }
66− return Maybe.Nothing;
67+ return Maybe.Nothing;
67 }
68 }
68 return Maybe.Just(parseFloat(s));
69 return Maybe.Just(parseFloat(s));
69 }
70 }
@@ -113,8 +114,8 @@ Elm.Native.Prelude = function(elm) {
113 };
114 };
114
115
115 function add(Module) {
116 function add(Module) {
116− var M = Module(elm);
117+ var M = Module(elm);
117− for (var k in M) { prelude[k] = M[k] }
118+ for (var k in M) { prelude[k] = M[k]; }
118 }
119 }
119 add(Elm.Native.Show);
120 add(Elm.Native.Show);
120 add(Elm.Signal);
121 add(Elm.Signal);
@@ -124,4 +125,4 @@ Elm.Native.Prelude = function(elm) {
124 add(Elm.Graphics.Element);
125 add(Elm.Graphics.Element);
125
126
126 return elm.Native.Prelude = prelude;
127 return elm.Native.Prelude = prelude;
127−};
128+};
libraries/Native/Show.js+1−1
@@ -96,4 +96,4 @@ Elm.Native.Show = function(elm) {
96 }
96 }
97
97
98 return elm.Native.Show = { show:show };
98 return elm.Native.Show = { show:show };
99−};
99+};
libraries/Native/Signal/Http.js+4−4
@@ -39,16 +39,16 @@ Elm.Native.Http = function(elm) {
39 request.onreadystatechange = function(e) {
39 request.onreadystatechange = function(e) {
40 if (request.readyState === 4) {
40 if (request.readyState === 4) {
41 response.value = (request.status === 200 ?
41 response.value = (request.status === 200 ?
42− { ctor:'Success', _0:JS.toString(request.responseText) } :
42+ { ctor:'Success', _0:JS.toString(request.responseText) } :
43− { ctor:'Failure', _0:request.status, _1:JS.toString(request.statusText) });
43+ { ctor:'Failure', _0:request.status, _1:JS.toString(request.statusText) });
44− setTimeout(function() { updateQueue(queue,responses); }, 0);
44+ setTimeout(function() { updateQueue(queue,responses); }, 0);
45 }
45 }
46 };
46 };
47 request.open(JS.fromString(req.verb), JS.fromString(req.url), true);
47 request.open(JS.fromString(req.verb), JS.fromString(req.url), true);
48 List.map(setHeader)(req.headers);
48 List.map(setHeader)(req.headers);
49 request.send(JS.fromString(req.body));
49 request.send(JS.fromString(req.body));
50 }
50 }
51−
51+
52 function send(requests) {
52 function send(requests) {
53 var responses = Signal.constant(elm.Http.Waiting);
53 var responses = Signal.constant(elm.Http.Waiting);
54 var sender = A2( Signal.lift, registerReq([],responses), requests );
54 var sender = A2( Signal.lift, registerReq([],responses), requests );
libraries/Native/Signal/Keyboard.js+7−7
@@ -47,13 +47,13 @@ Elm.Native.Keyboard = function(elm) {
47 function f(ks) {
47 function f(ks) {
48 var x = 0, y = 0;
48 var x = 0, y = 0;
49 while (ks.ctor == "Cons") {
49 while (ks.ctor == "Cons") {
50− switch (ks._0) {
50+ switch (ks._0) {
51− case left : --x; break;
51+ case left : --x; break;
52− case right: ++x; break;
52+ case right: ++x; break;
53− case up : ++y; break;
53+ case up : ++y; break;
54− case down : --y; break;
54+ case down : --y; break;
55− }
55+ }
56− ks = ks._1;
56+ ks = ks._1;
57 }
57 }
58 return { _:{}, x:x, y:y };
58 return { _:{}, x:x, y:y };
59 }
59 }
libraries/Native/Signal/Random.js+4−4
@@ -11,11 +11,11 @@ Elm.Native.Random = function(elm) {
11 return A2( Signal.lift, f, signal );
11 return A2( Signal.lift, f, signal );
12 }
12 }
13
13
14− function float(signal) {
14+ function flt(signal) {
15− function f(x) { return Math.random() }
15+ function f(x) { return Math.random(); }
16 return A2( Signal.lift, f, signal );
16 return A2( Signal.lift, f, signal );
17 }
17 }
18
18
19− return elm.Native.Random = { range: F3(range), float: float };
19+ return elm.Native.Random = { range: F3(range), float: flt };
20
20
21−};
21+};
libraries/Native/Signal/Signal.js+73−72
@@ -4,7 +4,7 @@ Elm.Native.Signal = function(elm) {
4
4
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;
7−
7+
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) {
44 ++count;
44 ++count;
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;
51 }
51 }
52 };
52 };
53 for (var i = n; i--; ) { args[i].kids.push(this); }
53 for (var i = n; i--; ) { args[i].kids.push(this); }
54 }
54 }
55
55
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]);
59 }
59 }
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]);
63 }
63 }
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]);
67 }
67 }
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]);
71 }
71 }
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]);
75 }
75 }
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]);
79 }
79 }
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]);
83 }
83 }
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]);
87 }
87 }
88
88
@@ -95,38 +95,38 @@ Elm.Native.Signal = function(elm) {
95 return new LiftN(update, [input]);
95 return new LiftN(update, [input]);
96 }
96 }
97
97
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);
106 };
106 };
107 input.kids.push(this);
107 input.kids.push(this);
108 }
108 }
109
109
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);
118 };
118 };
119 input.kids.push(this);
119 input.kids.push(this);
120 }
120 }
121−
121+
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);
126 }
126 }
127
127
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]);
131 }
131 }
132
132
@@ -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 = [];
137−
137+
138 var count = 0;
138 var count = 0;
139 var isChanged = false;
139 var isChanged = false;
140−
140+
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;
149− }
149+ }
150 };
150 };
151 s1.kids.push(this);
151 s1.kids.push(this);
152 s2.kids.push(this);
152 s2.kids.push(this);
153 }
153 }
154
154
155− function sampleOn(s1,s2) { return new SampleOn(s1,s2) }
155+ function sampleOn(s1,s2) { return new SampleOn(s1,s2); }
156
156
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);
163 }
163 }
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)));
166 }
166 }
167−
167+
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 = [];
172−
172+
173 var next = null;
173 var next = null;
174 var count = 0;
174 var count = 0;
175 var isChanged = false;
175 var isChanged = false;
176−
176+
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; }
183− }
183+ }
184−
184+
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;
190− }
190+ }
191 };
191 };
192 s1.kids.push(this);
192 s1.kids.push(this);
193 s2.kids.push(this);
193 s2.kids.push(this);
194 }
194 }
195
195
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)); }
200
200
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;
214 }
214 }
215− return lift(f,s);pp
215+ return lift(f,s);
216 }
216 }
217
217
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
246 };
247 };
247−};
248+};
libraries/Native/Signal/Time.js+7−7
@@ -12,9 +12,9 @@ Elm.Native.Time = function(elm) {
12 var ticker = Signal.constant(diff);
12 var ticker = Signal.constant(diff);
13 function tick(zero) { return function() {
13 function tick(zero) { return function() {
14 curr = Date.now();
14 curr = Date.now();
15− diff = zero ? 0 : curr - prev;
15+ diff = zero ? 0 : curr - prev;
16− prev = curr;
16+ prev = curr;
17− elm.notify(ticker.id, diff);
17+ elm.notify(ticker.id, diff);
18 };
18 };
19 }
19 }
20 var timeoutID = 0;
20 var timeoutID = 0;
@@ -22,14 +22,14 @@ Elm.Native.Time = function(elm) {
22 if (isOn) {
22 if (isOn) {
23 timeoutID = setTimeout(tick(!wasOn && isOn), msPerFrame);
23 timeoutID = setTimeout(tick(!wasOn && isOn), msPerFrame);
24 } else if (wasOn) {
24 } else if (wasOn) {
25− clearTimeout(timeoutID);
25+ clearTimeout(timeoutID);
26 }
26 }
27 wasOn = isOn;
27 wasOn = isOn;
28 return t;
28 return t;
29 }
29 }
30 return A3( Signal.lift2, F2(f), isOn, ticker );
30 return A3( Signal.lift2, F2(f), isOn, ticker );
31 }
31 }
32−
32+
33 function everyWhen(t, isOn) {
33 function everyWhen(t, isOn) {
34 var clock = Signal.constant(Date.now());
34 var clock = Signal.constant(Date.now());
35 function tellTime() { elm.notify(clock.id, Date.now()); }
35 function tellTime() { elm.notify(clock.id, Date.now()); }
@@ -38,7 +38,7 @@ Elm.Native.Time = function(elm) {
38 }
38 }
39
39
40 function since(t, s) {
40 function since(t, s) {
41− function cmp(a,b) { return !Utils.eq(a,b) }
41+ function cmp(a,b) { return !Utils.eq(a,b); }
42 var dcount = Signal.count(A2(Signal.delay, t, s));
42 var dcount = Signal.count(A2(Signal.delay, t, s));
43 return A3( Signal.lift2, F2(cmp), Signal.count(s), dcount );
43 return A3( Signal.lift2, F2(cmp), Signal.count(s), dcount );
44 }
44 }
@@ -70,4 +70,4 @@ Elm.Native.Time = function(elm) {
70 read : read
70 read : read
71 };
71 };
72
72
73−};
73+};
libraries/Native/Signal/Window.js+2−2
@@ -21,10 +21,10 @@ Elm.Native.Window = function(elm) {
21
21
22 // Do not move width and height into Elm. By setting the default number of kids,
22 // Do not move width and height into Elm. By setting the default number of kids,
23 // the resize listener can be detached.
23 // the resize listener can be detached.
24− var width = A2(Signal.lift, function(p){return p._0}, dimensions);
24+ var width = A2(Signal.lift, function(p){return p._0;}, dimensions);
25 width.defaultNumberOfKids = 0;
25 width.defaultNumberOfKids = 0;
26
26
27− var height = A2(Signal.lift, function(p){return p._1}, dimensions);
27+ var height = A2(Signal.lift, function(p){return p._1;}, dimensions);
28 height.defaultNumberOfKids = 0;
28 height.defaultNumberOfKids = 0;
29
29
30 function resizeIfNeeded() {
30 function resizeIfNeeded() {
libraries/Native/Utils.js+22−20
@@ -13,8 +13,8 @@ Elm.Native.Utils = function(elm) {
13 return c === Object.keys(y).length;
13 return c === Object.keys(y).length;
14 }
14 }
15 if (typeof x === 'function') {
15 if (typeof x === 'function') {
16− throw new Error('Equality error: general function equality is ' +
16+ throw new Error('Equality error: general function equality is ' +
17− 'undecidable, and therefore, unsupported');
17+ 'undecidable, and therefore, unsupported');
18 }
18 }
19 return x === y;
19 return x === y;
20 }
20 }
@@ -22,18 +22,20 @@ Elm.Native.Utils = function(elm) {
22 var EQ = 0, LT = 1, GT = 2, ord = ['EQ','LT','GT'];
22 var EQ = 0, LT = 1, GT = 2, ord = ['EQ','LT','GT'];
23 function compare(x,y) { return { ctor: ord[cmp(x,y)] } }
23 function compare(x,y) { return { ctor: ord[cmp(x,y)] } }
24 function cmp(x,y) {
24 function cmp(x,y) {
25+ var ord;
25 if (typeof x !== 'object') return x === y ? EQ : x < y ? LT : GT;
26 if (typeof x !== 'object') return x === y ? EQ : x < y ? LT : GT;
26
27
27 if (x.ctor === "Cons" || x.ctor === "Nil") {
28 if (x.ctor === "Cons" || x.ctor === "Nil") {
28− while (true) {
29+ while (true) {
29− if (x.ctor === "Nil" && y.ctor === "Nil") return EQ;
30+ if (x.ctor === "Nil" && y.ctor === "Nil") return EQ;
30− if (x.ctor !== y.ctor) return {ctor: x.ctor==='Nil'?LT:GT};
31+ if (x.ctor !== y.ctor) return x.ctor === 'Nil' ? LT : GT;
31− var ord = cmp(x._0, y._0);
32+ ord = cmp(x._0, y._0);
32− if (ord !== EQ) return ord;
33+ if (ord !== EQ) return ord;
33− x = x._1;
34+ x = x._1;
34− y = y._1;
35+ y = y._1;
35− }
36+ }
36 }
37 }
38+
37 if (x.ctor.slice(0,5) === 'Tuple') {
39 if (x.ctor.slice(0,5) === 'Tuple') {
38 var n = x.ctor.slice(5) - 0;
40 var n = x.ctor.slice(5) - 0;
39 var err = 'cannot compare tuples with more than 6 elements.';
41 var err = 'cannot compare tuples with more than 6 elements.';
@@ -48,8 +50,8 @@ Elm.Native.Utils = function(elm) {
48 return EQ;
50 return EQ;
49 }
51 }
50 throw new Error('Comparison error: comparison is only defined on ints, ' +
52 throw new Error('Comparison error: comparison is only defined on ints, ' +
51− 'floats, times, chars, strings, lists of comparable values, ' +
53+ 'floats, times, chars, strings, lists of comparable values, ' +
52− 'and tuples of comparable values.')
54+ 'and tuples of comparable values.')
53 }
55 }
54
56
55
57
@@ -68,11 +70,11 @@ Elm.Native.Utils = function(elm) {
68 function remove(x,r) {
70 function remove(x,r) {
69 var o = copy(r);
71 var o = copy(r);
70 if (x in o._) {
72 if (x in o._) {
71− o[x] = o._[x][0];
73+ o[x] = o._[x][0];
72− o._[x] = o._[x].slice(1);
74+ o._[x] = o._[x].slice(1);
73− if (o._[x].length === 0) { delete o._[x]; }
75+ if (o._[x].length === 0) { delete o._[x]; }
74 } else {
76 } else {
75− delete o[x];
77+ delete o[x];
76 }
78 }
77 return o;
79 return o;
78 }
80 }
@@ -80,8 +82,8 @@ Elm.Native.Utils = function(elm) {
80 function replace(kvs,r) {
82 function replace(kvs,r) {
81 var o = copy(r);
83 var o = copy(r);
82 for (var i = kvs.length; i--; ) {
84 for (var i = kvs.length; i--; ) {
83− var kvsi = kvs[i];
85+ var kvsi = kvs[i];
84− o[kvsi[0]] = kvsi[1];
86+ o[kvsi[0]] = kvsi[1];
85 }
87 }
86 return o;
88 return o;
87 }
89 }
@@ -103,7 +105,7 @@ Elm.Native.Utils = function(elm) {
103 t.style.visibility = "hidden";
105 t.style.visibility = "hidden";
104 t.style.styleFloat = "left";
106 t.style.styleFloat = "left";
105 t.style.cssFloat = "left";
107 t.style.cssFloat = "left";
106−
108+
107 elm.node.appendChild(t);
109 elm.node.appendChild(t);
108 var w = t.clientWidth;
110 var w = t.clientWidth;
109 var h = t.clientHeight;
111 var h = t.clientHeight;
@@ -144,4 +146,4 @@ Elm.Native.Utils = function(elm) {
144 htmlHeight: F2(htmlHeight),
146 htmlHeight: F2(htmlHeight),
145 toFloat: function(x){return x}
147 toFloat: function(x){return x}
146 };
148 };
147−};
149+};
runtime/Init.js+7−7
@@ -27,7 +27,7 @@ function init(display, container, module) {
27 var signalGraph = null;
27 var signalGraph = null;
28 var inputs = [];
28 var inputs = [];
29 var visualModel = null;
29 var visualModel = null;
30−
30+
31 function notify(id, v) {
31 function notify(id, v) {
32 var timestep = Date.now();
32 var timestep = Date.now();
33 var hasListener = false;
33 var hasListener = false;
@@ -42,7 +42,7 @@ function init(display, container, module) {
42 container.offsetX = 0;
42 container.offsetX = 0;
43 container.offsetY = 0;
43 container.offsetY = 0;
44
44
45− // create the actuall RTS. Any impure modules will attach themselves to this
45+ // create the actual RTS. Any impure modules will attach themselves to this
46 // object. This permits many Elm programs to be embedded per document.
46 // object. This permits many Elm programs to be embedded per document.
47 var elm = { notify:notify,
47 var elm = { notify:notify,
48 node:container,
48 node:container,
@@ -53,7 +53,7 @@ function init(display, container, module) {
53
53
54 // Set up methods to communicate with Elm program from JS.
54 // Set up methods to communicate with Elm program from JS.
55 function send(name, value) {
55 function send(name, value) {
56− if (typeof value === 'undefined') return function(v) { return send(name,v) };
56+ if (typeof value === 'undefined') return function(v) { return send(name,v); };
57 var e = document.createEvent('Event');
57 var e = document.createEvent('Event');
58 e.initEvent(name + '_' + elm.id, true, true);
58 e.initEvent(name + '_' + elm.id, true, true);
59 e.value = value;
59 e.value = value;
@@ -66,8 +66,8 @@ function init(display, container, module) {
66 recv('log', function(e) {console.log(e.value)});
66 recv('log', function(e) {console.log(e.value)});
67 recv('title', function(e) {document.title = e.value});
67 recv('title', function(e) {document.title = e.value});
68 recv('redirect', function(e) {
68 recv('redirect', function(e) {
69− if (e.value.length > 0) { window.location = e.value; }
69+ if (e.value.length > 0) { window.location = e.value; }
70− });
70+ });
71
71
72 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
72 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
73 if (display === ElmRuntime.Display.NONE) {
73 if (display === ElmRuntime.Display.NONE) {
@@ -78,7 +78,7 @@ function init(display, container, module) {
78
78
79 // evaluate the given module and extract its 'main' value.
79 // evaluate the given module and extract its 'main' value.
80 signalGraph = module(elm).main;
80 signalGraph = module(elm).main;
81−
81+
82 // make sure the signal graph is actually a signal, extract the visual model,
82 // make sure the signal graph is actually a signal, extract the visual model,
83 // and filter out any unused inputs.
83 // and filter out any unused inputs.
84 var Signal = Elm.Signal(elm);
84 var Signal = Elm.Signal(elm);
@@ -101,7 +101,7 @@ function init(display, container, module) {
101 });
101 });
102 return value;
102 return value;
103 }
103 }
104−
104+
105 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
105 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
106
106
107 return { send : send, recv : recv, node : container };
107 return { send : send, recv : recv, node : container };
runtime/Render/Collage.js+36−25
@@ -16,8 +16,8 @@ function trace(ctx, path) {
16 ctx.moveTo(points[i]._0, points[i]._1);
16 ctx.moveTo(points[i]._0, points[i]._1);
17 while (i--) { ctx.lineTo(points[i]._0, points[i]._1); }
17 while (i--) { ctx.lineTo(points[i]._0, points[i]._1); }
18 if (path.closed) {
18 if (path.closed) {
19− i = points.length - 1;
19+ i = points.length - 1;
20− ctx.lineTo(points[i]._0, points[i]._1);
20+ ctx.lineTo(points[i]._0, points[i]._1);
21 }
21 }
22}
22}
23
23
@@ -38,26 +38,26 @@ function customLineHelp(ctx, style, path) {
38 var draw = true, segmentLength = pattern[0];
38 var draw = true, segmentLength = pattern[0];
39 ctx.moveTo(x0,y0);
39 ctx.moveTo(x0,y0);
40 while (i--) {
40 while (i--) {
41− x1 = points[i]._0; y1 = points[i]._1;
41+ x1 = points[i]._0; y1 = points[i]._1;
42− dx = x1 - x0; dy = y1 - y0;
42+ dx = x1 - x0; dy = y1 - y0;
43− remaining = Math.sqrt(dx * dx + dy * dy);
43+ remaining = Math.sqrt(dx * dx + dy * dy);
44− while (segmentLength <= remaining) {
44+ while (segmentLength <= remaining) {
45− x0 += dx * segmentLength / remaining;
45+ x0 += dx * segmentLength / remaining;
46− y0 += dy * segmentLength / remaining;
46+ y0 += dy * segmentLength / remaining;
47− ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
47+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
48− // update starting position
48+ // update starting position
49− dx = x1 - x0; dy = y1 - y0;
49+ dx = x1 - x0; dy = y1 - y0;
50− remaining = Math.sqrt(dx * dx + dy * dy);
50+ remaining = Math.sqrt(dx * dx + dy * dy);
51− // update pattern
51+ // update pattern
52− draw = !draw;
52+ draw = !draw;
53− pindex = (pindex + 1) % plen;
53+ pindex = (pindex + 1) % plen;
54− segmentLength = pattern[pindex];
54+ segmentLength = pattern[pindex];
55− }
55+ }
56− if (remaining > 0) {
56+ if (remaining > 0) {
57− ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
57+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
58− segmentLength -= remaining;
58+ segmentLength -= remaining;
59− }
59+ }
60− x0 = x1; y0 = y1;
60+ x0 = x1; y0 = y1;
61 }
61 }
62}
62}
63
63
@@ -112,8 +112,19 @@ function drawImage(redo, ctx, form) {
112 var img = new Image();
112 var img = new Image();
113 img.onload = redo;
113 img.onload = redo;
114 img.src = fromString(form._3);
114 img.src = fromString(form._3);
115− var w = form._0, h = form._1, pos = form._2;
115+ var w = form._0,
116− ctx.drawImage(img, pos._0, pos._1, w, h, -w/2, -h/2, w, h);
116+ h = form._1,
117+ pos = form._2,
118+ srcX = pos._0,
119+ srcY = pos._1,
120+ srcW = w,
121+ srcH = h,
122+ destX = -w/2,
123+ destY = -h/2,
124+ destW = w,
125+ destH = h;
126+
127+ ctx.drawImage(img, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
117}
128}
118
129
119function renderForm(redo, ctx, form) {
130function renderForm(redo, ctx, form) {
@@ -317,4 +328,4 @@ function update(div, _, model) {
317
328
318return { render:render, update:update };
329return { render:render, update:update };
319
330
320−};
331+};
runtime/Utils.js+5−5
@@ -15,11 +15,11 @@ ElmRuntime.use = function(M) {
15function isAlive(input) {
15function isAlive(input) {
16 if (!('defaultNumberOfKids' in input)) return true;
16 if (!('defaultNumberOfKids' in input)) return true;
17 var len = input.kids.length;
17 var len = input.kids.length;
18− if (len == 0) return false;
18+ if (len === 0) return false;
19 if (len > input.defaultNumberOfKids) return true;
19 if (len > input.defaultNumberOfKids) return true;
20 var alive = false;
20 var alive = false;
21 for (var i = len; i--; ) {
21 for (var i = len; i--; ) {
22− alive = alive || isAlive(input.kids[i]);
22+ alive = alive || isAlive(input.kids[i]);
23 }
23 }
24 return alive;
24 return alive;
25}
25}
@@ -27,7 +27,7 @@ function isAlive(input) {
27ElmRuntime.filterDeadInputs = function(inputs) {
27ElmRuntime.filterDeadInputs = function(inputs) {
28 var temp = [];
28 var temp = [];
29 for (var i = inputs.length; i--; ) {
29 for (var i = inputs.length; i--; ) {
30− if (isAlive(inputs[i])) temp.push(inputs[i]);
30+ if (isAlive(inputs[i])) temp.push(inputs[i]);
31 }
31 }
32 return temp;
32 return temp;
33};
33};
@@ -36,8 +36,8 @@ ElmRuntime.filterDeadInputs = function(inputs) {
36var vendors = ['ms', 'moz', 'webkit', 'o'];
36var vendors = ['ms', 'moz', 'webkit', 'o'];
37for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
37for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
38 window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame'];
38 window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame'];
39− window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame']
39+ window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame'] ||
40− || window[vendors[i]+'CancelRequestAnimationFrame'];
40+ window[vendors[i]+'CancelRequestAnimationFrame'];
41}
41}
42
42
43if (window.requestAnimationFrame && window.cancelAnimationFrame) {
43if (window.requestAnimationFrame && window.cancelAnimationFrame) {