@@ -20,19 +20,28 @@ function empty (node) {
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
22
*/
23
- function mount ( model , update , view , root_element_id ) {
23
+ function mount ( model , update , view , root_element_id , subscriptions ) {
24
24
var root = document . getElementById ( root_element_id ) ; // root DOM element
25
- function signal ( action ) { // signal function takes action
26
- return function callback ( ) { // and returns callback
25
+
26
+ function render ( mod , sig , root , subs ) {
27
+ localStorage . setItem ( 'elmish_store' , JSON . stringify ( mod ) ) ; // save model!
28
+ empty ( root ) ; // clear root element (container) before (re)rendering
29
+ root . appendChild ( view ( mod , sig ) ) // render view based on model & signal
30
+ if ( subs && typeof subs === 'function' ) { subs ( sig ) ; } // event listeners
31
+ }
32
+
33
+ function signal ( action ) { // signal function takes action
34
+ // console.log('action:', action);
35
+ return function callback ( ) { // and returns callback
36
+ model = JSON . parse ( localStorage . getItem ( 'elmish_store' ) ) || model ;
37
+ // console.log('model BEFORE:', model);
27
38
var updatedModel = update ( action , model ) ; // update model for the action
28
- localStorage . setItem ( 'elmish_store' , JSON . stringify ( updatedModel ) ) ;
29
- empty ( root ) ; // clear root el before rerender
30
- root . appendChild ( view ( updatedModel , signal ) ) ; // subsequent re-rendering
39
+ // console.log('model AFTER:', updatedModel);
40
+ render ( updatedModel , signal , root , subscriptions ) ;
31
41
} ;
32
42
} ;
33
43
model = JSON . parse ( localStorage . getItem ( 'elmish_store' ) ) || model ;
34
- root . appendChild ( view ( model , signal ) ) // render initial model (once)
35
- localStorage . setItem ( 'elmish_store' , JSON . stringify ( model ) ) ; // save model!
44
+ render ( model , signal , root , subscriptions ) ;
36
45
}
37
46
38
47
/**
@@ -51,7 +60,7 @@ function add_attributes (attrlist, node) {
51
60
var a = attr . split ( '=' ) ;
52
61
switch ( a [ 0 ] ) {
53
62
case 'autofocus' :
54
- node . autofocus = "" ;
63
+ node . autofocus = "autofocus " ;
55
64
node . focus ( ) ;
56
65
break ;
57
66
case 'checked' :
0 commit comments