README
rematch-state-plugin
use
state
&setState
in rematch effects
Install
$ npm i -S rematch-state-plugin
API
const rematchStatePlugin = require('rematch-state-plugin')
add plugin entry
import {init} from '@rematch/core'
const store = init({
models: {foo, bar},
plugins: [rematchStatePlugin()],
})
plugin create options
const {state, setState, setStateAction} = {
state: 'state',
setState: 'setState',
setStateAction: '__rematch_state_plugin_@@_set_state__',
}
this.state
& this.setState
in effects
use // models/count.js with this plugin enabled
export default {
state: {
val: 1,
},
effects: {
add() {
this.setState({val: this.state.val + 1})
},
},
}
// models/count.js without this plugin enabled
export default {
name: 'count',
state: {
val: 1,
},
setState(payload) {
return {...state, ...payload}
},
effects: {
add(payload, rootState) {
const nsp = 'count'
const {val} = rootState[nsp]
this.setState({val: val + 1})
},
},
}
Changelog
License
the MIT License http://magicdawn.mit-license.org