evancz / elm-todomvc

The TodoMVC app written in Elm, nice example for beginners.
http://evancz.github.io/elm-todomvc/
BSD 3-Clause "New" or "Revised" License
1.21k stars 329 forks source link

Remaining TodoMVC test failures #11

Closed passy closed 9 years ago

passy commented 9 years ago

screenshot from 2014-12-14 20 12 56

I think the first confusingly titled "should allow me to add todo items" failure refers to the localStorage persistence.

Saving on blur is implemented slightly differently. You're currently reverting the edit on blur and escape is ignored. I tried to change it like this, but I must be missing something because the behavior is not what I expected. I think because escape also blurs the entry, it's not as easy as I thought:

diff --git a/Task.elm b/Task.elm
index 5e65045..6a0bcab 100644
--- a/Task.elm
+++ b/Task.elm
@@ -113,18 +113,25 @@ view channel task =
           , name "title"
           , id ("todo-" ++ toString task.id)
           , on "input" targetValue (\desc -> LC.send channel (task.id, Edit desc))
-          , onBlur (LC.send channel (task.id, Cancel))
+          , onEscape (LC.send channel (task.id, Cancel))
+          , onBlur (LC.send channel (task.id, Commit))
           , onEnter (LC.send channel (task.id, Commit))
           ]
           []
       ]

+onEscape : Signal.Message -> Attribute
+onEscape message =
+    on "keydown"
+      (Json.customDecoder keyCode (isKey 27))
+      (always message)
+
 onEnter : Signal.Message -> Attribute
 onEnter message =
     on "keydown"
-      (Json.customDecoder keyCode is13)
+      (Json.customDecoder keyCode (isKey 13))
       (always message)

-is13 : Int -> Result String ()
-is13 code =
-  if code == 13 then Ok () else Err "not the right key code"
+isKey : Int -> Int -> Result String ()
+isKey code input =
+  if input == code then Ok () else Err "not the right key code"

The "back button" means that the routing should be observed and using back/forwards should change the All/Active/Completed filter in the app.

luigy commented 9 years ago

It was fun to try to fix these tests to finally play with and get a feeling for Elm https://github.com/luigy/elm-todomvc/commit/c85fcf42a4421d4e69869bb556ff27abe9cf80dd

passy commented 9 years ago

@luigy That's looking great! :)

@evancz Any chance this could get pulled in?

evancz commented 9 years ago

@luigy, is it okay for me to merge these into my branch? My stuff is all BSD3 and I try to be very careful about this.

So the last remaining thing is local storage? I vaguely recall that not being needed, but I guess I was confused. Once we hear back from @luigy, I'll bring that over from the master branch. At that point, it'll probably be all set.

luigy commented 9 years ago

@evancz it needs to be cleaned up, though:

Since, "TodoMVC" is usually used as an example to follow I wasn't sure how to go about code style or naming in Elm so I was hoping someone familiar with it to critique :smile:

If you would like to tell me how to proceed I can submit a PR or feel free to merge with the proper changes :)

passy commented 9 years ago

@evancz Yup, localStorage is still needed. We have an experimental (and thus optional) API, but localStorage is mandatory in terms of the spec at this point.

evancz commented 9 years ago

Okay, I think all of the things mentioned here should be covered now. @luigy, I just left the URL parsing stuff in JS for now, though I could imagine a pattern match that only does stuff on valid strings.

passy commented 9 years ago

29 passing (1m)

Fantastic! \o/

There are some stylistic changed we have to make to match the TodoMVC repo. It's up to you whether we want to do this in this repo or whenever we're syncing the versions. It's only about white spaces and tabs. What do you think?

evancz commented 9 years ago

What are the rules of that change? Tabs are not permitted in Elm, and though it's possible to do things "all 4 space indent" it would not look very typical.

passy commented 9 years ago

Tabs are not permitted in Elm

Okay, that makes things easier. :) Other than that the only thing we enforce through JSCS/JSHint is a space after function, ie. function () { …. Otherwise it should be perfectly compatible.

evancz commented 9 years ago

Do you mean in the snippet of JS in index.html? I'm happy to make those changes on this repo.

passy commented 9 years ago

@evancz Yup, that's what I mean. Would you like to submit the PR afterwards?

evancz commented 9 years ago

I'm not sure exactly what is needed right now. Would you mind doing a PR for the JS changes? I'm not sure if function foo () also needs a space, and I think it's probably easier to just do it than explain to me exactly what needs to happen.

I'm not sure what the protocol is for doing PRs to the todomvc repo, so if I can just get cc'd on it, that'd be ideal.

Is that okay?

passy commented 9 years ago

@evancz Sounds good. I think I still have a pending one, I can just update that one and cc you on it. :)

passy commented 9 years ago

The discussion is now in https://github.com/tastejs/todomvc/pull/1041