Package Exports
- @rematch/immer
- @rematch/immer/package
- @rematch/immer/package.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rematch/immer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Rematch Immer
Immer plugin for Rematch. Provides immutable ability on immer library.
Install
npm install @rematch/immerFor @rematch/core@0.x use @rematch/immer@0.1.0
Setup
import immerPlugin from '@rematch/immer'
import { init } from '@rematch/core'
const immer = immerPlugin()
init({
plugins: [immer]
})Usage
Use Immer plugin, reducer could be use mutable method to achieve immutable state. Like the example:
const todo = {
state: [{
todo: "Learn typescript",
done: true
}, {
todo: "Try immer",
done: false
}],
reducers: {
done(state) {
state.push({todo: "Tweet about it"})
state[1].done = true
return state
}
}
};In Immer, reducers perform mutations to achieve the next immutable state. Keep in mind, Immer only supports change detection on plain objects and arrays, so primitive values like strings or numbers will always return a change. Like the example:
const count = {
state: 0,
reducers: {
add(state) {
state += 1
return state
}
}
};I suggest to developers that reducers could return changed value all the time.