state-observer
v1.0.14
Published
``` createStore (defaultState: Object) => { getState: () => Object; setState: (newState: Object); connect: (mapStateToProps: Object, func: Function); } ```
Downloads
6
Readme
Interface
createStore (defaultState: Object) => {
getState: () => Object;
setState: (newState: Object);
connect: (mapStateToProps: Object, func: Function);
}
Examples
- Create default store state
const defaultState = {
foo: 'bar',
fiz: 'buzz'
}
- Create Store
const store = createStore(defaultState);
- Connect function which triggered by a change of the part of store
//part of store
const mapStateToProps = (state) => ({
foo: state.foo
})
//triggered function
const func = ({foo}) => {
console.log('triggered')
}
store.connect(mapStateToProps, func)
- Change state
store.setState({foo: 'biba'})
- Connected func triggered
expected output: 'triggered'