Created
February 23, 2016 08:57
-
-
Save rndme/4e57e3f26f3eed92a170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<vcc-demo></vcc-demo> | |
<script src="http://danml.com/bundle/rndme.cia_rndme.vcc_.js"></script> | |
<script> | |
var store = CIA({ | |
INC: function(state, n) { | |
state.index+= (n||1); | |
}, | |
RESET: function(state, n) { | |
state.index= 0; | |
}, | |
}, { | |
index: 0 | |
}); | |
store._blnErrorThrowing = true; // for dev messaging | |
store.subscribe(function(state) { // fires after state changes | |
if(state.index == -1) return; | |
}); | |
VCC({ | |
displayName: "demo", | |
componentWillMount: function() { | |
this.unstore = store.subscribe(this._renderer); | |
}, | |
componentWillUnmount: function() { | |
this.unstore(); | |
}, | |
getDefaultProps: function(){ | |
return { | |
}; | |
}, | |
getInitialState: function() { | |
return { | |
}; | |
}, | |
render: function() { | |
var me = store.getState(); | |
return ` | |
<h3>${me.index} </h3> | |
<button on-click=store.actions.INC(2)>+2</button> | |
<button on-click=store.actions.RESET>0</button> | |
`; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment