microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 115 forks source link

Can't use combineEpics with redux-dynamic-modules-observable #129

Open FraserKillip opened 4 years ago

FraserKillip commented 4 years ago

The code uses toString() to check uniqueness on Epics, but when using combineEpics the result is always the same which means that if two modules use combineEpics only the first module's epic will actually be loaded.

Is there a way to determine epic uniqueness without using toString()?

https://github.com/microsoft/redux-dynamic-modules/blob/163377fdd9118a231c22d42d093374cdd615a1f7/packages/redux-dynamic-modules-observable/src/EpicManager.ts#L40

mmissey commented 4 years ago

We have a factory that creates epics for metering/debouncing calls. We got around this issue by adding a name property to each epic and then epicKey = `${epic.name} ${epic.toString}

shinvey commented 4 years ago

Maybe it's not a good pattern to use combineEpics. My practice for many epics in a file, I'll try this way:

// epic.ts
export function epicOne () {}
export function epicTwo () {}
// rdm.ts
import reducer from './reducer';
import * as epics from './epic';

export default {
  // Unique id of the module
  id: 'entry',
  // Maps the Store key to the reducer
  reducerMap: {
    entry: reducer,
  },
  epics: Object.values(epics),
}

It's recommended to import epics as needed.