@@ -7,11 +7,6 @@ export type ExecutionContext = {
77 __path : string [ ]
88}
99
10- export interface ActionChain < Context > extends EventEmitter {
11- getOptions ( ) : ActionChainOptions
12- getContext ( executionContext : ExecutionContext ) : Context & ExecutionContext
13- }
14-
1510export type ActionChainOptions = {
1611 actionWrapper ?: any
1712 providerExceptions ?: string [ ]
@@ -23,21 +18,24 @@ export type Execution = {
2318 executionId : number
2419}
2520
26- export function actionChainFactory < Context > (
27- context : Context ,
28- options : ActionChainOptions = { }
29- ) : ActionChain < Context > {
30- options . providerExceptions = options . providerExceptions || [ ]
21+ export class ActionChain < Context > extends EventEmitter {
22+ constructor (
23+ private context : Context ,
24+ private options : ActionChainOptions = { }
25+ ) {
26+ super ( )
27+ this . options . providerExceptions = options . providerExceptions || [ ]
28+ }
3129
32- return Object . assign ( new EventEmitter ( ) , {
33- getOptions ( ) {
34- return options
35- } ,
36- getContext ( executionContext : ExecutionContext ) {
37- const instance = this
38- const providers = Object . keys ( context ) . reduce ( ( currentContext , key ) => {
39- if ( IS_DEVELOPMENT && options . providerExceptions . indexOf ( key ) === - 1 ) {
40- currentContext [ key ] = new Proxy ( context [ key ] , {
30+ getContext ( executionContext : ExecutionContext ) {
31+ const instance = this
32+ const providers = Object . keys ( this . context ) . reduce (
33+ ( currentContext , key ) => {
34+ if (
35+ IS_DEVELOPMENT &&
36+ this . options . providerExceptions . indexOf ( key ) === - 1
37+ ) {
38+ currentContext [ key ] = new Proxy ( this . context [ key ] , {
4139 get ( target , prop ) {
4240 if ( typeof target [ prop ] === 'function' ) {
4341 return ( ...args ) => {
@@ -68,14 +66,20 @@ export function actionChainFactory<Context>(
6866 } ,
6967 } )
7068 } else {
71- currentContext [ key ] = context [ key ]
69+ currentContext [ key ] = this . context [ key ]
7270 }
7371
7472 return currentContext
75- } , { } )
73+ } ,
74+ { }
75+ )
76+ return { ...providers , ...executionContext }
77+ }
78+ }
7679
77- return Object . assign ( { } , providers , executionContext ) as Context &
78- ExecutionContext
79- } ,
80- } )
80+ export function actionChainFactory < Context > (
81+ context : Context ,
82+ options : ActionChainOptions = { }
83+ ) : ActionChain < Context > {
84+ return new ActionChain ( context , options )
8185}
0 commit comments