Skip to content

Commit ff4d297

Browse files
committed
adds section for creating the view for Elm(ish) Todo List App #44 / #48
1 parent e29da0e commit ff4d297

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

Diff for: todo-list.md

+50-5
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ All we need is an `Object` containing two keys `todos` and `hash`:
188188
{ id: 2, title: "Build Todo List App", done: false },
189189
{ id: 3, title: "Win the Internet!", done, false }
190190
],
191-
hash: '#/active' // the "route" to display
191+
hash: '#/' // the "route" to display
192192
}
193193
```
194194
`todos` is an `Array` of `Objects` and each Todo (Array) item
@@ -206,10 +206,10 @@ https://en.wikipedia.org/wiki/Metadata
206206

207207
There are two types of `metadata` in a Todo List App:
208208
+ `id` - each todo item has an `id`, this is the item's position in the list.
209-
+ count - the count of items according to their state of _completion_.
210-
e.g: in the model above there are
211-
2 items which are "active"
212-
and 1 which is "done".
209+
+ `count` - the count of items according to their state of _completion_.
210+
e.g: in the model above there are 3 todo items in the `todos` Array;
211+
2 items which are "active" (`done=false`)
212+
and 1 which is "done" (`done=true`).
213213

214214
Rather than _storing_ "metadata" in the model
215215
(_e.g: the count of active and completed Todo items_)
@@ -666,6 +666,51 @@ of the `TOGGLE case` in `upadate` until _all_ tests pass:
666666

667667
![undo-a-todo-item](https://user-images.githubusercontent.com/194400/43686533-b25d4608-98bf-11e8-809e-1153fcfb1db1.png)
668668

669+
### `view` Function
670+
671+
It won't have "_escaped_" you that _so far_ we have not written _any_ code
672+
that a _user_ can actually _interact_ with.
673+
674+
_So far_ we have _successfully_ added two `case` blocks in the `switch` statement
675+
of our `update` function. We now have the two _basic_ functions required
676+
to both `ADD` a new todo list item to the `model.todos` Array
677+
_and_ check-off a todo list item as "done" using the `TOGGLE action`.
678+
This is "_enough_" functionality to start _using_ the todo list (_ourselves_)
679+
and **UX-testing** it with _prospective_ "***users***".
680+
681+
If you followed through the "Elm(ish)" tutorial
682+
[`elmish.md`](https://github.com/dwyl/learn-elm-architecture-in-javascript/blob/master/elmish.md)
683+
you will have seen that we created a _sample_ `view` in the last few _tests_
684+
to "_exercise_" the DOM element creation functions.
685+
This means that we _already know_ how to build a `view` for our Todo List App!
686+
We "_just_" need to _adapt_ the `view` we made in `Elm`(_ish_) to display
687+
the data in our `model`.
688+
689+
#### Sample `model` to Render in Our `view`
690+
691+
Let's return to the sample `model` from above:
692+
693+
```js
694+
{
695+
todos: [
696+
{ id: 1, title: "Learn Elm Architecture", done: true },
697+
{ id: 2, title: "Build Todo List App", done: false },
698+
{ id: 3, title: "Win the Internet!", done, false }
699+
],
700+
hash: '#/' // the "route" to display
701+
}
702+
```
703+
The model contains _three_ items in the `todos` Array. <br />
704+
The first is complete (`done=true`)
705+
whereas the second and third items are still "todo" (`done=false`).
706+
707+
This is what this `model` looks like in the "VanillaJS"
708+
TodoMVC:
709+
echo ![todomvc-3-items-1-done](https://user-images.githubusercontent.com/194400/43689907-e9caa548-98f8-11e8-8fd1-7b63e7fc5e30.png)
710+
711+
Our quest in the next "pomodoro" is to re-create this
712+
using the DOM functions we created in `Elm`(_ish_)!
713+
669714

670715
<!--
671716

0 commit comments

Comments
 (0)