forked from evancz/elm-todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Guerra
committed
Jul 18, 2017
1 parent
ae52a44
commit d2a3e13
Showing
12 changed files
with
3,771 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
elm-stuff | ||
elm.js | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "TodoApp", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "webpack", | ||
"client": "webpack-dev-server --port 3000" | ||
}, | ||
"dependencies": { | ||
"css-loader": "^0.28.4", | ||
"elm-webpack-loader": "^4.3.1", | ||
"file-loader": "^0.11.2", | ||
"style-loader": "^0.18.2", | ||
"url-loader": "^0.5.9", | ||
"webpack": "^3.3.0", | ||
"webpack-dev-server": "^2.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
module Model exposing (..) | ||
|
||
import Json.Decode as Json | ||
import Json.Encode as Encode | ||
|
||
|
||
type Visibility | ||
= ShowAll | ||
| ShowCompleted | ||
| ShowActive | ||
|
||
|
||
|
||
-- The full application state of our todo app. | ||
|
||
|
||
type alias Model = | ||
{ entries : List Entry | ||
, field : String | ||
, uid : Int | ||
, visibility : Visibility | ||
} | ||
|
||
|
||
type alias Entry = | ||
{ description : String | ||
, completed : Bool | ||
, editing : Bool | ||
, id : Int | ||
} | ||
|
||
|
||
|
||
-- Decoders | ||
|
||
|
||
modelDecoder : Json.Decoder Model | ||
modelDecoder = | ||
Json.map4 Model | ||
(Json.at [ "entries" ] (Json.list entryDecoder)) | ||
(Json.at [ "field" ] Json.string) | ||
(Json.at [ "uid" ] Json.int) | ||
(Json.at [ "visibility" ] Json.string |> Json.andThen visibilityDecoder) | ||
|
||
|
||
entryDecoder : Json.Decoder Entry | ||
entryDecoder = | ||
Json.map4 Entry | ||
(Json.at [ "description" ] Json.string) | ||
(Json.at [ "completed" ] Json.bool) | ||
(Json.at [ "editing" ] Json.bool) | ||
(Json.at [ "id" ] Json.int) | ||
|
||
|
||
visibilityDecoder : String -> Json.Decoder Visibility | ||
visibilityDecoder tag = | ||
case tag of | ||
"ShowActive" -> | ||
Json.succeed ShowActive | ||
|
||
"ShowAll" -> | ||
Json.succeed ShowAll | ||
|
||
"ShowCompleted" -> | ||
Json.succeed ShowCompleted | ||
|
||
_ -> | ||
Json.fail (tag ++ " is not a recognized tag for Visibility") | ||
|
||
|
||
|
||
-- Encoders | ||
|
||
|
||
modelToValue : Model -> Encode.Value | ||
modelToValue model = | ||
Encode.object | ||
[ ( "entries", Encode.list (List.map entryToValue model.entries) ) | ||
, ( "field", Encode.string model.field ) | ||
, ( "uid", Encode.int model.uid ) | ||
, ( "visibility", visibilityToValue model.visibility ) | ||
] | ||
|
||
|
||
entryToValue : Entry -> Encode.Value | ||
entryToValue entry = | ||
Encode.object | ||
[ ( "description", Encode.string entry.description ) | ||
, ( "completed", Encode.bool entry.completed ) | ||
, ( "editing", Encode.bool entry.editing ) | ||
, ( "id", Encode.int entry.id ) | ||
] | ||
|
||
|
||
visibilityToValue : Visibility -> Encode.Value | ||
visibilityToValue visibility = | ||
case visibility of | ||
ShowActive -> | ||
Encode.string "ShowActive" | ||
|
||
ShowAll -> | ||
Encode.string "ShowAll" | ||
|
||
ShowCompleted -> | ||
Encode.string "ShowCompleted" | ||
|
||
|
||
emptyModel : Model | ||
emptyModel = | ||
{ entries = [] | ||
, visibility = ShowAll | ||
, field = "" | ||
, uid = 0 | ||
} | ||
|
||
|
||
newEntry : String -> Int -> Entry | ||
newEntry desc id = | ||
{ description = desc | ||
, completed = False | ||
, editing = False | ||
, id = id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Elm • TodoMVC</title> | ||
</head> | ||
|
||
<body> | ||
<div id="main"></div> | ||
<script src="/app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
require('./style.css'); | ||
// Require index.html so it gets copied to dist | ||
require('./index.html'); | ||
|
||
var Elm = require('./Main.elm'); | ||
var mountNode = document.getElementById('main'); | ||
|
||
var storedState = localStorage.getItem('elm-todo-save'); | ||
var startingState = storedState ? JSON.parse(storedState) : null; | ||
var todomvc = Elm.TodoApp.embed(mountNode, startingState); | ||
todomvc.ports.setStorage.subscribe(function(state) { | ||
localStorage.setItem('elm-todo-save', JSON.stringify(state)); | ||
}); |
File renamed without changes.
Oops, something went wrong.