Code Monkey home page Code Monkey logo

elm-todomvc's Introduction

TodoMVC in Elm - Try It!

All of the Elm code lives in src/Main.elm and relies on the elm/html library.

There also is a port handler set up in index.html to store the Elm application's state in localStorage on every update.

Build Instructions

Run the following command from the root of this project:

elm make src/Main.elm --output=elm.js

Then open index.html in your browser!

elm-todomvc's People

Contributors

evancz avatar fredcy avatar hrldcpr avatar ivanvotti avatar janiczek avatar kmoe avatar pdamoc avatar process-bot avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elm-todomvc's Issues

Issue when we try running using elm reactor on Main.elm

How to reproduce

It works fine if you click on index.html but if you want to make see the elm debugger in action, then it is a little problematic:

  1. Clone the repo.

  2. Run elm reactor

  3. Click on Main.elm.

The following error comes up:

Initialization Error

Error: Problem with the flags given to your Elm program on initialization.

Json.Decode.oneOf failed in the following 2 ways:

(1) Problem with the given value:
    
    undefined
    
    Expecting null



(2) Problem with the given value:
    
    undefined
    
    Expecting an OBJECT with a field named `visibility`

error initializing TODO module with null state

the first time i run these app savedModel is null because localStorage is empty yet so the init function gets an error because it is expecting a Model instead. this is rather strange since the type argument of init signature is Maybe Model

Add tags corresponding to elm-html versions

As this is the example pointed to by the elm-html docs, it would be useful to find earlier versions.

Use case: As a developer working on a production app that still uses elm-html 2.0.0, I want to find the corresponding version of elm-todomvc from the github tags menu.

No longer compiles (main expects Signal Element)

Cloning this and running elm-make Todo.elm installs 1.1.0 of core, elm-html, and virtual-dom, but I still get:

Error in Todo.elm:

Type Error: 'main' must have type Element or (Signal Element).

Instead 'main' has type:
    Signal.Signal Html.Html

Could it be that all the examples have been switched to "main gets Html", but 1.1.0 still expects Element?

elm-react gives me an error

Oops! Something went wrong when starting your Elm program.

Trying to initialize the Todo module with an unexpected flag.
I tried to convert it to an Elm value, but ran into this problem:

I ran into the following problems:

Expecting null but instead got: undefined
Expecting an object with a field named entries but instead got: undefined

syntax doubt about view

i'm new to elm and have a question concerning view arguments: in main, view is called with a Signal Model as second argument but the type annotation of view refers the argument as being Model.

i have this same issue in another app i'm working to practice elm in which the compiler report this error but it seems to be working here, how can this be?

Function `view` is expecting the 2nd argument to be:

    { tasks : List Task }

But it is:

    Signal Model

Class "header" usage?

Hey, Love this example so far! Learning a ton.

Quick question: I noticed that there is a class "header" on the header for the main input. Wondering what this is being used for?

Still loving Elm!!!!

Split into multiple files

I could not find a lot of information about splitting elm code into multiple files. And it was a lot trial and error to get this to work. Especially regarding splitting the update/msg stuff into multiple files and keeping the types correctly.
It would be nice to have an example app like this which is split into multiple files/smaller components.
Would you rather create small files with update and view functions. Or split them like in the redux architecture: Have one folder for all the actions/updates and one for views...

Tracking the entry that is being edited should live on the Model and not Entry

It looks like all the base are covered, but it is theoretically possible for two entries to be marked as editing = True.

Having something like editingEntryId : Maybe String would eliminate that possibility, and be more explicit. It does mean passing around more information into the entry views, though. I also don't know if this is technically any more correct.

Why visibility is a string and not a union type?

I'm new to Elm and reading code to understand language and patterns.
For me it seems like making visibility a union type would be better for understanding the code and type safety. Isn't it?

type Visibility
  = Active
  | Completed
  | All

Cannot run Todo from elm-reactor or serving from local server

Console is revealing the following error upon launching from elm-reactor:

"Todo.elm:3025 Uncaught Error: You are trying to initialize module `Todo` with an unexpected argument.
When trying to convert it to a usable Elm value, I run into this problem:

I ran into the following problems:

Expecting null but instead got: undefined
Expecting an object with a field named `entries` but instead got: undefined"

Same from localhost (mamp) serving index.html.

Fails to start with reactor

The app gives me the following error if I want to run it under reactor:

Initialization Error: port 'getStorage' was not given an input!
Open the developer console for more details.

Remaining TodoMVC test failures

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.

Split Todo.elm into submodules

It would make sense to extract some submodules from Todo.elm, e.g. Model, View, Messages, Update.

A big file is difficult to understand in a single read, whereas having submodules exposes the underlying structure. More importantly, I feel like there's no strong convention for containing different parts of a typical Elm application. Maintaining a single file is increasingly difficult, and suggesting a standard set of submodules would be beneficial for the community.

I'll be happy to work on a PR if this idea gets accepted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.