@@ -19,27 +19,26 @@ function empty (node) {
19
19
* @param {Function } update how the application state is updated ("controller")
20
20
* @param {Function } view function that renders HTML/DOM elements with model.
21
21
* @param {String } root_element_id root DOM element in which the app is mounted
22
+ * @param {Function } subscriptions any event listeners the application needs
22
23
*/
23
24
function mount ( model , update , view , root_element_id , subscriptions ) {
24
25
var root = document . getElementById ( root_element_id ) ; // root DOM element
25
26
26
- function render ( mod , sig , root , subs ) {
27
+ function render ( mod , sig , root , subs ) { // DRY rendering code (invoked twice)
27
28
localStorage . setItem ( 'elmish_store' , JSON . stringify ( mod ) ) ; // save model!
28
29
empty ( root ) ; // clear root element (container) before (re)rendering
29
30
root . appendChild ( view ( mod , sig ) ) // render view based on model & signal
30
31
if ( subs && typeof subs === 'function' ) { subs ( sig ) ; } // event listeners
31
32
}
32
33
33
34
function signal ( action ) { // signal function takes action
34
- // console.log('action:', action);
35
35
return function callback ( ) { // and returns callback
36
36
model = JSON . parse ( localStorage . getItem ( 'elmish_store' ) ) || model ;
37
- // console.log('model BEFORE:', model);
38
37
var updatedModel = update ( action , model ) ; // update model for the action
39
- // console.log('model AFTER:', updatedModel);
40
38
render ( updatedModel , signal , root , subscriptions ) ;
41
39
} ;
42
40
} ;
41
+
43
42
model = JSON . parse ( localStorage . getItem ( 'elmish_store' ) ) || model ;
44
43
render ( model , signal , root , subscriptions ) ;
45
44
}
0 commit comments