From 8db9ccf57e2515f70f2a998b99a83ea533daf3fe Mon Sep 17 00:00:00 2001 From: Colin Curtin Date: Sat, 11 May 2013 13:35:20 -0700 Subject: [PATCH] Fix HTTP/JSON * Elm Http: Signal (lift) was not imported * Native Http: "Waiting" was not a string. * Elm Json: find* weren't using the Json Object type (which find was expecting) * Native Json: Utils was not imported (to use Tuple2) --- libraries/Http.elm | 1 + libraries/Json.elm | 10 +++++----- libraries/Native/Json.js | 3 ++- libraries/Native/Signal/Http.js | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/Http.elm b/libraries/Http.elm index 031e834..57094af 100644 --- a/libraries/Http.elm +++ b/libraries/Http.elm @@ -5,6 +5,7 @@ module Http where import Native.Http (send) +import Signal (lift) -- The datatype for responses. Success contains only the returned message. -- Failures contain both an error code and an error message. diff --git a/libraries/Json.elm b/libraries/Json.elm index 294bf5c..4a16d00 100644 --- a/libraries/Json.elm +++ b/libraries/Json.elm @@ -78,25 +78,25 @@ find get base = -- Find a string value in an Elm Json object. If the key is not found or the -- value found is not a string, this returns the empty string. -findString : String -> Dict String Value -> String +findString : String -> Object -> String findString = find string "" -- Find a number value in an Elm Json object. If the key is not found or the -- value found is not a number, this returns 0 -findNumber : String -> Dict String Value -> Float +findNumber : String -> Object -> Float findNumber = find number 0 -- Find a boolean value in an Elm Json object. If the key is not found or the -- value found is not a boolean, this returns the False. -findBoolean : String -> Dict String Value -> Bool +findBoolean : String -> Object -> Bool findBoolean = find boolean False -- Find an array value in an Elm Json object. If the key is not found or the -- value found is not an array, this returns an empty list. -findArray : String -> Dict String Value -> [Value] +findArray : String -> Object -> [Value] findArray = find array [] -- Find an object value in an Elm Json object. If the key is not found or the -- value found is not an object, this returns an empty object. -findObject : String -> Dict String Value -> Dict String Value +findObject : String -> Object -> Object findObject = find object Dict.empty diff --git a/libraries/Native/Json.js b/libraries/Native/Json.js index 96b8dbd..bfa512b 100644 --- a/libraries/Native/Json.js +++ b/libraries/Native/Json.js @@ -6,6 +6,7 @@ Elm.Native.Json = function(elm) { var Dict = Elm.Dict(elm); var List = Elm.List(elm); var JS = Elm.JavaScript(elm); + var Utils = Elm.Native.Utils(elm); function fromValue(v) { switch (v.ctor) { @@ -45,7 +46,7 @@ Elm.Native.Json = function(elm) { return { ctor:"Array", _0: JS.toList(v) }; } var array = []; - for (var k in v) array.push(Tuple2(JS.toString(k), toValue(v[k]))); + for (var k in v) array.push(Utils.Tuple2(JS.toString(k), toValue(v[k]))); return { ctor:"Object", _0: Dict.fromList(JS.toList(array)) }; } } diff --git a/libraries/Native/Signal/Http.js b/libraries/Native/Signal/Http.js index a9b81f8..b482fb3 100644 --- a/libraries/Native/Signal/Http.js +++ b/libraries/Native/Signal/Http.js @@ -18,9 +18,9 @@ Elm.Native.Http = function(elm) { function updateQueue(queue,responses) { if (queue.length > 0) { elm.notify(responses.id, queue[0].value); - if (queue[0].value.ctor !== Waiting) { - queue.shift(); - setTimeout(function() { updateQueue(queue,responses); }, 0); + if (queue[0].value.ctor !== 'Waiting') { + queue.shift(); + setTimeout(function() { updateQueue(queue,responses); }, 0); } } }