1
- # Elm(ish) Todo List (TodoMVC) Mini App (TDD Tutorial!)
1
+ # Elm(ish) Todo List (TodoMVC) Mini App (Real World TDD Tutorial!)
2
2
3
3
If you've made it this far, give yourself a pat on the back!
4
- You are about to "_ level up_ " your JavaScript and "TEA" skills!
4
+ Your persistence is about to pay off as you
5
+ "_ level up_ " _ both_ your ** ` JavaScript ` ** and "TEA" skills!
5
6
6
7
7
8
## Why?
8
9
9
- _ Consolidate_ your understanding of The Elm Architecture (TEA)
10
- by creating a "real world" _ useable_ App.
10
+ The _ purpose_ of this ** Todo List _ mini_ project** is to
11
+ _ consolidate_ your understanding of The Elm Architecture (TEA)
12
+ by creating a "real world" _ useable_ App following a _ strict_
13
+ Documentation and Test Driven Development approach.
14
+
15
+ This will _ show_ you that it's not only _ possible_
16
+ to write docs and tests _ first_ ,
17
+ you will see _ first hand_ that ** ` code ` ** is ** more concise** ,
18
+ well-documented and thus ** _ easier_ to maintain**
19
+ and you will get your "work" done *** much faster*** .
20
+
21
+ These are _ foundational_ skills that will
22
+ pay ** _ immediate_ returns** on the time invested,
23
+ and will ** ` continue ` ** to ** ` return ` ** "** interest** "
24
+ for as long as you write (_ and people use your_ ) software!
25
+
26
+ > _ It's ** impossible** to "** over-state** " how ** vital writing tests first**
27
+ to both your ** personal effectiveness** and ** long-term sanity** .
28
+ Thankfully, by the end of this page, you will see how ** easy** it is._
29
+
30
+
11
31
12
32
## What?
13
33
@@ -19,14 +39,14 @@ Along the way we will cover:
19
39
+ [x] Browser Routing/Navigation
20
40
+ [x] Local Storage for Offline Support
21
41
22
- We will be abstracting all "TEA" related code
42
+ We will be abstracting all "TEA" related ("generic framework") code
23
43
into a file called ** ` elmish.js ` **
24
- so that our Todo List application can be as simple
44
+ so that our Todo List application can be as concise
25
45
and "declarative" as possible.
26
46
27
47
### Todo List?
28
48
29
- If you are _ unfamiliar_ with Todo lists,
49
+ If you are _ unfamiliar_ with Todo lists, simply put:
30
50
they are a way of keeping a list of the tasks that need to be done. <br />
31
51
see: https://en.wikipedia.org/wiki/Time_management#Setting_priorities_and_goals
32
52
@@ -38,17 +58,19 @@ Watch: https://www.youtube.com/results?search_query=checklist+manifesto
38
58
### TodoMVC?
39
59
40
60
If you have not come across TodoMVC before,
41
- it's a sample application to showcase various "frontend" frameworks.
61
+ it's a sample application to showcase various "frontend" frameworks
62
+ using a common user interface (UI): a Todo List Application.
42
63
![ TodoMVC-intro] ( https://user-images.githubusercontent.com/194400/42624420-4528a3c6-85bd-11e8-8b92-9b1c8951ba35.png )
43
64
44
65
45
- We highly recommend checking out the following links:
66
+ We _ highly recommend _ checking out the following links:
46
67
47
68
+ Website: http://todomvc.com
48
69
+ GitHub project: https://github.com/tastejs/todomvc
49
70
50
- For our purposes we will simply be re-using the ** ` CSS ` **
51
- to make our TEA Todo List _ look_ nice.
71
+ For our purposes we will simply be re-using the ** TodoMVC ` CSS ` **
72
+ to make our TEA Todo List _ look_ good
73
+ (_ not have to "worry" about styles so we can ** focus on functionality** _ ).
52
74
All the JavaScript code will be written "_ from scratch_ "
53
75
to ensure that everything is clear.
54
76
@@ -79,13 +101,19 @@ please see:
79
101
and
80
102
[ front-end-with-tape.md] ( https://github.com/dwyl/learn-tape/blob/master/front-end-with-tape.md )
81
103
104
+
105
+
106
+
82
107
It's "OK" to ask: "_ Where do I ** start** (my ** TDD** quest)?_ " <br />
83
108
The answer is: create ** two** new files:
84
109
` examples/todo-list/elmish.js ` and ` test/elmish.test.js `
85
110
86
111
We will create a couple of tests and their corresponding functions _ next_ !
87
112
88
- ## Elm(_ ish_ ) ?
113
+
114
+
115
+
116
+
89
117
90
118
Our ** first step** is to _ abstract_ and _ generalise_
91
119
the Elm Architecture (` mount ` ) and HTML ("DOM") functions
@@ -151,8 +179,9 @@ test('empty("root") removes DOM elements from container', function (t) {
151
179
```
152
180
153
181
> _ ** Note** : if any line in this file is ** unfamiliar** to you,
154
- please ** first** go back over the previous example(s),
155
- ** then** do bit of "googling" for any words or functions you don't recognise
182
+ please ** first** go back over the previous example(s)_ :
183
+ ` counter-basic ` _ and_ ` counter-reset ` ,
184
+ _ ** then** do bit of "googling" for any words or functions you don't recognise
156
185
e.g: ` childElementCount ` ,
157
186
and if you are ** still** "** stuck** "_ ,
158
187
[ *** please open an
@@ -1264,7 +1293,7 @@ writing the "business logic" of the Todo List Application,
1264
1293
because it will "make more sense" in context._
1265
1294
1266
1295
1267
- ### Elm(ish) Store > Save Model Data to ` localStorage `
1296
+ ### Elm(ish) Store > Save Model ( Data) to ` localStorage `
1268
1297
1269
1298
The _ final_ piece in the "Elm(ish)" puzzle is saving data on the device
1270
1299
so that the Todo List items (_ and history_ ) is not "_ lost_ " when
@@ -1412,7 +1441,8 @@ test.only('elmish.mount sets model in localStorage', function (t) {
1412
1441
});
1413
1442
```
1414
1443
1415
- There is quite a lot to "unpack" in this test but let's break it down:
1444
+ There is quite a lot to "unpack" in this test but let's walk through the steps:
1445
+
1416
1446
1 . Require the ` view ` and ` update ` from our counter reset example.
1417
1447
2 . ` mount ` the counter reset app
1418
1448
3 . *** test*** that the ` model ` (7) is being saved to ` localStorage `
@@ -1428,6 +1458,9 @@ the initial model from `localStorage` if it is defined.
1428
1458
Based on this test, try to add the necessary lines to the ` mount ` function,
1429
1459
to make the test pass.
1430
1460
1461
+ ** ` if ` ** you get stuck trying to make this test pass,
1462
+ refer to the completed code:
1463
+ [ /examples/todo-list/elmish.js] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js )
1431
1464
1432
1465
1433
1466
<!--
0 commit comments