Skip to content

Commit b56d6a3

Browse files
committed
update references in elmish.md to new foloder structure #5
1 parent efc7d16 commit b56d6a3

File tree

1 file changed

+37
-44
lines changed

1 file changed

+37
-44
lines changed

elmish.md

+37-44
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Let's start with a couple of "_familiar_" _generic_ functions
138138

139139
It's _essential_ to ask: "_Where do I **start** (my **TDD** quest)?_" <br />
140140
The answer is: create **two** new files:
141-
`examples/todo-list/elmish.js` and `test/elmish.test.js`
141+
`lib/elmish.js` and `test/elmish.test.js`
142142

143143

144144
### Test Setup
@@ -152,9 +152,9 @@ const test = require('tape'); // https://github.com/dwyl/learn-tape
152152
const fs = require('fs'); // to read html files (see below)
153153
const path = require('path'); // so we can open files cross-platform
154154
const html = fs.readFileSync(path.resolve(__dirname,
155-
'../examples/todo-list/index.html')); // sample HTML file to initialise JSDOM.
155+
'../index.html')); // sample HTML file to initialise JSDOM.
156156
require('jsdom-global')(html); // https://github.com/rstacruz/jsdom-global
157-
const elmish = require('../examples/todo-list/elmish.js'); // functions to test
157+
const elmish = require('../lib/elmish.js'); // functions to test
158158
const id = 'test-app'; // all tests use 'test-app' as root element
159159
```
160160

@@ -184,7 +184,7 @@ it is used to erase the DOM before re-rendering the app.
184184

185185
Following "**_Document(ation)_ Driven Development**",
186186
we create a **`JSDOC`** comment block
187-
in the `examples/todo-list/elmish.js` file
187+
in the `lib/elmish.js` file
188188
with _just_ the function description:
189189

190190
```js
@@ -259,7 +259,7 @@ You should see the following:
259259
#### `empty` Function _Implementation_
260260

261261
Now that we have the **test** for our `empty` function written,
262-
we can add the `empty` function to `examples/todo-list/elmish.js`:
262+
we can add the `empty` function to `lib/elmish.js`:
263263
```js
264264
/**
265265
* `empty` deletes all the DOM elements from within a specific "root" element.
@@ -281,7 +281,7 @@ function empty(node) {
281281

282282
Adding the function to the `elmish.js` file is a good _start_,
283283
but we need to ***`export`*** it to be able to _invoke_ it in our test. <br />
284-
Add the following code at the end of `examples/todo-list/elmish.js`:
284+
Add the following code at the end of `lib/elmish.js`:
285285

286286
```js
287287
/* module.exports is needed to run the functions using Node.js for testing! */
@@ -316,7 +316,7 @@ it "mounts" ("_renders_") the App in the "root" DOM element.
316316
It also tells our app to "re-render"
317317
when a `signal` with an `action` is received.
318318

319-
In `examples/todo-list/elmish.js` add the following `JSDOC` comment:
319+
In `lib/elmish.js` add the following `JSDOC` comment:
320320
```js
321321
/**
322322
* `mount` mounts the app in the "root" DOM Element.
@@ -333,7 +333,7 @@ In the `test/elmish.test.js` file, append the following code:
333333
```js
334334
// use view and update from counter-reset example
335335
// to invoke elmish.mount() function and confirm it is generic!
336-
const { view, update } = require('../examples/counter-reset/counter.js');
336+
const { view, update } = require('./counter.js');
337337

