@@ -38,7 +38,8 @@ Once you have had a "play" with the demo, come back and _build_ it!!
3838
3939## Why?
4040
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
4243_ consolidate_ your understanding of The Elm Architecture (TEA)
4344by creating a "real world" _ useable_ App following _ strict_
4445Documentation and Test Driven Development.
@@ -62,18 +63,23 @@ Thankfully, by the end of this chapter, you will see how **easy** it is._
6263
6364## What?
6465
65- _ Use _ our "TEA" knowledge to build a simple "Todo List" Application. <br />
66+ Build a fully functional "Todo List" Application! <br />
6667Along the way we will cover:
6768
6869+ [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
7071+ [x] Browser Routing/Navigation
7172+ [x] Local Storage for Offline Support
7273+ [x] Keyboard event listeners for rapid todo list creation and editing!
7374
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
7783and "declarative" as possible.
7884
7985### Todo List?
@@ -83,9 +89,10 @@ they are a way of keeping a list of the tasks that need to be done. <br />
8389see: https://en.wikipedia.org/wiki/Time_management#Setting_priorities_and_goals
8490
8591Todo 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 />
8793https://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
8996
9097### TodoMVC?
9198
@@ -112,16 +119,46 @@ This tutorial is for anyone/everyone who wants
112119to develop their "core" JavaScript skills (_ without using a framework/library_ )
113120while building a "real world" (_ fully functional_ ) Todo List Application.
114121
115- to _ apply_ their "TEA" knowledge
116- and _ think_ about the basics of a
117-
118122> 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
120124by opening a question you help _ everyone_ learn more effectively!
121125
122126
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+
123144## _ How?_
124145
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+
125162### ` Elm ` (_ ish_ ) ?
126163
127164In order to _ simplify_ the code for our Todo List App,
177214In your editor/terminal create the following files:
178215
179216+ ` 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 `
182219
183220These file names should be self-explanatory, but if unclear,
184221` 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.
193230
194231In the ` test/todo-app.test.js ` file, type the following code:
195232``` 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
197234const fs = require (' fs' ); // to read html files (see below)
198235const 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' ));
201237require (' 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
203239const id = ' test-app' ; // all tests use 'test-app' as root element
204240```
205241
206242> Most of this code should be _ familiar_ to you
207243 if you have followed previous tutorials.
208244> 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 )
210246and
211247[ ** front-end** -with-tape.md] ( https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/front-end-with-tape.md )
212248
@@ -215,7 +251,6 @@ you should see no output. <br />
215251(_ this is expected as we haven't written any tests yet!_ )
216252
217253
218-
219254### ` model `
220255
221256The ` 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.
257292This may "waste" a few CPU cycles computing the count but that's "OK"!
258293Even on an _ ancient_ Android device
259294this 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.
261296
262297
263298#### ` model ` _ Test_
@@ -1324,7 +1359,7 @@ into a functioning app!
13241359
13251360### Mount the App in ` index.html `
13261361
1327- Open your ** ` /examples/todo-list/ index.html` ** file
1362+ Open your ** ` index.html ` ** file
13281363and ensure that the following lines are in the ** ` <body> ` ** :
13291364
13301365``` html
@@ -1354,11 +1389,11 @@ and ensure that the following lines are in the **`<body>`**:
13541389```
13551390
13561391For 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 )
13581393
13591394
13601395If 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/
13621397
13631398You should see:
13641399![ 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:
15711606
15721607Try to make the "** 2. New Todo** " batch of tests _ pass_
15731608by creating (_ and exporting_ ) a ** ` subscriptions ` ** function
1574- in your ** ` examples/todo-list /todo-app.js` ** file.
1609+ in your ** ` lib /todo-app.js` ** file.
15751610
15761611If you get "_ stuck_ ", checkout the sample code:
15771612[ ** ` 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.
16931728
16941729Try and make this test pass by yourself before consulting the
16951730sample 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 )
16971732
16981733
16991734### 4. Item (Toggle, Edit & Delete)
@@ -2196,7 +2231,7 @@ But we are building a _visual_ application and are not _seeing_ anything ...
21962231
21972232Let's take a _brief_ detour to _visualise_ the progress we have made.
21982233
2199- Open the `examples/todo-list/ index.html` file
2234+ Open the `index.html` file
22002235and alter the contents of the `<script>` tag:
22012236```html
22022237<script>
@@ -2217,7 +2252,7 @@ Then in your terminal, start the live-server:
22172252``` sh
22182253npm start
22192254```
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 />
22212256You should see that the _ third_ todo list item is in "** editing _ mode_ ** ":
22222257
22232258![ elm-todomvc-editing-item] ( https://user-images.githubusercontent.com/194400/45180706-0eab5680-b214-11e8-9dcf-a8c4476e4b11.png )
0 commit comments