Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
db75d2b6
Commit
db75d2b6
authored
Feb 21, 2015
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elm: Sync with @evancz/elm-todomvc/trim
parent
0fe9e8d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
32 deletions
+26
-32
examples/elm/Todo.elm
examples/elm/Todo.elm
+26
-32
No files found.
examples/elm/Todo.elm
View file @
db75d2b6
...
...
@@ -3,9 +3,9 @@ module Todo where
This application is broken up into four distinct parts:
1. Model - a full de
finition of the application's state
2. Update - a way to
step the application state forward
3. View - a way to visualize our
application state
with HTML
1. Model - a full de
scription of the application as data
2. Update - a way to
update the model based on user actions
3. View - a way to visualize our
model
with HTML
4. Inputs - the signals necessary to manage events
This clean division of concerns is a core part of Elm. You can read more about
...
...
@@ -13,10 +13,9 @@ this in the Pong tutorial: http://elm-lang.org/blog/Pong.elm
This program is not particularly large, so definitely see the following
document for notes on structuring more complex GUIs with Elm:
http
s://gist.github.com/evancz/2b2ba366cae1887fe621
http
://elm-lang.org/learn/Architecture.elm
-}
import
Graphics
.
Element
(
Element
,
container
,
midTop
)
import
Html
(
..
)
import
Html
.
Attributes
(
..
)
import
Html
.
Events
(
..
)
...
...
@@ -52,9 +51,9 @@ emptyModel =
-- UPDATE
-- A description of the kinds of actions that can be performed on the
state
of
--
the
application. See the following post for more info on this pattern and
-- some alternatives: http
s://gist.github.com/evancz/2b2ba366cae1887fe621
-- A description of the kinds of actions that can be performed on the
model
of
--
our
application. See the following post for more info on this pattern and
-- some alternatives: http
://elm-lang.org/learn/Architecture.elm
type
Action
=
NoOp
|
UpdateField
String
...
...
@@ -65,54 +64,54 @@ type Action
|
ChangeVisibility
String
-- How we
step the state forward for any given a
ction
-- How we
update our Model on any given A
ction
update
:
Action
->
Model
->
Model
update
action
state
=
update
action
model
=
case
action
of
NoOp
->
state
NoOp
->
model
UpdateField
str
->
{
state
|
field
<-
str
}
{
model
|
field
<-
str
}
Add
->
let
description
=
String
.
trim
state
.
field
in
if
String
.
isEmpty
description
then
state
else
{
state
|
uid
<-
state
.
uid
+
1
,
let
description
=
String
.
trim
model
.
field
in
if
String
.
isEmpty
description
then
model
else
{
model
|
uid
<-
model
.
uid
+
1
,
field
<-
"
"
,
tasks
<-
state
.
tasks
++
[
Task
.
init
description
state
.
uid
]
tasks
<-
model
.
tasks
++
[
Task
.
init
description
model
.
uid
]
}
UpdateTask
(
id
,
taskAction
)
->
let
updateTask
t
=
if
t
.
id
==
id
then
Task
.
update
taskAction
t
else
Just
t
in
{
state
|
tasks
<-
List
.
filterMap
updateTask
state
.
tasks
}
{
model
|
tasks
<-
List
.
filterMap
updateTask
model
.
tasks
}
DeleteComplete
->
{
state
|
tasks
<-
List
.
filter
(
not
<<
.
completed
)
state
.
tasks
}
{
model
|
tasks
<-
List
.
filter
(
not
<<
.
completed
)
model
.
tasks
}
CheckAll
bool
->
let
updateTask
t
=
{
t
|
completed
<-
bool
}
in
{
state
|
tasks
<-
List
.
map
updateTask
state
.
tasks
}
in
{
model
|
tasks
<-
List
.
map
updateTask
model
.
tasks
}
ChangeVisibility
visibility
->
{
state
|
visibility
<-
visibility
}
{
model
|
visibility
<-
visibility
}
-- VIEW
view
:
Model
->
Html
view
state
=
view
model
=
div
[
class
"
todomvc-wrapper"
,
style
[
(
"
visibility"
,
"
hidden"
)
]
]
[
section
[
id
"
todoapp"
]
[
lazy
taskEntry
state
.
field
,
lazy2
taskList
state
.
visibility
state
.
tasks
,
lazy2
controls
state
.
visibility
state
.
tasks
[
lazy
taskEntry
model
.
field
,
lazy2
taskList
model
.
visibility
model
.
tasks
,
lazy2
controls
model
.
visibility
model
.
tasks
]
,
infoFooter
]
...
...
@@ -221,14 +220,9 @@ infoFooter =
-- SIGNALS
-- wire the entire application together
main
:
Signal
Element
main
:
Signal
Html
main
=
Signal
.
map2
scene
model
Window
.
dimensions
scene
:
Model
->
(
Int
,
Int
)
->
Element
scene
model
(
w
,
h
)
=
container
w
h
midTop
(
toElement
550
h
(
view
model
))
Signal
.
map
view
model
-- manage the model of our application over time
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment