Skip to content

Instantly share code, notes, and snippets.

@rndme
Created February 23, 2016 08:57
Show Gist options
  • Save rndme/4e57e3f26f3eed92a170 to your computer and use it in GitHub Desktop.
Save rndme/4e57e3f26f3eed92a170 to your computer and use it in GitHub Desktop.
<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