on master help sign in
List module dependencies in elm and js code.
d53cecfevancz
core/Color.elm+4−4
@@ -8,7 +8,7 @@ module Graphics.Color (rgba,rgb,hsva,hsv,
8 violet,forestGreen,
8 violet,forestGreen,
9 black,white,gray,grey) where
9 black,white,gray,grey) where
10
10
11−import Native.Color as Native
11+import Native.Color
12
12
13data Color = Color Int Int Int Float
13data Color = Color Int Int Int Float
14
14
@@ -39,6 +39,6 @@ purple = Color 128 0 128 1
39forestGreen = Color 34 139 34 1
39forestGreen = Color 34 139 34 1
40violet = Color 238 130 238 1
40violet = Color 238 130 238 1
41
41
42−complement = Native.complement
42+complement = Native.Color.complement
43−hsva = Native.hsva
43+hsva = Native.Color.hsva
44−hsv = Native.hsv
44+hsv = Native.Color.hsv
core/Date.elm+2
@@ -1,6 +1,8 @@
1
1
2module Date where
2module Date where
3
3
4+import Native.Date
5+
4data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
6data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
5
7
6data Month = Jan | Feb | Mar | Apr
8data Month = Jan | Feb | Mar | Apr
core/HTTP.elm+2
@@ -4,6 +4,8 @@
4
4
5module HTTP where
5module HTTP where
6
6
7+import Native.HTTP
8+
7-- The datatype for responses. Success contains only the returned message.
9-- The datatype for responses. Success contains only the returned message.
8-- Failures contain both an error code and an error message.
10-- Failures contain both an error code and an error message.
9data Response a = Success a | Waiting | Failure Int String
11data Response a = Success a | Waiting | Failure Int String
core/Keyboard.elm+4
@@ -4,6 +4,10 @@
4
4
5module Keyboard where
5module Keyboard where
6
6
7+import Native.Keyboard
8+
9+type KeyCode = Int
10+
7-- A signal of records indicating which arrow keys are pressed.
11-- A signal of records indicating which arrow keys are pressed.
8--
12--
9-- `{ x = 0, y = 0 }` when pressing no arrows.
13-- `{ x = 0, y = 0 }` when pressing no arrows.
core/Keyboard/Raw.elm+7
@@ -1,5 +1,12 @@
1
1
2module Keyboard.Raw where
2module Keyboard.Raw where
3
3
4+import Native.Keyboard.Raw
5+
6+type KeyCode = Int
7+
8+keysDown : Signal [KeyCode]
4keysDown = Native.Keyboard.Raw.keysDown
9keysDown = Native.Keyboard.Raw.keysDown
10+
11+charPressed : Signal (Maybe Char)
5charPressed = Native.Keyboard.Raw.charPressed
12charPressed = Native.Keyboard.Raw.charPressed
core/List.elm+22−22
@@ -1,64 +1,64 @@
1
1
2module List where
2module List where
3
3
4−import Native.List as Native
4+import Native.List
5
5
6head : [a] -> a
6head : [a] -> a
7−head = Native.head
7+head = Native.List.head
8
8
9tail : [a] -> [a]
9tail : [a] -> [a]
10−tail = Native.tail
10+tail = Native.List.tail
11
11
12last : [a] -> a
12last : [a] -> a
13−last = Native.last
13+last = Native.List.last
14
14
15map : (a -> b) -> [a] -> [b]
15map : (a -> b) -> [a] -> [b]
16−map = Native.map
16+map = Native.List.map
17
17
18foldl : (a -> b -> b) -> b -> [a] -> b
18foldl : (a -> b -> b) -> b -> [a] -> b
19−foldl = Native.foldl
19+foldl = Native.List.foldl
20
20
21foldr : (a -> b -> b) -> b -> [a] -> b
21foldr : (a -> b -> b) -> b -> [a] -> b
22−foldr = Native.foldr
22+foldr = Native.List.foldr
23
23
24foldl1 : (a -> a -> a) -> [a] -> a
24foldl1 : (a -> a -> a) -> [a] -> a
25−foldl1 = Native.foldl1
25+foldl1 = Native.List.foldl1
26
26
27foldr1 : (a -> a -> a) -> [a] -> a
27foldr1 : (a -> a -> a) -> [a] -> a
28−foldr1 = Native.foldr1
28+foldr1 = Native.List.foldr1
29
29
30scanl : (a -> b -> b) -> b -> [a] -> [b]
30scanl : (a -> b -> b) -> b -> [a] -> [b]
31−scanl = Native.scanl
31+scanl = Native.List.scanl
32
32
33scanl1 : (a -> a -> a) -> [a] -> [a]
33scanl1 : (a -> a -> a) -> [a] -> [a]
34−scanl1 = Native.scanl1
34+scanl1 = Native.List.scanl1
35
35
36filter : (a -> Bool) -> [a] -> [a]
36filter : (a -> Bool) -> [a] -> [a]
37−filter = Native.filter
37+filter = Native.List.filter
38
38
39length : [a] -> Int
39length : [a] -> Int
40−length = Native.length
40+length = Native.List.length
41
41
42reverse : [a] -> [a]
42reverse : [a] -> [a]
43−reverse = Native.reverse
43+reverse = Native.List.reverse
44
44
45concat : [[a]] -> [a]
45concat : [[a]] -> [a]
46−concat = Native.foldr (++) []
46+concat = Native.List.foldr (++) []
47
47
48concatMap : (a -> [b]) -> [a] -> [b]
48concatMap : (a -> [b]) -> [a] -> [b]
49−concatMap f = concat . Native.map f
49+concatMap f = concat . Native.List.map f
50
50
51all : (a -> Bool) -> [a] -> Bool
51all : (a -> Bool) -> [a] -> Bool
52−all pred = Native.all
52+all pred = Native.List.all
53
53
54any : (a -> Bool) -> [a] -> Bool
54any : (a -> Bool) -> [a] -> Bool
55−any = Native.any
55+any = Native.List.any
56
56
57and : [Bool] -> Bool
57and : [Bool] -> Bool
58−and = Native.all id
58+and = Native.List.all id
59
59
60or : [Bool] -> Bool
60or : [Bool] -> Bool
61−or = Native.any id
61+or = Native.List.any id
62
62
63sum = foldl (+) 0
63sum = foldl (+) 0
64product = foldl (*) 1
64product = foldl (*) 1
@@ -73,10 +73,10 @@ partition pred lst =
73 if pred x then (x::as,bs) else (as,x::bs)
73 if pred x then (x::as,bs) else (as,x::bs)
74
74
75zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
75zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
76−zipWith = Native.zipWith
76+zipWith = Native.List.zipWith
77
77
78zip : [a] -> [b] -> [(a,b)]
78zip : [a] -> [b] -> [(a,b)]
79−zip = Native.zip
79+zip = Native.List.zip
80
80
81unzip : [(a,b)] -> ([a],[b])
81unzip : [(a,b)] -> ([a],[b])
82unzip pairs =
82unzip pairs =
core/Mouse.elm+2
@@ -1,6 +1,8 @@
1
1
2module Mouse where
2module Mouse where
3
3
4+import Native.Mouse
5+
4-- The current mouse position.
6-- The current mouse position.
5position : Signal (Int,Int)
7position : Signal (Int,Int)
6position = Native.Mouse.position
8position = Native.Mouse.position
core/Native/Color.js+2−2
@@ -1,5 +1,5 @@
1
1
2−function nativeColor() {
2+(function() {
3"use strict";
3"use strict";
4
4
5function extract(c) {
5function extract(c) {
@@ -62,4 +62,4 @@ Elm.Native.Color = {hsva:hsva,
62 hsv:hsv,
62 hsv:hsv,
63 complement:complement,
63 complement:complement,
64 extract:extract};
64 extract:extract};
65−}
65+}());
core/Native/Date.js+10−5
@@ -1,12 +1,17 @@
1
1
2−function nativeDate(Maybe, JS) {
2+/*
3+import Maybe
4+import JavaScript
5+*/
6+
7+(function() {
3'use strict';
8'use strict';
4
9
5 function dateNow() { return new window.Date; }
10 function dateNow() { return new window.Date; }
6 function readDate(str) {
11 function readDate(str) {
7− var d = new window.Date(JS.castStringToJSString(str));
12+ var d = new window.Date(Elm.JavaScript.castStringToJSString(str));
8− if (isNaN(d.getTime())) return Maybe.Nothing;
13+ if (isNaN(d.getTime())) return Elm.Maybe.Nothing;
9− return Maybe.Just(d);
14+ return Elm.Maybe.Just(d);
10 }
15 }
11
16
12 var dayTable = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
17 var dayTable = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
@@ -25,4 +30,4 @@ function nativeDate(Maybe, JS) {
25 dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; },
30 dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; },
26 };
31 };
27
32
28−}
33+}());
core/Native/HTTP.js+9−3
@@ -1,6 +1,12 @@
1
1
2+/*
3+import JavaScript
4+import List
5+import Signal
6+*/
7+
2−function nativeHTTP() {
8+(function() {
3− "use strict";
9+ 'use strict';
4
10
5 function registerReq(queue,responses) { return function(req) {
11 function registerReq(queue,responses) { return function(req) {
6 if (req.url !== "") { sendReq(queue,responses,req); }
12 if (req.url !== "") { sendReq(queue,responses,req); }
@@ -53,4 +59,4 @@ function nativeHTTP() {
53 }
59 }
54
60
55 Elm.Native.HTTP = {send:send};
61 Elm.Native.HTTP = {send:send};
56−}
62+}());
core/Native/Keyboard.js+8−2
@@ -1,4 +1,10 @@
1+/*
2+import Signal
3+import Keyboard.Raw
4+import List
5+*/
6+
1−function nativeKeyboard() {
7+(function() {
2 'use strict';
8 'use strict';
3
9
4 function keySignal(f) {
10 function keySignal(f) {
@@ -31,4 +37,4 @@ function nativeKeyboard() {
31
37
32 Elm.Native.Keyboard = { isDown:is, dir:dir };
38 Elm.Native.Keyboard = { isDown:is, dir:dir };
33
39
34−}
40+}());
core/Native/Keyboard/Raw.js+9−2
@@ -1,4 +1,11 @@
1+/*
2+import Signal
3+import List
4+*/
5+
1−function nativeKeyboardRaw() {
6+(function() {
7+ 'use strict';
8+
2 var keysDown = Elm.Signal.constant(Elm.Native.List.Nil);
9 var keysDown = Elm.Signal.constant(Elm.Native.List.Nil);
3 var charPressed = Elm.Signal.constant(Elm.Maybe.Nothing);
10 var charPressed = Elm.Signal.constant(Elm.Maybe.Nothing);
4
11
@@ -30,4 +37,4 @@ function nativeKeyboardRaw() {
30 });
37 });
31
38
32 Elm.Native.Keyboard.Raw = {keysDown:keysDown, charPressed:charPressed};
39 Elm.Native.Keyboard.Raw = {keysDown:keysDown, charPressed:charPressed};
33−}
40+}());
core/Native/List.js+2−4
@@ -1,4 +1,4 @@
1−function nativeList() {
1+(function() {
2 "use strict";
2 "use strict";
3
3
4 var Nil = { ctor:'Nil' };
4 var Nil = { ctor:'Nil' };
@@ -189,8 +189,6 @@ function nativeList() {
189 }
189 }
190 }
190 }
191
191
192− function concatA(
193−
194 Elm.Native.List = {
192 Elm.Native.List = {
195 head:head,
193 head:head,
196 tail:tail,
194 tail:tail,
@@ -215,4 +213,4 @@ function nativeList() {
215 sort:sort,
213 sort:sort,
216 take:take,
214 take:take,
217 drop:drop};
215 drop:drop};
218−}
216+}());
core/Native/Mouse.js+21−13
@@ -1,6 +1,14 @@
1+/*
2+import Signal
3+import Native.Misc
4+*/
1
5
2−function nativeMouse(elm) {
6+(function() {
7+ 'use strict';
8+
9+ var Misc = Elm.Native.Misc;
10+
3− var position = Elm.Signal.constant(Value.Tuple(0,0));
11+ var position = Elm.Signal.constant(Misc.Tuple(0,0));
4 position.defaultNumberOfKids = 2;
12 position.defaultNumberOfKids = 2;
5
13
6 // do not get rid of x and y. By setting their default number
14 // do not get rid of x and y. By setting their default number
@@ -13,7 +21,7 @@ function nativeMouse(elm) {
13
21
14 var isDown = Elm.Signal.constant(false);
22 var isDown = Elm.Signal.constant(false);
15 var isClicked = Elm.Signal.constant(false);
23 var isClicked = Elm.Signal.constant(false);
16− var clicks = Elm.Signal.constant(Value.Tuple());
24+ var clicks = Elm.Signal.constant(Misc.Tuple());
17
25
18 function getXY(e) {
26 function getXY(e) {
19 var posx = 0;
27 var posx = 0;
@@ -28,27 +36,27 @@ function nativeMouse(elm) {
28 posy = e.clientY + document.body.scrollTop +
36 posy = e.clientY + document.body.scrollTop +
29 document.documentElement.scrollTop;
37 document.documentElement.scrollTop;
30 }
38 }
31− return Value.Tuple(posx, posy);
39+ return Misc.Tuple(posx, posy);
32 }
40 }
33
41
34− Value.addListener(document, 'click', function(e) {
42+ Misc.addListener(document, 'click', function(e) {
35 var hasListener1 = Dispatcher.notify(isClicked.id, true);
43 var hasListener1 = Dispatcher.notify(isClicked.id, true);
36− var hasListener2 = Dispatcher.notify(clicks.id, Value.Tuple());
44+ var hasListener2 = Dispatcher.notify(clicks.id, Misc.Tuple());
37 Dispatcher.notify(isClicked.id, false);
45 Dispatcher.notify(isClicked.id, false);
38 if (!hasListener1 && !hasListener2)
46 if (!hasListener1 && !hasListener2)
39 this.removeEventListener('click',arguments.callee,false);
47 this.removeEventListener('click',arguments.callee,false);
40 });
48 });
41− Value.addListener(document, 'mousedown', function(e) {
49+ Misc.addListener(document, 'mousedown', function(e) {
42 var hasListener = Dispatcher.notify(isDown.id, true);
50 var hasListener = Dispatcher.notify(isDown.id, true);
43 if (!hasListener)
51 if (!hasListener)
44 this.removeEventListener('mousedown',arguments.callee,false);
52 this.removeEventListener('mousedown',arguments.callee,false);
45 });
53 });
46− Value.addListener(document, 'mouseup', function(e) {
54+ Misc.addListener(document, 'mouseup', function(e) {
47 var hasListener = Dispatcher.notify(isDown.id, false);
55 var hasListener = Dispatcher.notify(isDown.id, false);
48 if (!hasListener)
56 if (!hasListener)
49 this.removeEventListener('mouseup',arguments.callee,false);
57 this.removeEventListener('mouseup',arguments.callee,false);
50 });
58 });
51− Value.addListener(document, 'mousemove', function(e) {
59+ Misc.addListener(document, 'mousemove', function(e) {
52 var hasListener = Dispatcher.notify(position.id, getXY(e));
60 var hasListener = Dispatcher.notify(position.id, getXY(e));
53 if (!hasListener)
61 if (!hasListener)
54 this.removeEventListener('mousemove',arguments.callee,false);
62 this.removeEventListener('mousemove',arguments.callee,false);
@@ -57,17 +65,17 @@ function nativeMouse(elm) {
57 var clickedOn = function(elem) {
65 var clickedOn = function(elem) {
58 var node = Render.render(elem);
66 var node = Render.render(elem);
59 var click = Elm.Signal.constant(false);
67 var click = Elm.Signal.constant(false);
60− Value.addListener(node, 'click', function(e) {
68+ Misc.addListener(node, 'click', function(e) {
61 Dispatcher.notify(click.id, true);
69 Dispatcher.notify(click.id, true);
62 Dispatcher.notify(click.id, false);
70 Dispatcher.notify(click.id, false);
63 });
71 });
64− return Value.Tuple(Value.wrap(node), click);
72+ return Misc.Tuple(Misc.wrap(node), click);
65 };
73 };
66− elm.Native.Mouse = {position: position,
74+ Elm.Native.Mouse = {position: position,
67 x:x,
75 x:x,
68 y:y,
76 y:y,
69 isClicked: isClicked,
77 isClicked: isClicked,
70 isDown: isDown,
78 isDown: isDown,
71 clicks: clicks,
79 clicks: clicks,
72 isClickedOn: clickedOn};
80 isClickedOn: clickedOn};
73−}
81+}());
core/Native/Random.js+13−20
@@ -1,29 +1,22 @@
1−/*! Random
2− !*/
3
1
4−Elm.Random = function() {
2+/*
5− /*[In a Range]*/
3+import Signal
4+*/
6
5
7− /** inRange : Int -> Int -> Signal Int
6+(function() {
8− Given a range from low to high, this produces a random number
7+
9− between 'low' and 'high' inclusive. The value in the signal does
10− not change after the page has loaded.
11− **/
12− var inRange = function(min) { return function(max) {
8+ function inRange(min) { return function(max) {
13 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
9 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
14 };
10 };
15− };
11+ }
16
12
17− /** randomize : Int -> Int -> Signal a -> Signal Int
18− Given a range from low to high and a signal of values, this produces
19− a new signal that changes whenever the input signal changes. The new
20− values are random number between 'low' and 'high' inclusive.
21− **/
22− var randomize = function(min) { return function(max) { return function(signal) {
13+ function randomize(min) { return function(max) { return function(signal) {
23 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
14 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
24 return Elm.Signal.lift(f)(signal);
15 return Elm.Signal.lift(f)(signal);
25 };
16 };
26 };
17 };
27− };
18+ }
19+
28− return { inRange:inRange, randomize:randomize };
20+ Elm.Native.Random = { inRange:inRange, randomize:randomize };
21+
29−}();
22+}());
core/Native/Time.js+16−50
@@ -1,35 +1,12 @@
1−/*! Time
1+/*
2−Library for working with time. Type `Time` represents some number of
2+import Signal
3−milliseconds.
3+*/
4−!*/
5
4
6−Elm.Time = function() {
5+(function() {
7−
6+ 'use strict';
8− /*[Times]*/
9−
10− /** hour, minute, second, ms : Time
11− Units of time, making it easier to specify things like a
12− half-second `(second / 2)`.
13− **/
14
7
15 function timeNow() { return (new window.Date).getTime(); }
8 function timeNow() { return (new window.Date).getTime(); }
16
9
17− /*[Tickers]*/
18−
19− /** fps : Number -> Signal Time
20− Takes desired number of frames per second (fps). The resulting signal
21− gives a sequence of time deltas as quickly as possible until it reaches
22− the desired FPS. A time delta is the time between the last frame and the
23− current frame.
24− **/
25−
26− /** fpsWhen : Number -> Signal Bool -> Signal Time
27− Same as the fps function, but you can turn it on and off. Allows you
28− to do brief animations based on user input without major ineffeciencies.
29− The first time delta after a pause is always zero, no matter how long
30− the pause was. This way summing the deltas will actually give the amount
31− of time that the output signal has been running.
32− **/
33 function fpsWhen(desiredFPS) { return function (isOn) {
10 function fpsWhen(desiredFPS) { return function (isOn) {
34 var msPerFrame = 1000 / desiredFPS;
11 var msPerFrame = 1000 / desiredFPS;
35 var prev = timeNow(), curr = prev, diff = 0, wasOn = true;
12 var prev = timeNow(), curr = prev, diff = 0, wasOn = true;
@@ -56,10 +33,6 @@ Elm.Time = function() {
56 };
33 };
57 }
34 }
58
35
59− /** every : Time -> Signal Time
60− Takes a time interval t. The resulting signal is the current time,
61− updated every t.
62− **/
63 function everyWhen(isOn) { return function(t) {
36 function everyWhen(isOn) { return function(t) {
64 var clock = Elm.Signal.constant(timeNow());
37 var clock = Elm.Signal.constant(timeNow());
65 function tellTime() { Dispatcher.notify(clock.id, timeNow()); }
38 function tellTime() { Dispatcher.notify(clock.id, timeNow()); }
@@ -90,23 +63,16 @@ Elm.Time = function() {
90 var t = window.Date.parse(s);
63 var t = window.Date.parse(s);
91 return isNaN(t) ? ["Nothing"] : ["Just",t];
64 return isNaN(t) ? ["Nothing"] : ["Just",t];
92 }
65 }
66+ Elm.Native.Time = {
93− return {fpsWhen : fpsWhen,
67+ fpsWhen : fpsWhen,
94− fps : function(t) { return fpsWhen(t)(Elm.Signal.constant(true)); },
68+ fps : function(t) { return fpsWhen(t)(Elm.Signal.constant(true)); },
95− every : everyWhen(Elm.Signal.constant(true)),
69+ every : everyWhen(Elm.Signal.constant(true)),
96− delay : Elm.Signal.delay,
70+ delay : Elm.Signal.delay,
97− since : since,
71+ since : since,
98− after : after,
72+ after : after,
99− before : before,
73+ before : before,
100− hour : 3600000,
101− minute : 60000,
102− second : 1000,
103− ms : 1,
104− inHours : function(t) { return t / 3600000; },
105− inMinutes : function(t) { return t / 60000; },
106− inSeconds : function(t) { return t / 1000; },
107− inMss : function(t) { return t; },
108− toDate : function(t) { return new window.Date(t); },
74+ toDate : function(t) { return new window.Date(t); },
109− read : read
75+ read : read
110 };
76 };
111
77
112−}();
78+}());
core/Native/Touch.js+9−4
@@ -1,5 +1,10 @@
1+/*
2+import Signal
3+import JavaScript
4+*/
5+
1−function nativeTouch(elm) {
6+(function() {
2− "use strict";
7+ 'use strict';
3
8
4 function Dict() {
9 function Dict() {
5 this.keys = [];
10 this.keys = [];
@@ -90,5 +95,5 @@ function nativeTouch(elm) {
90 return sig2;
95 return sig2;
91 }();
96 }();
92
97
93− elm.Native.Touch = { touches: touches, taps: taps };
98+ Elm.Native.Touch = { touches: touches, taps: taps };
94−}
99+}());
core/Native/WebSocket.js+10−4
@@ -1,6 +1,12 @@
1+/*
2+import Signal
3+import JavaScript
4+import List
5+*/
6+
7+(function() {
8+ 'use strict';
1
9
2−function nativeWebSocket(elm) {
3− "use strict";
4 var JS = Elm.JavaScript;
10 var JS = Elm.JavaScript;
5
11
6 function open(url) { return function(outgoing) {
12 function open(url) { return function(outgoing) {
@@ -29,5 +35,5 @@ function nativeWebSocket(elm) {
29 };
35 };
30 }
36 }
31
37
32− elm.Native.WebSocket = {open:open};
38+ Elm.Native.WebSocket = {open:open};
33−}
39+}());
core/Native/Window.js+15−21
@@ -1,35 +1,29 @@
1−/*! Window !*/
1+/*
2+import Signal
3+import Native.Misc
4+*/
2
5
3−Elm.Window = function() {
6+(function() {
7+ 'use strict';
4
8
5− /*[Dimensions]*/
9+ var Misc = Elm.Native.Misc;
6
10
7− /** dimensions : Signal (Int,Int)
8− The current dimensions of the window (i.e. the area viewable to the
9− user, not including scroll bars).
10− **/
11− var dimensions = Elm.Signal.constant(Value.Tuple(window.innerWidth,
11+ var dimensions = Elm.Signal.constant(Misc.Tuple(window.innerWidth,
12− window.innerHeight));
12+ window.innerHeight));
13 dimensions.defaultNumberOfKids = 2;
13 dimensions.defaultNumberOfKids = 2;
14
14
15− /** width : Signal Int
16− The current width of the window.
17− **/
18− var width = Elm.Signal.lift(function(p){return p[1];})(dimensions);
15+ var width = Elm.Signal.lift(function(p){return p._0;})(dimensions);
19 width.defaultNumberOfKids = 0;
16 width.defaultNumberOfKids = 0;
20
17
21− /** height : Signal Int
22− The current height of the window.
23− **/
24− var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);
18+ var height = Elm.Signal.lift(function(p){return p._1;})(dimensions);
25 height.defaultNumberOfKids = 0;
19 height.defaultNumberOfKids = 0;
26
20
27− Value.addListener(window, 'resize', function(e) {
21+ Misc.addListener(window, 'resize', function(e) {
28 var w = document.getElementById('widthChecker').offsetWidth;
22 var w = document.getElementById('widthChecker').offsetWidth;
29 var hasListener = Dispatcher.notify(dimensions.id,
23 var hasListener = Dispatcher.notify(dimensions.id,
30− Value.Tuple(w, window.innerHeight));
24+ Misc.Tuple(w, window.innerHeight));
31 if (!hasListener)
25 if (!hasListener)
32 this.removeEventListener('resize',arguments.callee,false);
26 this.removeEventListener('resize',arguments.callee,false);
33 });
27 });
34− return {dimensions:dimensions,width:width,height:height};
28+ Elm.Native.Window = {dimensions:dimensions,width:width,height:height};
35−}();
29+}());
core/Random.elmnew file+16
@@ -0,0 +1,16 @@
1+
2+module Random where
3+
4+import Native.Random
5+
6+-- Given a range from low to high, this produces a random number
7+-- between 'low' and 'high' inclusive. The value in the signal does
8+-- not change after the page has loaded.
9+inRange : Int -> Int -> Signal Int
10+inRange = Native.Random.inRange
11+
12+-- Given a range from low to high and a signal of values, this produces
13+-- a new signal that changes whenever the input signal changes. The new
14+-- values are random number between 'low' and 'high' inclusive.
15+randomize : Int -> Int -> Signal a -> Signal Int
16+randomize = Native.Random.randomize
core/Set.elm+2
@@ -6,6 +6,8 @@ module Set (empty,singleton,insert,remove
6 ,toList,fromList
6 ,toList,fromList
7 ) where
7 ) where
8
8
9+import Dict as Dict
10+
9type Set t = Dict t ()
11type Set t = Dict t ()
10
12
11empty : Set t
13empty : Set t
core/Time.elmnew file+52
@@ -0,0 +1,52 @@
1+-- Library for working with time. Type `Time` represents some number of
2+-- milliseconds.
3+
4+module Time where
5+
6+import Native.Time
7+
8+type Time = Float
9+
10+-- Units of time, making it easier to specify things like a
11+-- half-second `(second / 2)`.
12+
13+ms : Time
14+ms = 1
15+
16+second : Time
17+second = 1000 * ms
18+
19+minute : Time
20+minute = 60 * second
21+
22+hour : Time
23+hour = 60 * minute
24+
25+inMss : Time -> Float
26+inMss t = t
27+
28+inSeconds : Time -> Float
29+inSeconds t = t / second
30+
31+inMinutes : Time -> Float
32+inMinutes t = t / minute
33+
34+inHours : Time -> Float
35+inHours t = t / hour
36+
37+-- Takes desired number of frames per second (fps). The resulting signal
38+-- gives a sequence of time deltas as quickly as possible until it reaches
39+-- the desired FPS. A time delta is the time between the last frame and the
40+-- current frame.
41+fps : Number -> Signal Time
42+
43+-- Same as the fps function, but you can turn it on and off. Allows you
44+-- to do brief animations based on user input without major ineffeciencies.
45+-- The first time delta after a pause is always zero, no matter how long
46+-- the pause was. This way summing the deltas will actually give the amount
47+-- of time that the output signal has been running.
48+fpsWhen : Number -> Signal Bool -> Signal Time
49+
50+-- Takes a time interval t. The resulting signal is the current time,
51+-- updated every t.
52+every : Time -> Signal Time
core/Touch.elm+2
@@ -3,6 +3,8 @@
3
3
4module Touch where
4module Touch where
5
5
6+import Native.Touch
7+
6type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
8type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
7
9
8-- A list of touches. Each ongoing touch is represented by a set of
10-- A list of touches. Each ongoing touch is represented by a set of
core/WebSocket.elm+2
@@ -3,6 +3,8 @@
3
3
4module WebSocket where
4module WebSocket where
5
5
6+import Native.WebSocket
7+
6-- Create a web-socket. The first argument is the URL of the desired
8-- Create a web-socket. The first argument is the URL of the desired
7-- web-socket server. The input signal holds the outgoing messages,
9-- web-socket server. The input signal holds the outgoing messages,
8-- and the resulting signal contains the incoming ones.
10-- and the resulting signal contains the incoming ones.
core/Window.elmnew file+17
@@ -0,0 +1,17 @@
1+
2+module Window where
3+
4+import Native.Window
5+
6+-- The current dimensions of the window (i.e. the area viewable to the
7+-- user, not including scroll bars).
8+dimensions : Signal (Int,Int)
9+dimensions = Native.Window.dimensions
10+
11+-- The current width of the window.
12+width : Signal Int
13+width = Native.Window.width
14+
15+-- The current height of the window.
16+height : Signal Int
17+height = Native.Window.height