From da24cec7dd5cdd522b70a927b68fe3f2956034c6 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Mon, 8 May 2017 19:27:27 +0100 Subject: [PATCH] adds code to pass reset counter test (and screenshot) for https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/5#issuecomment-299949734 --- README.md | 17 ++++++++++++++--- examples/counter-reset/counter.js | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e615f705..8bf42455 100644 --- a/README.md +++ b/README.md @@ -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! + + + +


+ #### 9.1 Tests for Resetting the Counter We _always_ start with the Model test(s) @@ -397,9 +404,13 @@ Watch the test _fail_ in your Web Browser:
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)

diff --git a/examples/counter-reset/counter.js b/examples/counter-reset/counter.js index 77edeeda..3e564fb4 100644 --- a/examples/counter-reset/counter.js +++ b/examples/counter-reset/counter.js @@ -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) }