Skip to content

Commit

Permalink
fix: context binding in addModel (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
objectisundefined committed Mar 2, 2021
1 parent 69b44df commit 7f99a45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/core/src/rematchStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ export default function createRematchStore<
addModel(model: NamedModel<TModels>) {
validateModel(model)
createModelReducer(bag, model)
prepareModel(this, bag, model)
this.replaceReducer(createRootReducer(bag))
prepareModel(rematchStore, bag, model)
reduxStore.replaceReducer(createRootReducer(bag))
reduxStore.dispatch({ type: '@@redux/REPLACE' })
},
} as RematchStore<TModels, TExtraModels>

addExposed(rematchStore, config.plugins)

rematchStore.addModel.bind(rematchStore)

// generate dispatch[modelName][actionName] for all reducers and effects
bag.models.forEach((model) => prepareModel(rematchStore, bag, model))

Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,20 @@ describe('createStore:', () => {

expect(store.getState()).toEqual({ countA: 0, countB: 0, countC: 0 })
})

test('addModel works when it was used alone', () => {
const store = init()

const { addModel } = store

addModel({
name: 'count',
state: 0,
reducers: {},
})

expect(store.getState()).toEqual({
count: 0,
})
})
})

0 comments on commit 7f99a45

Please sign in to comment.