on master help sign in
Rewrite core-js to remove prefixes and change global Elm prefix from `ElmCode` to `Elm`.
commit7c319fe4c5edb5750d91137aef118a03778fe629 authorevancz <info@elm-lang.org> dateTue 16 Oct 2012, 22:02 (14 years ago) parentcc5d855
12 files changed+99−76
core-js/Graphics/Collage.js+3−3 core-js/Graphics/Render.js+2−2 core-js/Prelude.js+67−46 core-js/Signal/HTTP.js+2−1 core-js/Signal/Input.js+10−9 core-js/Signal/Keyboard.js+4−4 core-js/Signal/Mouse.js+6−6 core-js/Signal/Window.js+1−1 core-js/Text.js+1−1 core-js/Value.js+1−1 core-js/cat.bat+1−1 core-js/runtime/Dispatcher.js+1−1
core-js/Graphics/Collage.js+3−3
@@ -12,13 +12,13 @@ function tracePoints(ctx,points) {
1212
1313function solid(ctx,color,points) {
1414 tracePoints(ctx,points);
15− ctx.strokeStyle = ElmCode.Graphics.Color.extract(color);
15+ ctx.strokeStyle = Elm.Graphics.Color.extract(color);
1616 ctx.stroke();
1717};
1818
1919function filled(ctx,color,points) {
2020 tracePoints(ctx,points);
21− ctx.fillStyle = ElmCode.Graphics.Color.extract(color);
21+ ctx.fillStyle = Elm.Graphics.Color.extract(color);
2222 ctx.fill();
2323}
2424
@@ -35,7 +35,7 @@ function textured(redo,ctx,src,points) {
3535function customLine(pattern,ctx,color,points) {
3636 if (pattern.length === 0) { pattern = [8,4]; }
3737 customLineHelp(ctx, pattern, points);
38− ctx.strokeStyle = ElmCode.Graphics.Color.extract(color);
38+ ctx.strokeStyle = Elm.Graphics.Color.extract(color);
3939 ctx.stroke();
4040};
4141
core-js/Graphics/Render.js+2−2
@@ -177,7 +177,7 @@ function render(elem) {
177177 e.style.height = (~~elem[4]) + 'px';
178178 if (elem[5] !== 1) { e.style.opacity = elem[5]; }
179179 if (elem[6][0] === "Just") {
180− e.style.backgroundColor = ElmCode.Graphics.Color.extract(elem[6][1]);
180+ e.style.backgroundColor = Elm.Graphics.Color.extract(elem[6][1]);
181181 }
182182 if (elem[7][0] === "Just") {
183183 var a = newElement('a');
@@ -263,7 +263,7 @@ function update(node,curr,next) {
263263 if (next[4] !== curr[4]) node.style.height = (~~next[4]) + 'px';
264264 if (next[5] !== curr[5]) node.style.opacity = next[5];
265265 if (next[6].length === 2) {
266− var clr = ElmCode.Graphics.Color.extract(next[6][1]);
266+ var clr = Elm.Graphics.Color.extract(next[6][1]);
267267 if (clr !== node.style.backgroundColor) node.style.backgroundColor = clr;
268268 }
269269 if (next[7].length === 2) {
core-js/Prelude.js+67−46
@@ -1,4 +1,10 @@
11
2+Value.addListener(document, 'elm_log', function(e) { console.log(e.value); });
3+Value.addListener(document, 'elm_title', function(e) {document.title = e.value;});
4+Value.addListener(document, 'elm_redirect', function(e) {
5+ if (e.value.length > 0) { window.location = e.value; }
6+ });
7+
28var Elm = Elm || {};
39Elm.Prelude = function() {
410 var mod = function(x) { return function(y) {
@@ -64,50 +70,65 @@ Elm.Prelude = function() {
6470 curry : curry,
6571 uncurry : uncurry,
6672 logBase : logBase,
67− Just : Maybe.Just,
68− Nothing : Maybe.Nothing,
69− maybe : Maybe.maybe,
70− map : List.map,
71− filter : List.filter,
72− head : List.head,
73− tail : List.tail,
74− last : List.last,
75− length : List.length,
76− reverse : List.reverse,
77− foldr : List.foldr,
78− foldr1 : List.foldr1,
79− foldl : List.foldl,
80− foldl1 : List.foldl1,
81− and : List.and,
82− or : List.or,
83− all : List.all,
84− any : List.any,
85− sum : List.sum,
86− product : List.product,
87− concat : List.concat,
88− concatMap : List.concatMap,
89− maximum : List.maximum,
90− minimum : List.minimum,
91− scanl : List.scanl,
92− scanl1 : List.scanl1,
93− take : List.take,
94− drop : List.drop,
95− zip : List.zip,
96− unzip : List.unzip,
97− lift : Signal.lift,
98− lift2 : Signal.lift2,
99− lift3 : Signal.lift3,
100− lift4 : Signal.lift4,
101− foldp : Signal.foldp,
102− foldp1 : Signal.foldp1,
103− foldp_ : Signal.foldp_,
104− constant : Signal.constant,
105− count : Signal.count,
106− keepIf : Signal.keepIf,
107− dropIf : Signal.dropIf,
108− keepWhen : Signal.keepWhen,
109− dropWhen : Signal.dropWhen,
110− dropRepeats : Signal.dropRepeats,
111− sampleOn : Signal.sampleOn
73+ Just : Elm.Maybe.Just,
74+ Nothing : Elm.Maybe.Nothing,
75+ maybe : Elm.Maybe.maybe,
76+ map : Elm.List.map,
77+ filter : Elm.List.filter,
78+ head : Elm.List.head,
79+ tail : Elm.List.tail,
80+ last : Elm.List.last,
81+ length : Elm.List.length,
82+ reverse : Elm.List.reverse,
83+ foldr : Elm.List.foldr,
84+ foldr1 : Elm.List.foldr1,
85+ foldl : Elm.List.foldl,
86+ foldl1 : Elm.List.foldl1,
87+ and : Elm.List.and,
88+ or : Elm.List.or,
89+ all : Elm.List.all,
90+ any : Elm.List.any,
91+ sum : Elm.List.sum,
92+ product : Elm.List.product,
93+ concat : Elm.List.concat,
94+ concatMap : Elm.List.concatMap,
95+ maximum : Elm.List.maximum,
96+ minimum : Elm.List.minimum,
97+ scanl : Elm.List.scanl,
98+ scanl1 : Elm.List.scanl1,
99+ take : Elm.List.take,
100+ drop : Elm.List.drop,
101+ zip : Elm.List.zip,
102+ unzip : Elm.List.unzip,
103+ lift : Elm.Signal.lift,
104+ lift2 : Elm.Signal.lift2,
105+ lift3 : Elm.Signal.lift3,
106+ lift4 : Elm.Signal.lift4,
107+ foldp : Elm.Signal.foldp,
108+ foldp1 : Elm.Signal.foldp1,
109+ foldp_ : Elm.Signal.foldp_,
110+ constant : Elm.Signal.constant,
111+ count : Elm.Signal.count,
112+ keepIf : Elm.Signal.keepIf,
113+ dropIf : Elm.Signal.dropIf,
114+ keepWhen : Elm.Signal.keepWhen,
115+ dropWhen : Elm.Signal.dropWhen,
116+ dropRepeats : Elm.Signal.dropRepeats,
117+ sampleOn : Elm.Signal.sampleOn
112118 };
113−}();
119+
120+}();
121+
122+(function() {
123+ var include = function(library) {
124+ for (var i in library) {
125+ Elm.Prelude[i] = library[i];
126+ }
127+ };
128+ include (Elm.Graphics.Color);
129+ include (Elm.Graphics.Text);
130+ include (Elm.Graphics.Element);
131+
132+ show = Value.show;
133+
134+}());
core-js/Signal/HTTP.js+2−1
@@ -1,4 +1,5 @@
11Elm.HTTP = function() {
2+ var JS = Elm.JavaScript;
23 var toElmString = Elm.JavaScript.castJSStringToString;
34 function request(verb) { return function(url) { return function(data) {
45 return function(headers) {
@@ -31,7 +32,7 @@ Elm.HTTP = function() {
3132 }
3233 };
3334 request.open(req.verb, req.url, true);
34− List.map(function(pair) {
35+ Elm.List.map(function(pair) {
3536 request.setRequestHeader(
3637 JS.castStringToJSString(pair[1]),
3738 JS.castStringToJSString(pair[2]));
core-js/Signal/Input.js+10−9
@@ -1,15 +1,16 @@
11
22Elm.Input = function() {
3+ var JS = Elm.JavaScript;
34 var toElmString = Elm.JavaScript.castJSStringToString;
45 var newTextInput = function(elem, ghostText) {
56 elem.placeholder = JS.castStringToJSString(ghostText);
67 var str = Elm.Signal.constant(["Nil"]);
7− addListener(elem, 'keyup', function(e) {
8+ Value.addListener(elem, 'keyup', function(e) {
89 Dispatcher.notify(str.id, toElmString(elem.value));
910 elem.focus();
1011 });
1112 elem.style.padding = "1px";
12− return Value.Tuple(wrap(elem), str);
13+ return Value.Tuple(Value.wrap(elem), str);
1314 };
1415 var newElement = function(name) {
1516 var e = document.createElement(name);
@@ -39,10 +40,10 @@ Elm.Input = function() {
3940 box.type = 'checkbox';
4041 box.checked = checked;
4142 var status = Elm.Signal.constant(checked);
42− addListener(box, 'change', function(e) {
43+ Value.addListener(box, 'change', function(e) {
4344 Dispatcher.notify(status.id, box.checked);
4445 });
45− return Value.Tuple(wrap(box), status);
46+ return Value.Tuple(Value.wrap(box), status);
4647 };
4748 var dropDown = function(options) {
4849 var slct = newElement('select');
@@ -57,24 +58,24 @@ Elm.Input = function() {
5758 options = options[2];
5859 }
5960 var status = Elm.Signal.constant(opts[0]);
60− addListener(slct, 'change', function(e) {
61+ Value.addListener(slct, 'change', function(e) {
6162 Dispatcher.notify(status.id, opts[slct.selectedIndex]);
6263 });
63− return Value.Tuple(wrap(slct), status);
64+ return Value.Tuple(Value.wrap(slct), status);
6465 };
6566 var stringDropDown = function(opts) {
66− return dropDown(List.map (function(x) {return Value.Tuple(x,x);}) (opts));
67+ return dropDown(Elm.List.map (function(x) {return Value.Tuple(x,x);}) (opts));
6768 };
6869 var button = function(name) {
6970 var b = newElement('input');
7071 b.type = "button";
7172 b.value = JS.castStringToJSString(name);
7273 var press = Elm.Signal.constant(false);
73− addListener(b, 'click', function(e) {
74+ Value.addListener(b, 'click', function(e) {
7475 Dispatcher.notify(press.id, true);
7576 Dispatcher.notify(press.id, false);
7677 });
77− return Value.Tuple(wrap(b),press);
78+ return Value.Tuple(Value.wrap(b),press);
7879 };
7980 return {textArea:textArea, textField:textField,
8081 password:password, checkbox:checkbox,
core-js/Signal/Keyboard.js+4−4
@@ -14,24 +14,24 @@ Elm.Keyboard = { Raw : function() {
1414 }
1515 return false;
1616 }
17− addListener(document, 'keydown', function(e) {
17+ Value.addListener(document, 'keydown', function(e) {
1818 if (has(e.keyCode, keysDown.value)) return;
1919 var hasListener = Dispatcher.notify(keysDown.id, ["Cons", e.keyCode, keysDown.value]);
2020 if (!hasListener)
2121 this.removeEventListener('keydown',arguments.callee,false);
2222 });
23− addListener(document, 'keyup', function(e) {
23+ Value.addListener(document, 'keyup', function(e) {
2424 var codes = remove(e.keyCode, keysDown.value);
2525 var hasListener = Dispatcher.notify(keysDown.id, codes);
2626 if (!hasListener)
2727 this.removeEventListener('keyup',arguments.callee,false);
2828 });
29− addListener(window, 'blur', function(e) {
29+ Value.addListener(window, 'blur', function(e) {
3030 var hasListener = Dispatcher.notify(keysDown.id, ["Nil"]);
3131 if (!hasListener)
3232 this.removeEventListener('blur',arguments.callee,false);
3333 });
34− addListener(document, 'keypress', function(e) {
34+ Value.addListener(document, 'keypress', function(e) {
3535 var hasListener = Dispatcher.notify(charPressed.id, ["Just",e.charCode || e.keyCode]);
3636 Dispatcher.notify(charPressed.id, ["Nothing"]);
3737 if (!hasListener)
core-js/Signal/Mouse.js+6−6
@@ -28,24 +28,24 @@ Elm.Mouse = function() {
2828 return Value.Tuple(posx, posy);
2929 }
3030
31− addListener(document, 'click', function(e) {
31+ Value.addListener(document, 'click', function(e) {
3232 var hasListener1 = Dispatcher.notify(isClicked.id, true);
3333 var hasListener2 = Dispatcher.notify(clicks.id, Value.Tuple());
3434 Dispatcher.notify(isClicked.id, false);
3535 if (!hasListener1 && !hasListener2)
3636 this.removeEventListener('click',arguments.callee,false);
3737 });
38− addListener(document, 'mousedown', function(e) {
38+ Value.addListener(document, 'mousedown', function(e) {
3939 var hasListener = Dispatcher.notify(isDown.id, true);
4040 if (!hasListener)
4141 this.removeEventListener('mousedown',arguments.callee,false);
4242 });
43− addListener(document, 'mouseup', function(e) {
43+ Value.addListener(document, 'mouseup', function(e) {
4444 var hasListener = Dispatcher.notify(isDown.id, false);
4545 if (!hasListener)
4646 this.removeEventListener('mouseup',arguments.callee,false);
4747 });
48− addListener(document, 'mousemove', function(e) {
48+ Value.addListener(document, 'mousemove', function(e) {
4949 var hasListener = Dispatcher.notify(position.id, getXY(e));
5050 if (!hasListener)
5151 this.removeEventListener('mousemove',arguments.callee,false);
@@ -53,11 +53,11 @@ Elm.Mouse = function() {
5353 var clickedOn = function(elem) {
5454 var node = Render.render(elem);
5555 var click = Elm.Signal.constant(false);
56− addListener(node, 'click', function(e) {
56+ Value.addListener(node, 'click', function(e) {
5757 Dispatcher.notify(click.id, true);
5858 Dispatcher.notify(click.id, false);
5959 });
60− return Value.Tuple(wrap(node), click);
60+ return Value.Tuple(Value.wrap(node), click);
6161 };
6262 return {position: position,
6363 x:x,
core-js/Signal/Window.js+1−1
@@ -8,7 +8,7 @@ Elm.Window = function() {
88 var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);
99 height.defaultNumberOfKids = 0;
1010
11− addListener(window, 'resize', function(e) {
11+ Value.addListener(window, 'resize', function(e) {
1212 var w = document.getElementById('widthChecker').offsetWidth;
1313 var hasListener = Dispatcher.notify(dimensions.id,
1414 Value.Tuple(w, window.innerHeight));
core-js/Text.js+1−1
@@ -23,7 +23,7 @@ var Text = function() {
2323 var italic = addStyle('font-style', 'italic');
2424 var bold = addTag('b');
2525 var color = function(c) {
26− return addStyle('color', ElmCode.Graphics.Color.extract(c));
26+ return addStyle('color', Elm.Graphics.Color.extract(c));
2727 };
2828 var underline = addStyle('text-decoration', 'underline');
2929 var overline = addStyle('text-decoration', 'overline');
core-js/Value.js+1−1
@@ -190,7 +190,7 @@ var Value = function(){
190190 return "(JSON.fromList " + toString(ElmJSON.toList(v)) + ")";
191191 } else if (v[0] === "RBNode" || v[0] === "RBEmpty") {
192192 function cons(k){ return function(v) { return function(acc) { return ["Cons",["Tuple2",k,v],acc]; }; }; }
193− return "(Map.fromList " + toString(ElmCode.Map.fold(cons)(["Nil"])(v)) + ")";
193+ return "(Map.fromList " + toString(Elm.Dict.fold(cons)(["Nil"])(v)) + ")";
194194 } else {
195195 var output = "";
196196 for (var i = v.length; --i; ) {
core-js/cat.bat+1−1
@@ -1,4 +1,4 @@
1−copy /B Guid.js+foreign\JavaScript.js+foreign\JSON.js+Value.js+List.js+Char.js+Maybe.js+String.js+Graphics\Color.js+Graphics\Collage.js+Graphics\Element.js+Text.js+Graphics\Render.js+runtime\Signal.js+runtime\Dispatcher.js+Signal\HTTP.js+Signal\Input.js+Signal\Keyboard.js+Signal\Mouse.js+Signal\Random.js+Signal\Time.js+Signal\Window.js+Prelude.js+Everything.js+Automaton.js ..\elm-mini.js
1+copy /B Guid.js+foreign\JavaScript.js+foreign\JSON.js+Value.js+List.js+Dict.js+Set.js+Char.js+Maybe.js+String.js+Graphics\Color.js+Graphics\Collage.js+Graphics\Element.js+Text.js+Graphics\Render.js+runtime\Signal.js+runtime\Dispatcher.js+Signal\HTTP.js+Signal\Input.js+Signal\Keyboard.js+Signal\Mouse.js+Signal\Random.js+Signal\Time.js+Signal\Window.js+Prelude.js+Automaton.js ..\elm-mini.js
22
33cd ..\elm
44
core-js/runtime/Dispatcher.js+1−1
@@ -6,7 +6,7 @@ var Dispatcher = function() {
66 var currentElement = null;
77
88 var initialize = function() {
9− program = ElmCode.main();
9+ program = Elm.main();
1010 if (!program.hasOwnProperty('recv')) {
1111 program = Elm.Signal.constant(program);
1212 }