Skip to content

Commit b1e3ecf

Browse files
committed
finish writeup of Elm(_ish_) for #44
1 parent 81928f7 commit b1e3ecf

File tree

3 files changed

+491
-476
lines changed

3 files changed

+491
-476
lines changed

Diff for: elmish.md

+32-15
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ Your `module.exports` statement should now look something like this:
391391
if (typeof module !== 'undefined' && module.exports) {
392392
module.exports = {
393393
empty: empty,
394-
mount: mount,
395-
init: init
394+
mount: mount
396395
}
397396
} else { init(document); }
398397
```
@@ -455,10 +454,10 @@ _Don't worry, we will walk through building each feature in detail._
455454

456455
A todo list has only 2 _basic_ functions:
457456

458-
1. **Add** a `new` item to the list when the **`[Enter]`** key is pressed
457+
1. **Add** a `new` item to the list (when the **`[Enter]`** key is pressed)
459458
2. **Check-off** an item as "**completed**" (_done/finished_)
460459

461-
> **Add** item and **Check-off** is _exactly_ the "functionality"
460+
> **Add** item and "**Check-off**" is _exactly_ the "functionality"
462461
you would have in a _paper_-based Todo List.
463462

464463
#### TodoMVC "Advanced" Functionality
@@ -554,6 +553,8 @@ This is a "copy-paste" of the _generated_ code including the Todo items:
554553
Let's split each one of these elements into it's own `function`
555554
(_with any necessary "helpers"_) in the order they appear.
556555

556+
> For a "checklist" of these features see: https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/44
557+
557558
When building a House we don't think "build house" as our _first_ action. <br />
558559
_Instead_ we think: what are the "foundations" that need to be in place
559560
***before*** we lay the _first_ "brick"?
@@ -665,7 +666,7 @@ take a moment to think of how _you_ would write
665666
the `add_attributes` function to apply a CSS `class` to an element. <br />
666667

667668
If you can, make the test _pass_
668-
by writing the `add_attributes` function.
669+
by writing the `add_attributes` function. <br />
669670
(_don't forget to_ `export` _the function at the bottom of the file_).
670671

671672
If you get "stuck", checkout the _complete_ example:
@@ -681,7 +682,6 @@ the whole point of having a step-by-step tutorial
681682
is that you can check if you get "stuck",
682683
but you should only check _after_ making
683684
a good attempt to write the code _yourself_.
684-
<br />
685685

686686
> **Note 2**: The `add_attributes` function is "impure" as it "mutates"
687687
the target DOM `node`, this is more of a "fact of life" in JavaScript,
@@ -705,7 +705,7 @@ Once you make the test _pass_ you _should_ see the following in your Terminal:
705705

706706
The `<input>` form element (_where we create new Todo List items_)
707707
has a helpful `placeholder` attribute _prompting_ us with a question:
708-
"***What needs to be done?***"
708+
"_What needs to be done?_"
709709

710710
Add the following test to the `test/elmish.test.js` file: <br />
711711

@@ -798,7 +798,7 @@ we will _know_ that the `switch` is "_incomplete_". <br />
798798
and not having to"debate" or "discuss" the "merits" of it means
799799
we can have _confidence_ in the code.
800800

801-
#### Test `null` Attribute Value in `add_attributes` Function
801+
#### Test `null` Attribute Argument (`attrlist`) in `add_attributes` Function
802802

803803
Since JavaScript is _not_ statically/strictly typed we need to _consider_
804804
the situation where someone might _accidentally_ pass a `null` value.
@@ -867,6 +867,9 @@ In your `package.json` file add:
867867
Now whenever you `commit` your code, your tests will run
868868
and `istanbul` will check the test coverage level for you.
869869

870+
Let's get back to our `add_attributes` function!
871+
872+
<br />
870873

871874
#### Input `autofocus`
872875

@@ -894,7 +897,8 @@ test.only('elmish.add_attributes add "autofocus" attribute', function (t) {
894897
});
895898
```
896899