338338
test('elmish.mount app expect state to be Zero', function (t) {
339339
const root = document.getElementById(id);
@@ -360,7 +360,7 @@ see:_ `test/counter-reset.test.js`
360360
#### `mount` Function _Implementation_
361361

362362
Add the following code to the `mount` function body to make the test _pass_
363-
in `examples/todo-list/elmish.js`:
363+
in `lib/elmish.js`:
364364
```js
365365
/**
366366
* `mount` mounts the app in the "root" DOM Element.
@@ -670,7 +670,7 @@ by writing the `add_attributes` function. <br />
670670
(_don't forget to_ `export` _the function at the bottom of the file_).
671671

672672
If you get "stuck", checkout the _complete_ example:
673-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
673+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
674674

675675
> **Note 0**: we have "_seen_" the code _before_ in the `counter` example:
676676
> [counter.js#L51](https://github.com/dwyl/learn-elm-architecture-in-javascript/blob/814467e81b1b9739da74378455bd12721b096ebd/examples/counter-reset/counter.js#L51) <br />
@@ -735,7 +735,7 @@ and make this test _pass_:
735735
![image](https://user-images.githubusercontent.com/194400/43416921-8506baaa-9431-11e8-9585-814e704a694d.png)
736736

737737
If you get "stuck", checkout the _complete_ example:
738-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
738+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
739739

740740
<br />
741741

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

10441044
If you get "stuck", checkout:
1045-
https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js
1045+
https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/lib/elmish.js
10461046

10471047
<br />
10481048

@@ -1177,7 +1177,8 @@ It _should_ be the _easiest_ one so far.
11771177
Don't forget to remove the `.only` from the test, once you finish.
11781178

11791179
If you get "stuck", checkout:
1180-
https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js <br />
1180+
[`lib/elmish.js`](https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/lib/elmish.js)
1181+
<br />
11811182

11821183

11831184
### `<section>` HTML Element
@@ -1251,10 +1252,11 @@ Attempt to create the `section` function
12511252
using the `add_attributes` and `append_childnodes` "helper" functions.
12521253

12531254
If you get "stuck", checkout:
1254-
https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js <br />
1255+
[`lib/elmish.js`](https://github.com/dwyl/todomvc-vanilla-javascript-elm-architecture-example/blob/master/lib/elmish.js)
1256+
<br />
12551257
> _**Note**: in our "solution" we created a "helper" function
12561258
called `create_element` to "DRY" the HTML element creation code;
1257-
this is a *recommended** "best practice"._
1259+
this is a *recommended** "best practice" improves maintainability._
12581260

12591261
The `JSDOC` comment for our `create_element` function is:
12601262
```js
@@ -1341,7 +1343,7 @@ but has only one argument and invokes a native method.
13411343

13421344
If you get stuck trying to make this test pass,
13431345
refer to the completed code:
1344-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js )
1346+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js )
13451347

13461348

13471349
#### Create the "main" `view` functions
@@ -1420,7 +1422,7 @@ Just make the tests pass and try to keep your code _maintainable_.
14201422

14211423
Again, if you get stuck trying to make this test pass,
14221424
refer to the completed code:
1423-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
1425+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
14241426

14251427

14261428
#### Create the `<footer>` view functions
@@ -1493,7 +1495,7 @@ to `elmish.js` and `export` them so the test will pass.
14931495

14941496
if you get stuck trying to make this test pass,
14951497
refer to the completed code:
1496-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
1498+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
14971499

14981500
<br />
14991501

@@ -1617,7 +1619,7 @@ Try and figure it out for yourself before checking a solution.
16171619

16181620
**`if`** you get stuck trying to make this test pass,
16191621
refer to the completed code:
1620-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
1622+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
16211623

16221624

16231625
> _**Note**: do not "worry" about how to render the "right" content on the "page"
@@ -1738,7 +1740,7 @@ console.log('localStorage (polyfil) hello', localStorage.getItem('hello'));
17381740
// to confirm that our elmish.mount localStorage works and is "generic".
17391741

