forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionChain.ts
More file actions
28 lines (24 loc) · 718 Bytes
/
ActionChain.ts
File metadata and controls
28 lines (24 loc) · 718 Bytes
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
import { EventEmitter } from 'betsy'
import { proxifyEffects } from './utils'
import { ActionChainEvents, Execution } from './types'
const IS_DEVELOPMENT = process.env.NODE_ENV !== 'production'
export class ActionChain<Effects, ExtraEvents = {}> extends EventEmitter<
ActionChainEvents & ExtraEvents
> {
constructor(
private effects: Effects,
private options: { providerExceptions?: string[] } = {}
) {
super()
}
getEffects(thisExecution: Execution) {
if (IS_DEVELOPMENT) {
return proxifyEffects(
this.effects,
this.options.providerExceptions,
(effect) => this.emitAsync('effect', { ...thisExecution, ...effect })
)
}
return this.effects
}
}