@@ -38,7 +38,8 @@ Once you have had a "play" with the demo, come back and _build_ it!!
38
38
39
39
## Why?
40
40
41
- The _ purpose_ of this ** Todo List _ mini_ project** is to
41
+ The _ purpose_ of this ** Todo List _ mini_ project**
42
+ is to _ practice_ your "VanillaJS" skills and
42
43
_ consolidate_ your understanding of The Elm Architecture (TEA)
43
44
by creating a "real world" _ useable_ App following _ strict_
44
45
Documentation and Test Driven Development.
@@ -62,18 +63,23 @@ Thankfully, by the end of this chapter, you will see how **easy** it is._
62
63
63
64
## What?
64
65
65
- _ Use _ our "TEA" knowledge to build a simple "Todo List" Application. <br />
66
+ Build a fully functional "Todo List" Application! <br />
66
67
Along the way we will cover:
67
68
68
69
+ [x] Building an App using a pre-made CSS Styles/Framework!
69
- + [x] The Document Object Model (DOM)
70
+ + [x] The Document Object Model (DOM) + JSDOM
70
71
+ [x] Browser Routing/Navigation
71
72
+ [x] Local Storage for Offline Support
72
73
+ [x] Keyboard event listeners for rapid todo list creation and editing!
73
74
74
- We will be abstracting all "TEA" related ("generic") code
75
- into a file called ** ` elmish.js ` **
76
- so that our Todo List application can be as concise
75
+ We will be abstracting all "architecture" related ("generic") code
76
+ into a "mini frontend framework" called "*** elmish*** ".
77
+ (_ elmish is inspired by Elm but only meant for educational purposes!_ )
78
+
79
+ The journey to creating ** elmish** is captured in
80
+ [ ** ` elmish.md ` ** ] ( https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/elmish.md )
81
+ and fully documented code is in ** ` elmish.js ` ** .
82
+ This means our Todo List App can be as concise
77
83
and "declarative" as possible.
78
84
79
85
### Todo List?
@@ -83,9 +89,10 @@ they are a way of keeping a list of the tasks that need to be done. <br />
83
89
see: https://en.wikipedia.org/wiki/Time_management#Setting_priorities_and_goals
84
90
85
91
Todo Lists or "Checklists" are the _ best_ way of tracking tasks. <br />
86
- Atul Gawande wrote a _ superb_ book on this subject:
92
+ Atul Gawande wrote a _ superb_ book on this subject: < br />
87
93
https://www.amazon.com/Checklist-Manifesto-How-Things-Right/dp/0312430000 <br />
88
- Watch: https://www.youtube.com/results?search_query=checklist+manifesto
94
+ Or if you don't have time to read,
95
+ watch: https://www.youtube.com/results?search_query=checklist+manifesto
89
96
90
97
### TodoMVC?
91
98
@@ -112,16 +119,46 @@ This tutorial is for anyone/everyone who wants
112
119
to develop their "core" JavaScript skills (_ without using a framework/library_ )
113
120
while building a "real world" (_ fully functional_ ) Todo List Application.
114
121
115
- to _ apply_ their "TEA" knowledge
116
- and _ think_ about the basics of a
117
-
118
122
> As always, if you get "stuck", _ please_ open an issue:
119
- https://github.com/dwyl/learn- elm-architecture-in-javascript /issues
123
+ https://github.com/dwyl/todomvc-vanilla-javascript- elm-architecture-example /issues
120
124
by opening a question you help _ everyone_ learn more effectively!
121
125
122
126
127
+ ### Prerequisites
128
+
129
+ Most beginners with basic JavaScript and HTML knowledge
130
+ should be able to follow this example without any prior experience.
131
+ The code is commented and the most "complex" function is an event listener.
132
+ With that said, if you feel "stuck" at any point,
133
+ please consult the recommend reading (_ and Google_ )
134
+ and if you cannot find an answer,
135
+ please open an issue!
136
+
137
+ ### Recommended reading:
138
+
139
+ + Test Driven Developement: https://github.com/dwyl/learn-tdd
140
+ + Tape-specific syntax: https://github.com/dwyl/learn-tape
141
+ + Elm Architecture: https://github.com/dwyl/learn-elm-architecture-in-javascript
142
+
143
+
123
144
## _ How?_
124
145
146
+
147
+ Start by cloning this repository to your ` localhost `
148
+ so that you can follow the example/tutorial offline:
149
+
150
+ ``` sh
151
+ git clone https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example.git
152
+ ```
153
+
154
+ Install the ` devDependencies ` so you can run the tests:
155
+ ``` sh
156
+ cd todomvc-vanilla-javascript-elm-architecture-example && npm install
157
+ ```
158
+
159
+ Now you have _ everything_ you need to build a Todo List from scratch!
160
+
161
+
125
162
### ` Elm ` (_ ish_ ) ?
126
163
127
164
In order to _ simplify_ the code for our Todo List App,
177
214
In your editor/terminal create the following files:
178
215
179
216
+ ` test/todo-app.test.js `
180
- + ` examples/todo-list /todo-app.js`
181
- + ` examples/todo-list/ index.html`
217
+ + ` lib /todo-app.js`
218
+ + ` index.html `
182
219
183
220
These file names should be self-explanatory, but if unclear,
184
221
` todo-app.test.js ` is where we will write the tests for our
@@ -193,20 +230,19 @@ that "requires" the libraries/files so we can _execute_ the functions.
193
230
194
231
In the ` test/todo-app.test.js ` file, type the following code:
195
232
``` js
196
- const test = require (' tape' ); // https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example
233
+ const test = require (' tape' ); // https://github.com/dwyl/learn-tape
197
234
const fs = require (' fs' ); // to read html files (see below)
198
235
const path = require (' path' ); // so we can open files cross-platform
199
- const html = fs .readFileSync (path .resolve (__dirname ,
200
- ' ../examples/todo-list/index.html' )); // sample HTML file to initialise JSDOM.
236
+ const html = fs .readFileSync (path .resolve (__dirname , ' ../index.html' ));
201
237
require (' jsdom-global' )(html); // https://github.com/rstacruz/jsdom-global
202
- const app = require (' ../examples/todo-list /todo-app.js' ); // functions to test
238
+ const app = require (' ../lib /todo-app.js' ); // functions to test
203
239
const id = ' test-app' ; // all tests use 'test-app' as root element
204
240
```
205
241
206
242
> Most of this code should be _ familiar_ to you
207
243
if you have followed previous tutorials.
208
244
> If anything is _ unclear_ please revisit
209
- [ https://github.com/dwyl/**todomvc-vanilla-javascript-elm-architecture-example ** ] ( https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example )
245
+ [ https://github.com/dwyl/**learn-tape ** ] ( https://github.com/dwyl/learn-tape )
210
246
and
211
247
[ ** front-end** -with-tape.md] ( https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/front-end-with-tape.md )
212
248
@@ -215,7 +251,6 @@ you should see no output. <br />
215
251
(_ this is expected as we haven't written any tests yet!_ )
216
252
217
253
218
-
219
254
### ` model `
220
255
221
256
The ` model ` for our Todo List App is ** _ boringly_ simple** .
@@ -257,7 +292,7 @@ we will "compute" (derive) it "at runtime" to keep the `model` simple.
257
292
This may "waste" a few CPU cycles computing the count but that's "OK"!
258
293
Even on an _ ancient_ Android device
259
294
this will only take a millisecond to compute and
260
- will not "slow down" the app or affect UX.
295
+ won't "slow down" the app or affect UX.
261
296
262
297
263
298
#### ` model ` _ Test_
@@ -1324,7 +1359,7 @@ into a functioning app!
1324
1359
1325
1360
### Mount the App in ` index.html `
1326
1361
1327
- Open your ** ` /examples/todo-list/ index.html` ** file
1362
+ Open your ** ` index.html ` ** file
1328
1363
and ensure that the following lines are in the ** ` <body> ` ** :
1329
1364
1330
1365
``` html
@@ -1354,11 +1389,11 @@ and ensure that the following lines are in the **`<body>`**:
1354
1389
```
1355
1390
1356
1391
For a complete "snapshot" of the ` index.html ` file here,
1357
- see: [ ** ` examples/todo-list/ index.html` ** ] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/blob/ef56c490a48db8a900f1832d0cc373b75838b4d4/examples/todo-list/index.html )
1392
+ see: [ ** ` index.html ` ** ] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/blob/ef56c490a48db8a900f1832d0cc373b75838b4d4/examples/todo-list/index.html )
1358
1393
1359
1394
1360
1395
If you run the project with command ** ` npm start ` **
1361
- and navigate to: http://127.0.0.1:8000/examples/todo-list
1396
+ and navigate to: http://127.0.0.1:8000/
1362
1397
1363
1398
You should see:
1364
1399
![ view-working] ( https://user-images.githubusercontent.com/194400/43786145-e476bdd0-9a5f-11e8-9043-cf997be615ae.png )
@@ -1571,7 +1606,7 @@ if you need a recap, see:
1571
1606
1572
1607
Try to make the "** 2. New Todo** " batch of tests _ pass_
1573
1608
by creating (_ and exporting_ ) a ** ` subscriptions ` ** function
1574
- in your ** ` examples/todo-list /todo-app.js` ** file.
1609
+ in your ** ` lib /todo-app.js` ** file.
1575
1610
1576
1611
If you get "_ stuck_ ", checkout the sample code:
1577
1612
[ ** ` todo-app.js > subscriptions ` ** ] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/files#diff-6be3e16fe7cfb4c00788d4d587374afdR320 )
@@ -1693,7 +1728,7 @@ function to include `signal('TOGGLE_ALL')` in the attributes array.
1693
1728
1694
1729
Try and make this test pass by yourself before consulting the
1695
1730
sample code:
1696
- [ ** ` examples/todo-list /todo-app.js` ** ] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/files#diff-6be3e16fe7cfb4c00788d4d587374afdR46 )
1731
+ [ ** ` lib /todo-app.js` ** ] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/files#diff-6be3e16fe7cfb4c00788d4d587374afdR46 )
1697
1732
1698
1733
1699
1734
### 4. Item (Toggle, Edit & Delete)
@@ -2196,7 +2231,7 @@ But we are building a _visual_ application and are not _seeing_ anything ...
2196
2231
2197
2232
Let's take a _brief_ detour to _visualise_ the progress we have made.
2198
2233
2199
- Open the `examples/todo-list/ index.html` file
2234
+ Open the `index.html` file
2200
2235
and alter the contents of the `<script>` tag:
2201
2236
```html
2202
2237
<script>
@@ -2217,7 +2252,7 @@ Then in your terminal, start the live-server:
2217
2252
``` sh
2218
2253
npm start
2219
2254
```
2220
- In your browser, vist: http://127.0.0.1:8000/examples/todo-list/ <br />
2255
+ In your browser, vist: http://127.0.0.1:8000/ <br />
2221
2256
You should see that the _ third_ todo list item is in "** editing _ mode_ ** ":
2222
2257
2223
2258
![ elm-todomvc-editing-item] ( https://user-images.githubusercontent.com/194400/45180706-0eab5680-b214-11e8-9dcf-a8c4476e4b11.png )
0 commit comments