Skip to content

Commit 1002ef5

Browse files
committed
"as a friend" >> "ask a friend" (correct typo!)
1 parent a5df3c4 commit 1002ef5

File tree

1 file changed

+47
-39
lines changed

1 file changed

+47
-39
lines changed

Diff for: todo-list.md

+47-39
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Along the way we will cover:
5050
+ [x] The Document Object Model (DOM)
5151
+ [x] Browser Routing/Navigation
5252
+ [x] Local Storage for Offline Support
53+
+ [x] Keyboard event listeners for rapid todo list creation and editing!
5354

5455
We will be abstracting all "TEA" related ("generic") code
5556
into a file called **`elmish.js`**
@@ -72,7 +73,7 @@ Watch: https://www.youtube.com/results?search_query=checklist+manifesto
7273
### TodoMVC?
7374

7475
If you have not come across TodoMVC before,
75-
it's a sample application to showcase various "frontend" frameworks
76+
it's a website that showcases various "frontend" frameworks
7677
using a common user interface (UI): a Todo List Application.
7778
![TodoMVC-intro](https://user-images.githubusercontent.com/194400/42624420-4528a3c6-85bd-11e8-8b92-9b1c8951ba35.png)
7879

@@ -137,9 +138,9 @@ The choice is yours; there is no "_right_" way to learn.
137138
_Before_ diving into _building_ the Todo List App,
138139
we need to consider how we are going to _test_ it.
139140
By ensuring that we follow **TDD** from the _start_ of an App,
140-
we will have ["**no surprises"](https://youtu.be/u5CVsCnxyXg)
141+
we will have ["***no surprises***"](https://youtu.be/u5CVsCnxyXg)
141142
and _avoid_ having to "correct" any
142-
["**bad habits**"](https://www.youtube.com/results?search_query=Destiny%27s+Child+Bad+Habit).
143+
["***bad habits***"](https://www.youtube.com/results?search_query=Destiny%27s+Child+Bad+Habit).
143144

144145
We will be using **Tape** and **JSDOM** for testing
145146
both our functions and the final application.
@@ -156,6 +157,7 @@ In your editor/terminal create the following files:
156157

157158
+ `test/todo-app.test.js`
158159
+ `examples/todo-list/todo-app.js`
160+
+ `examples/todo-list/index.html`
159161

160162
These file names should be self-explanatory, but if unclear,
161163
`todo-app.test.js` is where we will write the tests for our
@@ -188,25 +190,24 @@ and
188190
[**front-end**-with-tape.md](https://github.com/dwyl/learn-tape/blob/master/front-end-with-tape.md)
189191

190192
If you attempt to run the test file: `node test/todo-app.test.js`
191-
you should see no output.
193+
you should see no output. <br />
192194
(_this is expected as we haven't written any tests yet!_)
193195

194196

195197

196198
### `model`
197199

198200
The `model` for our Todo List App is **_boringly_ simple**.
199-
All we need is an `Object` containing two keys `todos` and `hash`:
201+
All we need is an `Object` with a
202+
`todos` key which has an Array of Objects as it's value:
200203

201204
```js
202205
{
203206
todos: [
204207
{ id: 1, title: "Learn Elm Architecture", done: true },
205208
{ id: 2, title: "Build Todo List App", done: false },
206209
{ id: 3, title: "Win the Internet!", done, false }
207-
],
208-
hash: '#/', // the "route" to display
209-
editing: false // if we are editing a todo list item this will be set.
210+
]
210211
}
211212
```
212213
`todos` is an `Array` of `Objects` and each Todo (Array) item
@@ -282,8 +283,8 @@ e.g:
282283
* and as the "reset" state when all todos are deleted at once.
283284
*/
284285
var initial_model = {
285-
todos: [],
286-
hash: "#/"
286+
todos: [], // empty array which we will fill shortly
287+
hash: "#/" // the hash in the url (for routing)
287288
}
288289

289290
/* module.exports is needed to run the functions using Node.js for testing! */
@@ -328,12 +329,13 @@ The **`JSDOC`** for our `update` function is:
328329

329330
As with the `update` in our `counter` example
330331
the function body is a `switch` statement
331-
that "decides" how to handle a request based on the `action` (_also known as the "message"_).
332+
that "decides" how to handle a request based on the `action`
333+
(_also known as the "message"_).
332334

333335
Given that we _know_ that our `update` function "skeleton"
334336
will be a `switch` statement
335337
(_because that is the "TEA" pattern_)
336-
good test to _start_ with is the `default case`.
338+
a good test to _start_ with is the `default case`.
337339

338340
Append following test code in `test/todo-app.test.js`:
339341

@@ -358,10 +360,13 @@ You should see the assertion _fail_:
358360
Write the _minimum_ code necessary to pass the test.
359361

360362
> Yes, we could just write:
363+
361364
```js
362365
function update (action, model) { return model; }
363366
```
367+
364368
And that _would_ make the test _pass_. <br />
369+
365370
But, in light of the fact that we **know** the `update`
366371
function body will contain a `switch` statement,
367372
make the test pass by returning the `model` _unmodified_ in the `default` case.
@@ -595,17 +600,15 @@ _FROM_:
595600
{
596601
todos: [
597602
{id: 1, "Toggle a todo list item", done: false }
598-
],
599-
hash: "#/"
603+
]
600604
}
601605
```
602606
_TO_:
603607
```js
604608
{
605609
todos: [
606610
{id: 1, "Toggle a todo list item", done: true }
607-
],
608-
hash: "#/"
611+
]
609612
}
610613
```
611614

@@ -653,8 +656,8 @@ If you get "stuck" see: [**`todo-app.js`**](https://github.com/dwyl/learn-elm-ar
653656

654657
#### Hold On, Does This Work _Both_ Ways?
655658

656-
_Yes_, You _guessed_ it,
657-
choosing to name the `action` as "`TOGGLE`"
659+
_Yes_, you _guessed_ it!
660+
Choosing to name the `action` as "`TOGGLE`"
658661
is _precisely_ because we don't _need_
659662
to have a _**separate**_ function
660663
to "undo" an item if it has been "checked off".
@@ -727,7 +730,8 @@ whereas the second and third items are still "todo" (`done=false`).
727730

728731
This is what this `model` looks like in the "VanillaJS"
729732
TodoMVC:
730-
echo ![todomvc-3-items-1-done](https://user-images.githubusercontent.com/194400/43689907-e9caa548-98f8-11e8-8fd1-7b63e7fc5e30.png)
733+
734+
![todomvc-3-items-1-done](https://user-images.githubusercontent.com/194400/43689907-e9caa548-98f8-11e8-8fd1-7b63e7fc5e30.png)
731735

732736
Our _quest_ in the next "pomodoro" is to re-create this
733737
using the DOM functions we created in `Elm`(_ish_)!
@@ -742,6 +746,7 @@ and _just_ focus on rendering the _list_ itself.
742746

743747
In your web browser, open **Dev**eloper **Tools**
744748
and _inspect_ the HTML for the Todo list:
749+
http://todomvc.com/examples/vanillajs/
745750

746751
![todomvc-main-section-todo-list-html](https://user-images.githubusercontent.com/194400/43717480-9fb80982-997f-11e8-9ffe-6aa90a89a042.png)
747752

@@ -791,7 +796,7 @@ with a **`class="view"`** which "wraps":
791796
(_which updates the model
792797
From: `model.todos[id].done=false`
793798
To: `model.todos[id].done=true`_)
794-
+ [ ] **`<label>`** - the text content of the todo list item
799+
+ [ ] **`<label>`** - the text content ("title") of the todo list item
795800
+ [ ] **`<button class="destroy">`** - the button the person
796801
can click/tap to **`delete`** a Todo item.
797802

@@ -852,17 +857,18 @@ Given the test above, I added the following code to my `todo-app.js` file:
852857
```js
853858
/* if require is available, it means we are in Node.js Land i.e. testing! */
854859
/* istanbul ignore next */
855-
const { a, button, div, empty, footer, input, h1, header, label, li, mount,
856-
route, section, span, strong, text, ul } =
857-
(typeof require !== 'undefined') ? require('./elmish.js') : {};
860+
if (typeof require !== 'undefined' && this.window !== this) {
861+
var { a, button, div, empty, footer, input, h1, header, label, li, mount,
862+
route, section, span, strong, text, ul } = require('./elmish.js');
863+
}
858864

859865
/**
860866
* `render_item` creates an DOM "tree" with a single Todo List Item
861867
* using the "elmish" DOM functions (`li`, `div`, `input`, `label` and `button`)
862868
* returns an `<li>` HTML element with a nested `<div>` which in turn has the:
863-
* + `<input type=checkbox>` which lets users to "Toggle" the status of the item
864-
* + `<label>` which displays the Todo item text (`title`) in a `<text>` node
865-
* + `<button class="destroy">` lets people "delete" a todo item.
869+
* `<input type=checkbox>` which lets users to "Toggle" the status of the item
870+
* `<label>` which displays the Todo item text (`title`) in a `<text>` node
871+
* `<button class="destroy">` lets people "delete" a todo item.
866872
* see: https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/52
867873
* @param {Object} item the todo item object
868874
* @return {Object} <li> DOM Tree which is nested in the <ul>.
@@ -968,18 +974,20 @@ Onwards!
968974
<br />
969975

970976

971-
### `<footer>` Element [issues/53](https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/53)
977+
### `<footer>` Element [issues/53](https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/53)
972978

973979
Referring again to the _rendered_ HTML
974980
on http://todomvc.com/examples/vanillajs as our "guide":
975-
![image](https://user-images.githubusercontent.com/194400/42633421-5eb20f24-85d8-11e8-94ad-bb653dd93ab0.png)
981+
982+
![footer-screenshot](https://user-images.githubusercontent.com/194400/42633421-5eb20f24-85d8-11e8-94ad-bb653dd93ab0.png)
983+
976984
there is:
977-
+ [ ] a **`<footer>`** element with
978-
+ [ ] a **`<span>`** element which contains
979-
+ [ ] a **`text`** node with: **"`{count}` item(s) left"**.
980-
+ [ ] a **`<ul>`** containing
981-
+ [ ] 3 **`<li>`** elements each with
982-
+ [ ] a link (**`<a>`**) which allow the "user"
985+
+ [ ] **`<footer>`** element with:
986+
+ [ ] **`<span>`** element which contains
987+
+ [ ] **`text`** node with: **"`{count}` item(s) left"**.
988+
+ [ ] **`<ul>`** containing
989+
+ [ ] 3 x **`<li>`** elements each with
990+
+ [ ] link (**`<a>`**) which allow the "user"
983991
to ***filter*** which items appear in the **`<view>`**.
984992
+ [ ] a **`<button class="clear-completed">`**
985993
which will **_Clear_ all `Completed`** items when clicked.
@@ -1046,7 +1054,7 @@ from building the previous view functions
10461054
**`render_item`** and **`render_main`**
10471055
we ***estimate*** with _reasonable confidence_
10481056
that it will take us
1049-
**_25 minutes** (_**one** "**pomodoro**_)
1057+
**25 minutes** (_**one** "**pomodoro**_)
10501058
to:
10511059
+ [ ] Craft the **`JSDOC`** comment _documenting_ the `render_footer` function
10521060
so that all future developers will _easily_ understand what the function does.
@@ -1143,8 +1151,8 @@ Given the docs and test above, attempt to write the `render_footer` function.
11431151
with what happens when the "Clear completed" **`<buton>`** is clicked/tapped.
11441152
We will "cover" that below. For now, focus on rendering the DOM._
11451153

1146-
> If you get "stuck" trying to make the tests pass, first keep tring!
1147-
Then "as a friend" and finally, consult the _reference_ implementation in:
1154+
> If you get "stuck" trying to make the tests pass, first keep trying! <br />
1155+
Then "ask a friend" and finally, consult the _reference_ implementation in:
11481156
[**`todo-app.js`**](https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/commits/68e2afa3bd95c46da7df559007d90dedcbae500f#diff-6be3e16fe7cfb4c00788d4d587374afdR103)
11491157

11501158

@@ -1279,8 +1287,8 @@ you will see something like this ("_Red_"):
12791287
You should have the knowledge & skill
12801288
to write the `view` function and make the test pass.
12811289

1282-
> If you get "stuck" trying to make the tests pass, first keep tring!
1283-
Then "as a friend" and finally, consult the _reference_ implementation in:
1290+
> If you get "stuck" trying to make the tests pass, first keep trying! <br />
1291+
Then "ask a friend" and finally, consult the _reference_ implementation in:
12841292
[**`todo-app.js`**](https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/commits/3096d81a777392c07a132136db496224871ff4c9#diff-6be3e16fe7cfb4c00788d4d587374afdR145)
12851293

12861294
When you run `npm test` you should see something like this:

0 commit comments

Comments
 (0)