Skip to content

Commit 2931b8c

Browse files
fix(action-chain): pass operatorId and path correctly
1 parent 70f3422 commit 2931b8c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

packages/node_modules/action-chain/src/ActionBase.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
6161
: value
6262

6363
if (initialOperator && returnValue instanceof Promise) {
64-
returnValue.then((promiseValue) => {
64+
returnValue.then(() => {
6565
actionChain.emit('action:end', {
6666
actionId: executionContext.__execution.actionId,
6767
executionId: executionContext.__execution.executionId,
@@ -99,26 +99,34 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
9999
? executionContext.__path.concat(newPath)
100100
: executionContext.__path.slice(),
101101
}
102-
const path = executionContextWithPath.__path
103102
const prevResult = this.runOperators
104103
? this.runOperators(props, executionContextWithPath)
105104
: props
106105

107-
const operatorId = ++executionContextWithPath.__execution.operatorId
108-
109106
const produceResult = (currentValue) => {
110107
if (currentValue instanceof StopExecution) {
111108
return currentValue
112109
}
113110

114-
const context = this.actionChain.getContext(executionContextWithPath)
111+
const thisExecution = {
112+
...executionContextWithPath.__execution,
113+
operatorId: executionContextWithPath.__execution.operatorId + 1,
114+
}
115+
116+
executionContextWithPath.__execution.operatorId++
117+
118+
const path = executionContextWithPath.__path
119+
120+
const context = this.actionChain.getContext(
121+
thisExecution,
122+
executionContextWithPath
123+
)
115124

116125
this.actionChain.emit('operator:start', {
117126
type,
118127
name,
119128
path,
120-
...context.__execution,
121-
operatorId,
129+
...thisExecution,
122130
})
123131
const result = cb(context, currentValue)
124132

@@ -128,18 +136,16 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
128136
name,
129137
path,
130138
isAsync: true,
131-
...context.__execution,
132-
operatorId,
139+
...thisExecution,
133140
})
134141
return result.then((promiseResult) => {
135142
this.actionChain.emit('operator:end', {
136143
type,
137144
name,
138145
path,
139-
...context.__execution,
146+
...thisExecution,
140147
isAsync: true,
141148
result: promiseResult,
142-
operatorId,
143149
})
144150
return promiseResult
145151
})
@@ -149,10 +155,9 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
149155
type,
150156
name,
151157
path,
152-
...context.__execution,
158+
...thisExecution,
153159
isAsync: false,
154160
result: result,
155-
operatorId,
156161
})
157162

158163
return result

packages/node_modules/action-chain/src/ActionChain.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
6565
this.options.providerExceptions = options.providerExceptions || []
6666
}
6767

68-
getContext(executionContext: ExecutionContext) {
68+
getContext(thisExecution: Execution, executionContext: ExecutionContext) {
6969
const instance = this
7070
const providers = Object.keys(this.context).reduce(
7171
(currentContext, key) => {
@@ -81,15 +81,15 @@ export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
8181
if (result instanceof Promise) {
8282
result.then((promisedResult) => {
8383
instance.emit('provider', {
84-
...executionContext.__execution,
84+
...thisExecution,
8585
name: key,
8686
method: prop,
8787
result: promisedResult,
8888
})
8989
})
9090
} else {
9191
instance.emit('provider', {
92-
...executionContext.__execution,
92+
...thisExecution,
9393
name: key,
9494
method: prop,
9595
result,

packages/node_modules/action-chain/src/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('PROVIDER', () => {
140140
})
141141
fn()
142142
})
143-
test('should track execution of clas instance providers', () => {
143+
test('should track execution of class instance providers', () => {
144144
expect.assertions(2)
145145
const fn = action().test(({ test }) => {
146146
expect(test.foo()).toBe('bar')

0 commit comments

Comments
 (0)