897-
Write the necessary code to make this test _pass_ in `elmish.js`.
900+
Write the necessary code to make this test _pass_
901+
as a `case` in `add_attributes` in `elmish.js`.
898902

899903
Relevant reading:
900904
+ `<input>` attributes:
@@ -973,6 +977,7 @@ test.only('elmish.add_attributes set "for" attribute <label> element', function
973977
Add the "`case`" in the `add_attributes` function's `switch` statement
974978
to make this test _pass_ in `elmish.js`.
975979

980+
<br />
976981

977982
#### `<input>` attribute `type`
978983

@@ -993,11 +998,13 @@ test('elmish.add_attributes type="checkbox" on <input> element', function (t) {
993998
});
994999
```
9951000

996-
Write the "case" in to make this test _pass_ in `elmish.js`.
1001+
Write the "case" in `add_attributes` to make this test _pass_ in `elmish.js`.
9971002

998-
`<input>` attribute `type`:
1003+
Relevant reading
1004+
+ `<input>` attribute `type`:
9991005
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes
10001006

1007+
<br />
10011008

10021009
#### Add `style` attribute to HTML element?
10031010

@@ -1035,8 +1042,9 @@ test.only('elmish.add_attributes apply style="display: block;"', function (t) {
10351042
Write the "case" in to make this test _pass_ in `elmish.js`.
10361043

10371044
If you get "stuck", checkout:
1038-
https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js <br />
1045+
https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js
10391046

1047+
<br />
10401048

10411049
#### `checked=true` attribute for "complete"/"done" items
10421050

@@ -1073,6 +1081,8 @@ and is **more intention revealing** to maintainers._"
10731081
For more detail on the `<input type="checkbox">`
10741082
see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox
10751083

1084+
<br />
1085+
10761086
#### Set `href` on `<a>` (anchor) element
10771087

10781088
The "filters" in the `<footer>` of TodoMVC contain 3 links ("anchors") `<a>`
@@ -1111,6 +1121,7 @@ Useful knowledge:
11111121
+ Why: https://stackoverflow.com/questions/4855168/what-is-href-and-why-is-it-used
11121122
+ How: https://stackoverflow.com/questions/4689344/how-can-i-add-href-attribute-to-a-link-dynamically-using-javascript
11131123

1124+
<br />
11141125

11151126
### `append_childnodes`
11161127

@@ -1567,7 +1578,7 @@ Consider the following JSDOC for the `route` function:
15671578

15681579
#### `route` _Test_!
15691580

1570-
Add the following _test_ to your `test/elmish.test.js` file: <br />:
1581+
Add the following _test_ to your `test/elmish.test.js` file: <br />
15711582

15721583
```js
15731584
test.only('elmish.route updates the url hash and sets history', function (t) {
@@ -1596,7 +1607,7 @@ test.only('elmish.route updates the url hash and sets history', function (t) {
15961607
#### `route` Implementation (_to make test(s) pass_)
15971608

15981609
The code to make these tests pass is only 3 or 4 lines.
1599-
(_depending on your implementation ..._)
1610+
(_depending on your implementation ..._) <br />
16001611
Provided the tests pass and you haven't "hard coded" the `return`,
16011612
there is no "wrong answer".
16021613
Try and figure it out for yourself before checking a solution.
@@ -1781,8 +1792,14 @@ to make the test pass.
17811792
refer to the completed code:
17821793
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
17831794

1795+
<br />
1796+
1797+
That's it for now! `Elm`(_ish_) is "ready" to be _used_
1798+
for our TodoMVC App!
1799+
1800+
<br />
17841801

1785-
### Why _Not_ use HTML5 `<template>`
1802+
### Why _Not_ use HTML5 `<template>` ??
17861803

17871804
Templates are an _awesome_ feature in HTML5 which
17881805
allow the creation of reusable markup!

0 commit comments

Comments
 (0)