use scoped dispatch rather than global dispatch, because rematch also used scoped store.
mirrorx:
import * as store_module from 'mirrorx/lib/store'; const getStore = () => store_module.store;;actions;rematch:
const store = init({ models });;dispatch, it should use scoped dispatch;You're right. We are currently working on making Rematch work with multiple stores. In order to do this, we have to implement some of the changes you've described.
Expect a few changes:
store.dispatch, and usable within connect. getState is currently deprecated and will be removedI hope you'll agree, when we are done, Rematch will have a more scoped and modular design.
If you have other suggestions, please let us know :)
Sorry, I just reread your post from the title.
const { store, dispatch } = init({ models })
There are a few reasons this is less than ideal.
Dispatch needs to be exported to other files.
export const { store, dispatch } = init({ models })
However, import/exports are run at startup and will result in an imported dispatch that is undefined.
There is a way around this.
export let fileDispatch
const { store, dispatch } = init({ models })
fileDispatch = dispatch
But I don't think anyone wants to see that.
There's another way to do this with classes, but also not pretty.
Well, store.dispatch as scoped dispatch is OK.
But export const { store, dispatch } = init({ models }) won't lead to an undefined dispatch.
Yeah, you're right. As long as dispatch is called before the rest of the app, and all imports are loaded later, this should work. I agree, this IS a good idea.
Though after some thought, I think a simpler solution can be reached to access scoped dispatch.
export const store = init()
export const { dispatch } = store
agree
Thanks again. You've outlined a problem: we should move people towards using scoped dispatch.
Globals are not a good idea.
Most helpful comment
You're right. We are currently working on making Rematch work with multiple stores. In order to do this, we have to implement some of the changes you've described.
Expect a few changes:
store.dispatch, and usable within connect.getStateis currently deprecated and will be removedI hope you'll agree, when we are done, Rematch will have a more scoped and modular design.
If you have other suggestions, please let us know :)