17401742
test.only('elmish.mount sets model in localStorage', function (t) {
1741-
const { view, update } = require('../examples/counter-reset/counter.js');
1743+
const { view, update } = require('./counter.js');
17421744

17431745
const root = document.getElementById(id);
17441746
elmish.mount(7, update, view, id);
@@ -1793,7 +1795,7 @@ to make the test pass.
17931795

17941796
**`if`** you get stuck trying to make this test pass,
17951797
refer to the completed code:
1796-
[/examples/todo-list/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
1798+
[/lib/elmish.js](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/todo-list/elmish.js)
17971799

17981800
<br />
17991801

@@ -1896,26 +1898,27 @@ Background reading: https://webaim.org/techniques/keyboard
18961898

18971899
#### Baseline Example Code _Without_ Subscription
18981900

1899-
Let's start by making a "copy" of the code in `/examples/counter-reset`:
1901+
Let's start by making a "copy" of the code in
1902+
[`/examples/counter-reset`](https://github.com/dwyl/learn-elm-architecture-in-javascript/tree/master/examples/counter-reset):
1903+
19001904
```sh
1901-
mkdir examples/counter-reset-keyboard
1902-
cp examples/counter-reset/* examples/counter-reset-keyboard/
1905+
cp test/counter.js test/counter-reset-keyboard.js
19031906
```
19041907

19051908
_First step_ is to _re-factor_ the code in
1906-
`examples/counter-reset-keyboard/counter.js`
1909+
`test/counter-reset-keyboard.js`
19071910
to use the "DOM" functions we've been creating for `Elm`(_ish_).
19081911
This will _simplify_ the `counter.js` down to the _bare minimum_.
19091912

1910-
In your `examples/counter-reset-keyboard/counter.js` file,
1913+
In your `test/counter-reset-keyboard.js` file,
19111914
type the following code:
19121915

19131916
```js
19141917
/* if require is available, it means we are in Node.js Land i.e. testing!
19151918
in the broweser, the "elmish" DOM functions are loaded in a <script> tag */
19161919
/* istanbul ignore next */
19171920
if (typeof require !== 'undefined' && this.window !== this) {
1918-
var { button, div, empty, h1, mount, text } = require('./elmish.js');
1921+
var { button, div, empty, h1, mount, text } = require('../lib/elmish.js');
19191922
}
19201923

19211924
function update (action, model) { // Update function takes the current state
@@ -1945,20 +1948,20 @@ if (typeof module !== 'undefined' && module.exports) {
19451948
}
19461949
}
19471950
```
1948-
1951+
<!--
19491952
Without _touching_ the code/tests
1950-
in **`examples/counter-reset-keyboard/test.js`**,
1953+
in **`test/counter-reset-keyboard.js`**,
1954+
19511955
You should just be able to _run_ the "liveserver" on your `localhost`:
19521956
19531957
```sh
1954-
npm start
1958+
npm run dev
19551959
```
1956-
19571960
and when you open: http://127.0.0.1:8000/examples/counter-reset-keyboard
19581961
19591962
should see the Qunit (Broweser) Tests _passing_:
19601963
![counter-reset-keyboard-broweser-tests-passing](https://user-images.githubusercontent.com/194400/43960760-ed098e80-9caa-11e8-9d8f-08310846dacb.png)
1961-
1964+
-->
19621965

19631966
#### How do We _Test_ for Subscription Events?
19641967

@@ -2003,7 +2006,7 @@ It's "OK" to "take a peek" at the sample code:
20032006
[**`examples/counter-reset-keyboard/counter.js`**](https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/files#diff-97353eabc55df91dbb3f96ba5a000a1aR26)
20042007

20052008
Once you add the **`subscriptions`** function to
2006-
**`examples/counter-reset-keyboard/counter.js`**,
2009+
**`test/counter-reset-keyboard.js`**,
20072010
Your tests should pass:
20082011

20092012
![counter-reset-keyboard-subscriptions-tests-passing](https://user-images.githubusercontent.com/194400/43981911-b6413dda-9ceb-11e8-8514-44fc1f88c3fe.png)
@@ -2021,17 +2024,7 @@ for our TodoMVC App!
20212024

20222025

20232026

2024-
2025-
2026-
2027-
2028-
2029-
2030-
2031-
2032-
2033-
2034-
### Why _Not_ use HTML5 `<template>` ??
2027+
### Why _Not_ use HTML5 `<template>` Element ??
20352028

20362029
Templates are an _awesome_ feature in HTML5 which
20372030
allow the creation of reusable markup!

0 commit comments

Comments
 (0)