Skip to content

Commit 260c104

Browse files
committed
add support for Subscritions in elmish.js for #57
1 parent a3cf67e commit 260c104

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

examples/todo-list/elmish.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,26 @@ function empty (node) {
1919
* @param {Function} update how the application state is updated ("controller")
2020
* @param {Function} view function that renders HTML/DOM elements with model.
2121
* @param {String} root_element_id root DOM element in which the app is mounted
22+
* @param {Function} subscriptions any event listeners the application needs
2223
*/
2324
function mount (model, update, view, root_element_id, subscriptions) {
2425
var root = document.getElementById(root_element_id); // root DOM element
2526

26-
function render (mod, sig, root, subs) {
27+
function render (mod, sig, root, subs) { // DRY rendering code (invoked twice)
2728
localStorage.setItem('elmish_store', JSON.stringify(mod)); // save model!
2829
empty(root); // clear root element (container) before (re)rendering
2930
root.appendChild(view(mod, sig)) // render view based on model & signal
3031
if (subs && typeof subs === 'function') { subs(sig); } // event listeners
3132
}
3233

3334
function signal(action) { // signal function takes action
34-
// console.log('action:', action);
3535
return function callback() { // and returns callback
3636
model = JSON.parse(localStorage.getItem('elmish_store')) || model;
37-
// console.log('model BEFORE:', model);
3837
var updatedModel = update(action, model); // update model for the action
39-
// console.log('model AFTER:', updatedModel);
4038
render(updatedModel, signal, root, subscriptions);
4139
};
4240
};
41+
4342
model = JSON.parse(localStorage.getItem('elmish_store')) || model;
4443
render(model, signal, root, subscriptions);
4544
}

0 commit comments

Comments
 (0)