Skip to content

Commit 39779b2

Browse files
committed
re-order params of update function in counter.js and elmish.js for clarity see: #44 (comment)
1 parent 820250b commit 39779b2

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Diff for: elmish.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function mount(model, update, view, root_element_id) {
373373
var root = document.getElementById(root_element_id); // root DOM element
374374
function signal(action) { // signal function takes action
375375
return function callback() { // and returns callback
376-
var updatedModel = update(model, action); // update model for the action
376+
var updatedModel = update(action, model); // update model for the action
377377
empty(root); // clear root el before rerender
378378
view(signal, updatedModel, root); // subsequent re-rendering
379379
};
@@ -1701,7 +1701,7 @@ function mount(model, update, view, root_element_id) {
17011701
var root = document.getElementById(root_element_id); // root DOM element
17021702
function signal(action) { // signal function takes action
17031703
return function callback() { // and returns callback
1704-
var updatedModel = update(model, action); // update model for the action
1704+
var updatedModel = update(action, model); // update model for the action
17051705
empty(root); // clear root el before rerender
17061706
view(signal, updatedModel, root); // subsequent re-rendering
17071707
};

Diff for: examples/counter-reset/counter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Inc = 'inc'; // increment the counter
33
var Dec = 'dec'; // decrement the counter
44
var Res = 'reset'; // reset counter: git.io/v9KJk
55

6-
function update(model, action) { // Update function takes the current state
6+
function update (action, model) { // Update function takes the current state
77
switch(action) { // and an action (String) runs a switch
88
case Inc: return model + 1; // add 1 to the model
99
case Dec: return model - 1; // subtract 1 from model
@@ -27,7 +27,7 @@ function mount(model, update, view, root_element_id) {
2727
var root = document.getElementById(root_element_id); // root DOM element
2828
function signal(action) { // signal function takes action
2929
return function callback() { // and returns callback
30-
model = update(model, action); // update model according to action
30+
model = update(action, model); // update model according to action
3131
view(signal, model, root); // subsequent re-rendering
3232
};
3333
};

Diff for: test/counter-reset.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ test('Mount app expect state to be Zero', function (t) {
2121
t.end()
2222
});
2323

24-
test('Test Update update(0) returns 0 (current state)', function (t) {
25-
var result = update(0);
24+
test('Test Update update("", 0) returns 0 (current state)', function (t) {
25+
var result = update('', 0);
2626
t.equal(result, 0, "Initial state: 0, No Action, Final state: 0");
2727
t.end();
2828
});
2929

30-
test('Test Update increment: update(1, "inc") returns 2', function (t) {
31-
var result = update(1, "inc");
30+
test('Test Update increment: update("inc", 1) returns 2', function (t) {
31+
var result = update("inc", 1);
3232
t.equal(result, 2, "Initial state: 1, Increment once, Final state: 2");
3333
t.end();
3434
});
3535

36-
test('Test Update decrement: update(3, "dec") returns 2', function (t) {
37-
var result = update(1, "dec");
36+
test('Test Update decrement: update("dec", 1) returns 0', function (t) {
37+
var result = update("dec", 1);
3838
t.equal(result, 0, "Initial state: 1, Decrement once, Final state: 0");
3939
t.end();
4040
});
@@ -81,7 +81,7 @@ test('Click reset button resets state to 0', function (t) {
8181
// Reset Functionality
8282

8383
test('Test reset counter when model/state is 6 returns 0', function(t) {
84-
var result = update(6, "reset");
84+
var result = update("reset", 6);
8585
t.equal(result, 0, "counter reset to 0 (Zero)");
8686
t.end()
8787
});

0 commit comments

Comments
 (0)