at present the subscriptions in the todo list example (that I am busy writing... #45) do not receive the model as an argument:
/**
* `subscriptions` let us "listen" for events such as "key press" or "click".
* and respond according to a pre-defined update/action.
* @param {Function} singal - the Elm Architicture "dispacher" which will run
* both the "update" and "render" functions when invoked with singal(action)
*/
function subscriptions (signal) {
var ENTER_KEY = 13; // add a new todo item when [Enter] key is pressed
var ESCAPE_KEY = 27; // used for "escaping" when editing a Todo item
document.addEventListener('keyup', function handler (e) {
var new_todo = document.getElementById('new-todo');
console.log('e.keyCode:', e.keyCode, '| key:', e.key);
if (e.keyCode === ENTER_KEY && new_todo.value.length > 0) {
signal('ADD')(); // invoke singal inner callback
new_todo.value = ''; // reset <input> so we can add another todo
document.getElementById('new-todo').focus();
}
});
}
This is an obvious fail (in retrospect) as we cannot "infer" the model when triggering an action!
So my next step is to re-trace my own instructions and refactor the subscriptions function!
pass the model into the subscriptions
reset and re-invoke the subscriptions when re-rendering
[x] understand the problem and fix it with the least code!
at present the subscriptions in the todo list example (that I am busy writing... #45) do not receive the
model
as an argument:This is an obvious fail (in retrospect) as we cannot "infer" the model when triggering an action! So my next step is to re-trace my own instructions and refactor the subscriptions function!
model
into the subscriptions