Open LFFATE opened 4 years ago
Looks like I should move middleware from store to module:
export function commonModule(): IEpicModule<ModuleState> {
return {
id: 'module',
reducerMap: moduleReducer,
epics: moduleEpics,
middlewares: [epicMiddleware]
}
}
But problem with dependencies still actual and appears a new problem:
redux-observable | WARNING: this middleware is already associated with a store. createEpicMiddleware should be called for every store.
But there is just one store at the moment
So, I think I found the problem. And I think I can create a PR, just check my explorations:
// create deps object to be accessible in epics
const options= { dependencies: { ... }}
export const store = createStore({
initialState: persistedState,
// pass it to extension creator
extensions: [getObservableExtension(options)],
}, commonModule())
export function getObservableExtension(options?: Options): IExtension {
const epicMiddleware = createEpicMiddleware(options);
...
}
where Options is:
interface Options<D = any> {
dependencies?: D;
}
this type directly from redux-observable, but the library doesn't export it
Almost done with migration to redux-dynamic-modules, but I can't make my epics working. I use Dependencies Injection because of unit testing:
https://redux-observable.js.org/docs/recipes/InjectingDependenciesIntoEpics.html
and, for example, I try to create initial store:
And I see that epics are called, but at the moment it calls for dependency - it crushes because of undefined
Any suggestions please?
And another question:
epicMiddleware.run(rootEpic)
- rootEpic is any type, but with redux-dynamic-modules we should use Epic[] here:Where any - type from redux-observable, and I see that Epic type from redux-dynamic-modules-observable allows dependencies:
Should I manually call
epicMiddleware.run
and what argument with?