react-capacitor
v0.0.7
Published
Flux boilerplate – stores, and dispatcher.
Downloads
3
Readme
react-capacitor
Flux store, and dispatcher.
Example Usage
npm install --save react-capacitor
var Dispatcher = require('react-capacitor/lib/Dispatcher');
var AppDispatcher = new Dispatcher();
###Trigger an action in the view
AppDispatcher.triggerAction('signup', {
email: '[email protected]',
name: 'Emmett'
});
###Binding to actions
AppDispatcher.onAction('signup', function(data) {
UserStore.setProperties({
email: data.email,
name: data.name
});
// automatically emits the change event, but only when the data is different
});
Create a store and set the default
var Store = require('react-capacitor/lib/Store');
var UserStore = new Store({
// Default values
email: '',
name: ''
});
###Managing the store
// Set a single value
UserStore.set('email', '[email protected]');
// Set multiple values
UserStore.setProperties({name: 'Marty McFly', car: 'Delorean'});
// Reset and set multiple values
UserStore.setAll({name: 'Doc Brown'});
// Reset values
UserStore.reset();
###Getting store data
// Get a single value
UserStore.get('email');
// Get multiple values
UserStore.getProperties('email', 'name');
// Get all values
UserStore.getAll();
###Binding to change events on a React component
...
componentWillUnmount: function() {
UserStore.on('change', this._change);
},
componentWillUnmount: function() {
UserStore.removeListener('change', this._change);
},
...