-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcombineEpics.js
41 lines (33 loc) · 1.11 KB
/
combineEpics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { mergeArray } from 'most'
import { findIndex, map } from '@most/prelude'
export const combineEpics = epicsArray => (
actionsStream,
middlewareApiOrStateStream,
) => {
if (!epicsArray || !Array.isArray(epicsArray)) {
throw new TypeError('You must provide an array of Epics to combineEpics.')
}
if (epicsArray.length < 1) {
throw new TypeError(
'The array passed to combineEpics must contain at least one Epic.',
)
}
const callEpic = epic => {
if (typeof epic !== 'function') {
throw new TypeError(
'The array passed to combineEpics must contain only Epics (functions).',
)
}
const out = epic(actionsStream, middlewareApiOrStateStream)
if (!out || !out.source) {
const epicIdentifier = epic.name
? `named ${epic.name}`
: `at index ${findIndex(epic, epicsArray)} of the passed in array`
throw new TypeError(
`All Epics in the array provided to combineEpics must return a stream. Check the return value of the Epic ${epicIdentifier}.`,
)
}
return out
}
return mergeArray(map(callEpic, epicsArray))
}