Merged
Show file tree
Hide file tree
Changes from 1 commit
Show all changes
165 commits
Select commit Hold shift + click to select a range
6db982a
create basic files for "elmish" Todo List #44
nelsonicJul 5, 2018
cc1b8b8
adds todo-list.md (outline) for #44
nelsonicJul 9, 2018
8908312
add base TodoMVC CSS file from https://.com/tastejs/todomvc/tre…
nelsonicJul 10, 2018
7813efd
adds complete TodoMVC requirements to todo-list.md for #44
nelsonicJul 11, 2018
f6b7e6e
add link to todo-list.md in README.md #44
nelsonicJul 11, 2018
45ece77
add sample html code for TodoMVC https://.com/dwyl/learn-elm-ar…
nelsonicJul 12, 2018
5451619
refactor counter-reset tests to use tape (cleaner)!
nelsonicJul 13, 2018
94bbbbf
run tape tests in pre-commit and on CI (faster and simpler)
nelsonicJul 13, 2018
8aafc99
add link to https://.com/dwyl/learn-tape as using Tape in Todo …
nelsonicJul 13, 2018
c5101d9
add empty function with JSDOC & test for #44
nelsonicJul 14, 2018
08723c9
use jsdom-global instead of *manually* instantiating JSDOM! for #44
nelsonicJul 14, 2018
eeec661
use view & update from counter-reset example to test elmish.mount gen…
nelsonicJul 14, 2018
28ab679
add instructions for empty function in todo-list.md for #44
nelsonicJul 14, 2018
560c9bc
adds instructions+code for mount generic function in elm(ish) for #44
nelsonicJul 14, 2018
cb41458
add elmish.attributes function to apply HTML attributes to node for h…
nelsonicJul 15, 2018
0b28eca
add id case to attributes function for #44
nelsonicJul 15, 2018
41dd1a6
add package-lock.json to .gitignore #noise!
nelsonicJul 15, 2018
21f05d5
add tap-spec to package.json and test script to "prettify" test outpu…
nelsonicJul 15, 2018
25cd493
add instructions for elmish attributes function #44
nelsonicJul 15, 2018
606e293
rename attributes to add_attributes for clarity! #44
nelsonicJul 15, 2018
6763bae
adds elmish.append_children test, docs & function for #44
nelsonicJul 15, 2018
ac5eeb3
rename to elmish.append_childnodes for clarity ... #44
nelsonicJul 15, 2018
6a715fe
add Input Placeholder Attribute instructions, test and code for #44
nelsonicJul 16, 2018
cfa2832
remove test.only to ensure all tests are executed
nelsonicJul 16, 2018
536f2ec
add elmish.add_attributes set data-id on <li> element for #44
nelsonicJul 16, 2018
906639e
adds <label for="toggle-all"> for #44
nelsonicJul 16, 2018
511c868
update codecov script in .travis.yml (simplify)
nelsonicJul 16, 2018
43bd3d6
add type attribute to <input> element e.g: <input id="toggle-all" typ…
nelsonicJul 16, 2018
22c809b
adds instructions, docs, test and implementation for applying in-line…
nelsonicJul 17, 2018
4b1e680
add instructions, docs, test & code for checked=true for #44
nelsonicJul 18, 2018
6b6495a
add checked=false for toggling todo items
nelsonicJul 18, 2018
111644e
add href attribute to <a> tags (Docs, Tests & Code) for #44
nelsonicJul 19, 2018
a3a4bfa
add instructions, tests & code for <input autofocus> for #44
nelsonicJul 19, 2018
48e1bb8
<input autofocus> unavailable on iOS Safari! https://caniuse.com/#fea…
nelsonicJul 19, 2018
956ac1f
add test, JSDOC and implementation of <section> html element for #44
nelsonicJul 19, 2018
6c66a04
adds create_element DOM element creation function to "DRY" DOM code f…
nelsonicJul 19, 2018
59c5298
add <section> test code to todo-list.md for #44
nelsonicJul 19, 2018
be35d3e
add two "compound" views, tests, docs & code to pass tests! (for #44)
nelsonicJul 19, 2018
27ea95c
add remaining instructions/docs, tests & code for <footer> view! #44 …
nelsonicJul 20, 2018
59664d9
adds example location.href and history.pushState code for https://git…
nelsonicJul 21, 2018
fa20108
add JSDOC for elmish.route function for #46
nelsonicJul 22, 2018
b22596e
add instructions test(s) and code for routing! closes #46
nelsonicJul 22, 2018
a1a1e30
add intro text and sample code for saving Todo List data to localStor…
nelsonicJul 22, 2018
8f34ff7
adds test for localStorage functionality #47 to todo-list.md
nelsonicJul 22, 2018
fb83010
add test for Elm(ish) localStorage in mount function with implementat…
nelsonicJul 22, 2018
e0d64de
remove localstorage-polyfil from package.json as not using
nelsonicJul 22, 2018
e7d542f
adds "Acceptance Criteria" for localStorage functionality. closes #47
nelsonicJul 22, 2018
c70ba2b
preparing to move elm(ish) code to elmish.md ... for #44
nelsonicJul 23, 2018
47bb415
adds clarifying note on why "Elm(ish)" for #44
nelsonicJul 24, 2018
208c153
add Elm(ish) intro header image to elmish.md for #44
nelsonicJul 25, 2018
6fe6364
add What? Who? & How? sections to elmish.md for #44
nelsonicJul 25, 2018
2b21e7a
Always imagine that you are "_pairing_" with someone
nelsonicJul 26, 2018
f94ecd9
re-word Doc Driven Dev section
nelsonicJul 27, 2018
42e0a4a
add instructsion for elmish.init function to elmish.md for #44
nelsonicJul 28, 2018
7efdaf0
add screenshot of init + empty tests passing https://.com/dwyl/…
nelsonicJul 29, 2018
2e4622f
finish "transferring" the elm(ish) related code and docs to elmish.md…
nelsonicJul 29, 2018
6898e8b
add link to /examples/multiple-counters-instances/index.html for #40 …
nelsonicJul 30, 2018
075c4c4
minor markdown fixes for #44 https://youtu.be/E1vXNrN6BbU
nelsonicJul 30, 2018
f9ba7aa
remove init function from counter-reset.js & counter-reset.test.js fi…
nelsonicJul 30, 2018
6ec9868
remove init function from elmish.js & elmish.md see https://.co…
nelsonicJul 30, 2018
354685e
adds screenshots of tests failing & passing for add_attributes functi…
nelsonicJul 30, 2018
5041de1
add further instructions & screenshots for placeholder attribute in e…
nelsonicJul 30, 2018
81928f7
adds default branch test and pre-commit hook instructions to elmish.m…
nelsonicJul 31, 2018
b1e3ecf
finish writeup of `Elm`(_ish_) for #44
nelsonicJul 31, 2018
47caf12
add test setup lines to test/todo-app.test.js for #44
nelsonicAug 1, 2018
0ff09c2
add sample `model` to todo-list.md for #44
nelsonicAug 1, 2018
e1f9851
fix typo in elmish.md
nelsonicAug 1, 2018
820250b
add section on learning style and three options for when people can r…
nelsonicAug 1, 2018
39779b2
re-order params of update function in counter.js and elmish.js for cl…
nelsonicAug 1, 2018
caf8165
[WiP] link back to Todo List from elmish.md & add `update` section fo…
nelsonicAug 2, 2018
34c2a05
add code to pass default branch update test for #44
nelsonicAug 2, 2018
23c9d47
ADD item acceptance criteria for https://.com/dwyl/learn-elm-ar…
nelsonicAug 3, 2018
dba0be7
add section on refactoring update JSDOC and function signature or #44…
nelsonicAug 3, 2018
4571db0
add update ADD todo item test for #48
nelsonicAug 3, 2018
a19da15
adds sample implementation for update ADD case for #48
nelsonicAug 3, 2018
de9797e
finish writeup on ADD new todo item to list. #48
nelsonicAug 4, 2018
5d4ebc5
add sample code for making TOGGLE todo item test pass for #48
nelsonicAug 5, 2018
e29da0e
add writeup instructions for how to "undo" a todo item using TOGGLE a…
nelsonicAug 5, 2018
ff4d297
adds section for creating the `view` for Elm(ish) Todo List App #44 /…
nelsonicAug 5, 2018
afaed24
for now, ignore the <footer> and focus on rendering the Todo List! se…
nelsonicAug 5, 2018
dd51dcb
add (human readable) Acceptance Criteria and Test Assertions for "mai…
nelsonicAug 6, 2018
6137d41
[WiP] add test for "main" view #51
nelsonicAug 6, 2018
91efbbd
add assertions to main view test for #51
nelsonicAug 6, 2018
e7d6784
adds screenshot of failng test https://.com/dwyl/learn-elm-arch…
nelsonicAug 6, 2018
3cbb25b
add code to make render_item test pass see: https://.com/dwyl/l…
nelsonicAug 7, 2018
864f4cc
update test/elmish.test.js assertions in light of the removal of defa…
nelsonicAug 7, 2018
b660747
add code to make render_main pass see/fixes #51
nelsonicAug 7, 2018
82bd69d
remove (debuggin) console.log from render_item ... fix #52
nelsonicAug 7, 2018
171f34a
add screenshot and text reminding readers that we have 100% test cove…
nelsonicAug 7, 2018
8a50b25
add acceptance criteria for Todo List <footer> element https://…
nelsonicAug 7, 2018
8f2252a
add JSDOC comment for render_footer #53
nelsonicAug 7, 2018
68e2afa
add render_footer function implementation for #53
nelsonicAug 7, 2018
aae0490
adds JSDOC and test for view function #54
nelsonicAug 7, 2018
3096d81
add view function implementation to pass tests for #54
nelsonicAug 7, 2018
470ad9f
add link to reference implementation of view function fixes #54
nelsonicAug 7, 2018
ef56c49
refactor counter-reset example to use the elmish mount function signa…
nelsonicAug 8, 2018
93f00d0
add (failing) test and screenshot for "No Todos" test case #56
nelsonicAug 8, 2018
d1bd85e
add code to pass test for "No Todos" fixes #56
nelsonicAug 8, 2018
3b8eb11
add render function to DRY code in elmish mount function for #44 / #55
nelsonicAug 9, 2018
a3cf67e
add test (failing) for "2. New Todo" #55
nelsonicAug 9, 2018
260c104
add support for Subscritions in elmish.js for https://.com/dwyl…
nelsonicAug 9, 2018
c79eccf
add additional checks in Elmish/Todo-list App code for null values #44
nelsonicAug 9, 2018
86dcc83
add extra keyCode "trigger" assertion to exercise subscrition branch #55
nelsonicAug 9, 2018
7b56e55
update test for "2. New Todo" to test all branches
nelsonicAug 9, 2018
f37c398
reorder New Todo test assertions for clarity #55
nelsonicAug 9, 2018
d6c8b92
update examples/counter-reset/test.js to reflect change in parameter …
nelsonicAug 10, 2018
e3e5a65
cp examples/counter-reset/* examples/counter-reset-keyboard/ for #57
nelsonicAug 10, 2018
d890749
add test for onclick attribute for #57
nelsonicAug 10, 2018
d41c8d8
add test and code for onclick function in attributes for/fixes #58
nelsonicAug 10, 2018
7369443
add link to "solution" in onclick section of elmish.md
nelsonicAug 10, 2018
209d72d
add sample code after refactoring counter-reset-keyboard to use Elm(i…
nelsonicAug 10, 2018
a3e0644
fix failing test due to change in name of localstorage key for #57
nelsonicAug 10, 2018
9a10d60
[WiP] elmish subscription test FAILING for #57
nelsonicAug 10, 2018
39d270b
add additional assertions for counter-reset-keyboard example for #57
nelsonicAug 10, 2018
0fd18b2
tidy-up counter-reset-keyboard example subscrition considerably! #57
nelsonicAug 10, 2018
a326d58
update subscriptions parameter in elmish.mount for clarity fixe #57
nelsonicAug 10, 2018
9471c34
add screenshot of counter-reset-keyboard subscription tests passing #57
nelsonicAug 10, 2018
193d55e
add screenshot of 2. New Todo tests passing #57
nelsonicAug 10, 2018
89de33a
add code to make TOGGLE_ALL tests pass. see/fixes https://.com/…
nelsonicAug 11, 2018
fff65da
add link to sample code for TOGGLE_ALL #50
nelsonicAug 11, 2018
b8bb500
for some reason the class attribute *MUST* be last in array!
nelsonicAug 11, 2018
b277b6c
add test (passing) for 4. Item (toggle) done #44
nelsonicAug 11, 2018
a47b24c
[WiP] add outline of Acceptance Criteria for Editing a Todo List Item…
nelsonicAug 11, 2018
aa4d787
Updates some typos and flow up until no. 7 of the basic counter #44
itelesAug 12, 2018
77546af
add *failing* test for DELETE an item https://.com/dwyl/learn-e…
nelsonicSep 2, 2018
39ed374
implement DELETE todo item using least possible code. closes #59
nelsonicSep 4, 2018
a597688
add acceptance criteria and checklist of features for EDIT todo item #60
nelsonicSep 5, 2018
dbcca39
adds basic EDIT item implementation including EDIT and SAVE actions f…
nelsonicSep 5, 2018
ce3258e
Merge pull request #61 from dwyl/review-todo
nelsonicSep 5, 2018
72fd1a6
add link to StackOverflow answer for double-click function handler ht…
nelsonicSep 5, 2018
43d2133
adds test for render_item in edit mode! #60
nelsonicSep 6, 2018
fd60ff6
add screenshot of render_item ("edit mode") tests passing for #60
nelsonicSep 6, 2018
0ffb30b
rename localStorage key prefix inline with TodoMVC spec: https://gith…
nelsonicSep 6, 2018
c110c0c
add model.editing to sample model in examples/todo-list/index.html to…
nelsonicSep 6, 2018
1a89e35
add code to to make EDIT case pass for #60
nelsonicSep 6, 2018
2968cd8
add test for [ENTER] key in edit mode to SAVE revised todo item title…
nelsonicSep 6, 2018
c8098e9
add SAVE todo item title edit implementation for #60
nelsonicSep 6, 2018
eec3642
add test for SAVE *blank* todo title > should delete item for #60
nelsonicSep 6, 2018
0887ba8
add implementation for SAVE *blank* item title > deletes item. #60
nelsonicSep 6, 2018
4fdb098
add test for [esc] CANCEL ediing for #64
nelsonicSep 6, 2018
d812e6c
add implementation for [esc] CANCEL editing fixes #64
nelsonicSep 6, 2018
e367ce8
remove test.only ... derp!
nelsonicSep 6, 2018
c40a583
add tests for 6, 7 & 8 for #48 (shift up a gear! time to get this don…
nelsonicSep 7, 2018
b1f895b
update older tests to reflect clear-completed count in footer #48
nelsonicSep 7, 2018
fc2ed3c
add test for routing based on clicking links in footer #48
nelsonicSep 7, 2018
2e67605
add solution to routing all/active/completed using footer links inclu…
nelsonicSep 7, 2018
f118ec4
add solution to routing all/active/completed using footer links inclu…
nelsonicSep 7, 2018
812248b
first draft of TodoMVC tutorial *complete*!! :tada:
nelsonicSep 7, 2018
9cabb38
remove port from npm start script to allow heroku to pass in PORT env…
nelsonicSep 7, 2018
538d53a
comment out all console.log in todo-app.js to avoid noise ... un-comm…
nelsonicSep 7, 2018
fcb0102
remove dev script from package.json as not needed/used
nelsonicSep 7, 2018
31bb9bc
fix markdown fails in edit-todo.md
nelsonicSep 7, 2018
e08461b
fix mixed content warning from loading dwyl favicon over http ... htt…
nelsonicSep 7, 2018
607f004
add favicon.ico to examples/todo-list to avoid https://.com/dwy…
nelsonicSep 7, 2018
cd70fad
reference favicon.ico in todo-list/index.html for https://.com/…
nelsonicSep 7, 2018
ae61175
add link to https://todomvc-app.herokuapp.com/examples/todo-list in r…
nelsonicSep 7, 2018
a5df3c4
add space between learning styles in todo-list.md
nelsonicSep 7, 2018
1002ef5
"as a friend" >> "ask a friend" (correct typo!)
nelsonicSep 7, 2018
b8f3ae9
add links to lower order rendering function issues to show workflow #…
nelsonicSep 7, 2018
913b4d5
move edit-todo.md to todo-list.md (consolidate)
nelsonicSep 7, 2018
a72ce67
remove edit-todo.md ... copy/code is in todo-list.md
nelsonicSep 7, 2018
21e74f6
recommend reading https://.com/dwyl/learn-heroku to deploy your…
nelsonicSep 7, 2018
26e661e
add hyperlink to implementation of DELETE update case: https://…
nelsonicSep 7, 2018
ee9c95d
expand section 9 to explain the code a bit better ... #60
nelsonicSep 8, 2018
f986777
add extended explanation of non-destructive filters in section 9 (rou…
nelsonicSep 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
PrevPrevious commit
Next Next commit
[WiP] elmish subscription test FAILING for #57
  • Loading branch information
@nelsonic
nelsonic committedAug 10, 2018
commit 9a10d60edcc7ef05d3f7ffa220e7efd75e462312
Original file line numberDiff line numberDiff line change
Expand Up@@ -1883,6 +1883,18 @@ and consider an alternative User Interaction/Experience: Keyboard!

#### Use-case: Use Up/Down Keyboard (Arrow) Keys to Increment/Decrement Counter

As a user <br />
I would like to use the keyboard **`[↑]`** (Up) and **`[↓]`** (Down) arrow keys
to signal the **Increment** and **Decrement** action (_respectively_)
of the Counter.
So that I don't have to use a mouse to click a button.

![up-down-arrrow-keys](https://user-images.usercontent.com/194400/43962720-4cbfb192-9cb0-11e8-9c45-63e7644f1cf6.png)

Background reading: https://webaim.org/techniques/keyboard

#### Baseline Example Code _Without_ Subscription

Let's start by making a "copy" of the code in `/examples/counter-reset`:
```sh
mkdir examples/counter-reset-keyboard
Expand DownExpand Up@@ -1920,8 +1932,8 @@ function view(model, signal) {
div(["class=count", "id=count"], [text(model.toString())]), // count
button(["class=dec", "id=dec", signal('dec')], [text('-')]), // decrement
button(["class=reset", "id=reset", signal('reset')], [text('Reset')])
]); // forEach is ES5 so IE9+
} // yes, for loop is "faster" than forEach, but readability trumps "perf" here!
]);
}

/* The code block below ONLY Applies to tests run using Node.js */
/* istanbul ignore else */
Expand All@@ -1947,9 +1959,40 @@ should see the Qunit (Broweser) Tests _passing_:
![counter-reset-keyboard-broweser-tests-passing](https://user-images.usercontent.com/194400/43960760-ed098e80-9caa-11e8-9d8f-08310846dacb.png)



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

As described above in our "use case" we want to create event listeners,
for the **`[↑]`** (Up) and **`[↓]`** (Down) arrow keyboard keys,
so the _only_ way to _test_ for these is to "Trigger" the event(s).
Thankfully, this is _easy_ in JavaScript. Let's write the test!

Add the following _test code_ to your `test/elmish.test.js` file: <br />
```js
test here!
```

Run the test (_watch it fail_!):
```sh
node test/elmish.test.js
```
![subscriptions-test-failing](https://user-images.usercontent.com/194400/43964543-f4a6e520-9cb4-11e8-80f5-ae6bb491b83f.png)

Hopefully it's clear from reading the test _why_ the assertion is _failing_.
The counter is not being incremented.
The last assertion passes because
"_even a broken clock is right twice a day_" ...
since the counter is never incremented,
the count is 0 (zero) throughout the test,
so the last assertion always passes.
(_this will not be the case
once you have the [Up] arrow event listener working_).

#### `subscriptions`_Implementation_: Keyboard Keys Increment/Decrement Counter!

We could spend an hour googling or I can _give_ you the sample code






Expand All@@ -1962,6 +2005,18 @@ for our TodoMVC App!

<br />













### Why _Not_ use HTML5 `<template>` ??

Templates are an _awesome_ feature in HTML5 which
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,27 +22,27 @@ function empty (node) {
* @param {Function} subscriptions any event listeners the application needs
*/
function mount (model, update, view, root_element_id, subscriptions) {
var root = document.getElementById(root_element_id); // root DOM element
var ROOT = document.getElementById(root_element_id); // root DOM element
var store_name = 'elmish_' + root_element_id; // test-app !== app

function render (mod, sig, root, subs) { // DRY rendering code (invoked twice)
localStorage.setItem(store_name, JSON.stringify(mod)); // save model!
empty(root); // clear root element (container) before (re)rendering
root.appendChild(view(mod, sig)) // render view based on model & signal
if (subs && typeof subs === 'function') { subs(sig); } // event listeners
if (subs && typeof subs === 'function') { subs(sig, root); } // subscription
}

function signal(action) { // signal function takes action
return function callback() { // and returns callback
console.log('signal action:', action);
model = JSON.parse(localStorage.getItem(store_name)) //|| model;
var updatedModel = update(action, model); // update model for the action
render(updatedModel, signal, root, subscriptions);
render(updatedModel, signal, ROOT, subscriptions);
};
};

model = JSON.parse(localStorage.getItem(store_name)) || model;
render(model, signal, root, subscriptions);
render(model, signal, ROOT, subscriptions);
}

/**
Expand Down