Skip to content

Commit

Permalink
adds code to pass reset counter test (and screenshot) for #5 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 8, 2017
1 parent 191cf6e commit da24cec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ we go through the following steps:
and often `should` have multiple tests to cover all cases._)
4. Write code to make the test(s) pass.

> `BEFORE` you continue, try and build the "reset"
functionality yourself following TDD approach!



<br /><br /><br />

#### 9.1 Tests for Resetting the Counter

We _always_ start with the Model test(s)
Expand All @@ -397,9 +404,13 @@ Watch the test _fail_ in your Web Browser: <br />

In the case of an App written with the Elm Architecture,
the minimum code is:
+ Action
+ Update (_case and/or function_)

+ Action in this case `var Res = 'reset';`
+ Update (_case and/or function_) to "_process the signal_" from the UI
(_i.e. handle the user's desired action_)
```js
case Res: return 0;
```
![reset-counter-test-passing](https://cloud.githubusercontent.com/assets/194400/25818892/05349e96-3424-11e7-8d42-b4cbbc1eb1a6.png)

<br /> <br />

Expand Down
3 changes: 2 additions & 1 deletion examples/counter-reset/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ function mount(muv, id) { // state is encapsulated by mount function
// Define the Component's Actions:
var Inc = 'inc'; // increment the counter
var Dec = 'dec'; // decrement the counter

var Res = 'reset'; // reset counter: git.io/v9KJk

function update(model, action) { // Update function takes the current state
switch(action) { // and an action (String) runs a switch
case Inc: return model + 1; // add 1 to the model
case Dec: return model - 1; // subtract 1 from model
case Res: return 0; // reset state to 0 (Zero) git.io/v9KJk
default: return model; // if no action, return curent state.
} // (default action always returns current)
}
Expand Down

0 comments on commit da24cec

Please sign in to comment.