Способ, которым я бы предложил сделать это - объединить отдельные эпопеи в «метаэпику».То есть вы можете использовать отдельные потоки, чтобы прослушивать их отдельные события и распространять их, когда все объединенные потоки завершены.
const getUserEpic = action$ => ...
const someOtherEpic = action$ => ...
// Creates an epic that merges all the results from each provided epic
const initializationEpic = combineEpics(getUserEpic, someOtherEpic)
const appLoadEpic = (action$, state$) => {
// Runs the new epic with the action and state values.
const onLoad$ = initializationEpic(action$, state$).pipe(
endWith({type: LOAD_APP_SUCCESS})
)
// Listen for the load app request before subscribing to the initialization
action$.pipe(
ofType(LOAD_APP_REQUEST),
mergeMapTo(onLoad$),
)
}
Если вы чувствуете себя модно и не хотите вводитьэпосы через импорт, вы также можете динамически внедрять эпосы. документы подробно описывают способ асинхронной инъекции эпопеи, что означает, что вместо внедрения файла вы можете включить его как часть тела действия во время запуска, это можетсделать тестирование немного проще.
const appLoadEpic = (action$, state$) => {
// Listen for the load app request before subscribing to the initialization
action$.pipe(
ofType(LOAD_APP_REQUEST),
// Now the epic is injected during the app loading, and you run it inline
// here. This makes it easy to mock it during testing
mergeMap(({epic}) => epic(action$, state$).pipe(endWith({type: LOAD_APP_SUCCESS}))),
)
}