redux-simple-event
v1.2.1
Published
A redux implementation using Event Emitter
Downloads
29
Readme
redux-simple-event
npm i redux-simple-event
// store.js
const { ReduxSimpleEvent } = require('redux-simple-event');
class Store extends ReduxSimpleEvent {
// methods
}
module.exports = new Store()
Usage
Example:
// Setting a value on state
store.setState('member.name', 'John');
// Getting a state value
store.getState();
// General listener
store.addListener('change', func);
// Or specific listener
store.addListener('change-member-name', func);
Server side:
module.exports = new ReduxSimpleEvent({ foo: 'bar' }, { browser: false });
Marko Usage
You can use <provider />
component to encapsulate store.
// my-store-instance.js
module.exports = new ReduxSimpleEvent({ foo: 'bar' });
// index.marko
$ const myStoreInstance = require('../my-store-instance');
provider store=myStoreInstance
@content|{ store }|
inner-component ...store
// inner-component/index.marko
div -- ${ input.store.getState().foo}
// or
div -- ${ input.foo }