Skip to content

Instantly share code, notes, and snippets.

@toruticas
Created August 13, 2018 13:18
Show Gist options
  • Save toruticas/9faf584d97bfbaf2bc63b42aaa25364c to your computer and use it in GitHub Desktop.
Save toruticas/9faf584d97bfbaf2bc63b42aaa25364c to your computer and use it in GitHub Desktop.
Real world bug modifying reference argument in a function
import { init } from "@rematch/core"
import * as models from "./models"
import * as reducers from "./reducers"
import { syncInitialStatePlugin } from "./plugins"
function initStore(initialStateModel ,initialStateRedux) {
store = init({
models: models,
plugins: [syncInitialStatePlugin(initialStateModel)],
redux: {
initialStateRedux,
middlewares: [thunkMiddleware],
reducers: reducers,
},
})
}
export const syncInitialStatePlugin = (state = {}) => ({
init: () => ({
onModel(model) {
model.state = state[model.name]
},
}),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment