on master help sign in
Merge branch 'master' into dev
commit9943120f1bc6aa4f8acf655a1660e4bae740042b authorEvan Czaplicki <info@elm-lang.org> dateTue 25 Mar 2014, 14:32 (13 years ago) parent35e07efe9dfea7
9 files changed+84−55
Elm.cabal+1−1 libraries/Char.elm+2−2 libraries/Debug.elm+2 libraries/Http.elm+2−4 libraries/Keyboard.elm+2−4 libraries/Signal.elm+1−1 libraries/String.elm+6−6 runtime/Render/Element.js+57−29 server/Server.hs+11−8
Elm.cabal+1−1
@@ -20,7 +20,7 @@ Category: Compiler, Language
2020
2121Build-type: Custom
2222
23−Extra-source-files: changelog.txt
23+Extra-source-files: changelog.md
2424Data-dir: data
2525Data-files: elm-runtime.js interfaces.data docs.json
2626Cabal-version: >=1.9
libraries/Char.elm+2−2
@@ -52,8 +52,8 @@ toLocaleLower = Native.Char.toLocaleLower
5252
5353type KeyCode = Int
5454
55−{-| Convert to unicode. Used with the [`Keyboard`](/docs/Keyboard.elm)
56−library, which expects the input to be uppercase. -}
55+{-| Convert to unicode. Used with the `Keyboard` library, which expects the
56+input to be uppercase. -}
5757toCode : Char -> KeyCode
5858toCode = Native.Char.toCode
5959
libraries/Debug.elm+2
@@ -1,6 +1,8 @@
11module Debug where
22{-| This library is for investigating bugs or performance problems. It should
33*not* be used in production code.
4+
5+@docs log
46-}
57
68import Native.Debug
libraries/Http.elm+2−4
@@ -1,8 +1,6 @@
11module Http where
2−
3−{-| A library for asynchronous HTTP requests. See the
4−[WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
5−you have very strict latency requirements.
2+{-| A library for asynchronous HTTP requests. See the `WebSocket`
3+library if you have very strict latency requirements.
64
75# Sending Requests
86@docs send, sendGet
libraries/Keyboard.elm+2−4
@@ -1,5 +1,4 @@
11module Keyboard where
2−
32{-| Library for working with keyboard input.
43
54# Representing Keys
@@ -20,9 +19,8 @@ import Signal (Signal)
2019import Native.Keyboard
2120
2221{-| Type alias to make it clearer what integers are supposed to represent
23−in this library. Use [`Char.toCode`](docs/Char.elm#toCode) and
24−[`Char.fromCode`](/docs/Char.elm#fromCode) to convert key codes to characters.
25−Use the uppercase character with `toCode`.
22+in this library. Use `Char.toCode` and `Char.fromCode` to convert key codes
23+to characters. Use the uppercase character with `toCode`.
2624-}
2725type KeyCode = Int
2826
libraries/Signal.elm+1−1
@@ -10,7 +10,7 @@ past-dependence.
1010
1111Some useful functions for working with time (e.g. setting FPS) and combining
1212signals and time (e.g. delaying updates, getting timestamps) can be found in
13−the [`Time`](/docs/Signal/Time.elm) library.
13+the `Time` library.
1414
1515# Combine
1616@docs constant, lift, lift2, merge, merges, combine
libraries/String.elm+6−6
@@ -174,18 +174,18 @@ pad = Native.String.pad
174174
175175{-| Pad a string on the left until it has a given length.
176176
177− pad 5 '.' "1" == "....1"
178− pad 5 '.' "11" == "...11"
179− pad 5 '.' "121" == "..121"
177+ padLeft 5 '.' "1" == "....1"
178+ padLeft 5 '.' "11" == "...11"
179+ padLeft 5 '.' "121" == "..121"
180180-}
181181padLeft : Int -> Char -> String -> String
182182padLeft = Native.String.padLeft
183183
184184{-| Pad a string on the right until it has a given length.
185185
186− pad 5 '.' "1" == "1...."
187− pad 5 '.' "11" == "11..."
188− pad 5 '.' "121" == "121.."
186+ padRight 5 '.' "1" == "1...."
187+ padRight 5 '.' "11" == "11..."
188+ padRight 5 '.' "121" == "121.."
189189-}
190190padRight : Int -> Char -> String -> String
191191padRight = Native.String.padRight
runtime/Render/Element.js+57−29
@@ -34,35 +34,59 @@ function setProps(elem, e) {
3434 e.appendChild(a);
3535 }
3636 if (props.hover.ctor !== '_Tuple0') {
37− e.style.pointerEvents = 'auto';
38− e.elm_hover_handler = props.hover;
39− e.elm_hover_count = 0;
40− e.addEventListener('mouseover', function() {
41− if (e.elm_hover_count++ > 0) return;
42− var handler = e.elm_hover_handler;
43− if (handler !== null) {
44− handler(true);
45− }
46− });
47− e.addEventListener('mouseout', function(evt) {
48− if (e.contains(evt.toElement || evt.relatedTarget)) return;
49− e.elm_hover_count = 0;
50− var handler = e.elm_hover_handler;
51− if (handler !== null) {
52− handler(false);
53− }
54− });
37+ addHover(e, props.hover);
5538 }
5639 if (props.click.ctor !== '_Tuple0') {
57− e.style.pointerEvents = 'auto';
58− e.elm_click_handler = props.click;
59− e.addEventListener('click', function() {
60− e.elm_click_handler(Tuple0);
61− });
40+ addClick(e, props.click);
6241 }
6342 return e;
6443}
6544
45+function addClick(e, handler) {
46+ e.style.pointerEvents = 'auto';
47+ e.elm_click_handler = handler;
48+ function trigger() {
49+ e.elm_click_handler(Utils.Tuple0);
50+ }
51+ e.elm_click_trigger = trigger;
52+ e.addEventListener('click', trigger);
53+}
54+
55+function removeClick(e, handler) {
56+ if (e.elm_click_trigger) {
57+ e.removeEventListener('click', e.elm_click_trigger);
58+ }
59+}
60+
61+function addHover(e, handler) {
62+ e.style.pointerEvents = 'auto';
63+ e.elm_hover_handler = handler;
64+ e.elm_hover_count = 0;
65+
66+ function over() {
67+ if (e.elm_hover_count++ > 0) return;
68+ e.elm_hover_handler(true);
69+ }
70+ function out(evt) {
71+ if (e.contains(evt.toElement || evt.relatedTarget)) return;
72+ e.elm_hover_count = 0;
73+ e.elm_hover_handler(false);
74+ }
75+ e.elm_hover_over = over;
76+ e.elm_hover_out = out;
77+ e.addEventListener('mouseover', over);
78+ e.addEventListener('mouseout', out);
79+}
80+
81+function removeHover(e) {
82+ if (e.elm_hover_over) {
83+ e.removeEventListener('mouseover', e.elm_hover_over);
84+ }
85+ if (e.elm_hover_out) {
86+ e.removeEventListener('mouseout', e.elm_hover_out);
87+ }
88+}
89+
6690function image(props, img) {
6791 switch (img._0.ctor) {
6892 case 'Plain': return plainImage(img._3);
@@ -358,17 +382,21 @@ function updateProps(node, curr, next) {
358382 }
359383
360384 // update hover handlers
361− if (props.hover.ctor !== '_Tuple0') {
362− e.elm_hover_handler = props.hover;
385+ if (props.hover.ctor === '_Tuple0') {
386+ removeHover(e);
363387 } else if (e.elm_hover_handler) {
364− e.elm_hover_handler = null;
388+ e.elm_hover_handler = props.hover;
389+ } else {
390+ addHover(e, props.hover);
365391 }
366392
367393 // update click handlers
368− if (props.click.ctor !== '_Tuple0') {
369− e.elm_click_handler = props.click;
394+ if (props.click.ctor === '_Tuple0') {
395+ removeClick(e);
370396 } else if (e.elm_click_handler) {
371− e.elm_click_handler = null;
397+ e.elm_click_handler = props.click;
398+ } else {
399+ addClick(e, props.click);
372400 }
373401}
374402
server/Server.hs+11−8
@@ -24,11 +24,14 @@ import Snap.Util.FileServe
2424
2525data Flags = Flags
2626 { port :: Int
27+ , runtime :: Maybe FilePath
2728 } deriving (Data,Typeable,Show,Eq)
2829
2930flags :: Flags
3031flags = Flags
3132 { port = 8000 &= help "set the port of the server"
33+ , runtime = Nothing &= typFile
34+ &= help "Specify a custom location for Elm's runtime system."
3235 } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
3336 \It serves static files and freshly recompiled Elm files."
3437 &= helpArg [explicit, name "help", name "h"]
@@ -49,7 +52,7 @@ main = do
4952 putStrLn $ "Elm Server " ++ Version.showVersion version ++
5053 ": Just refresh a page to recompile it!"
5154 httpServe (setPort (port cargs) config) $
52− serveRuntime
55+ serveRuntime (maybe Elm.runtime id (runtime cargs))
5356 <|> serveElm
5457 <|> serveDirectoryWith directoryConfig "."
5558
@@ -74,14 +77,14 @@ indexStyle =
7477 \th { background:rgb(90,99,120); color:white; text-align:left;\
7578 \ padding:10px; font-weight:normal; }"
7679
77−runtime :: String
78−runtime = "elm-runtime.js"
80+runtimeName :: String
81+runtimeName = "elm-runtime.js"
7982
80−serveRuntime :: Snap ()
81−serveRuntime =
83+serveRuntime :: FilePath -> Snap ()
84+serveRuntime runtimePath =
8285 do file <- BSC.unpack . rqPathInfo <$> getRequest
83− guard (file == runtime)
84− serveFileAs "application/javascript" Elm.runtime
86+ guard (file == runtimeName)
87+ serveFileAs "application/javascript" runtimePath
8588
8689serveElm :: Snap ()
8790serveElm =
@@ -91,7 +94,7 @@ serveElm =
9194 onSuccess (compile file) (serve file)
9295 where
9396 compile file =
94− let elmArgs = [ "--make", "--runtime=" ++ runtime, file ]
97+ let elmArgs = [ "--make", "--runtime=" ++ runtimeName, file ]
9598 in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
9699
97100 serve file =