action-chain
Advanced tools
Comparing version 1.0.0-1532274233141 to 1.0.0-1532533507115
@@ -27,7 +27,5 @@ import * as tslib_1 from "tslib"; | ||
}; | ||
var path = executionContextWithPath.__path; | ||
var prevResult = _this.runOperators | ||
? _this.runOperators(props, executionContextWithPath) | ||
: props; | ||
var operatorId = ++executionContextWithPath.__execution.operatorId; | ||
var produceResult = function (currentValue) { | ||
@@ -37,6 +35,9 @@ if (currentValue instanceof StopExecution) { | ||
} | ||
var context = _this.actionChain.getContext(executionContextWithPath); | ||
var thisExecution = tslib_1.__assign({}, executionContextWithPath.__execution, { operatorId: executionContextWithPath.__execution.operatorId + 1 }); | ||
executionContextWithPath.__execution.operatorId++; | ||
var path = executionContextWithPath.__path; | ||
var context = _this.actionChain.getContext(thisExecution, executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, context.__execution, { operatorId: operatorId })); | ||
path: path }, thisExecution)); | ||
var result = cb(context, currentValue); | ||
@@ -46,7 +47,7 @@ if (result instanceof Promise) { | ||
name: name, | ||
path: path, isAsync: true }, context.__execution, { operatorId: operatorId })); | ||
path: path, isAsync: true }, thisExecution)); | ||
return result.then(function (promiseResult) { | ||
_this.actionChain.emit('operator:end', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, context.__execution, { isAsync: true, result: promiseResult, operatorId: operatorId })); | ||
path: path }, thisExecution, { isAsync: true, result: promiseResult })); | ||
return promiseResult; | ||
@@ -57,3 +58,3 @@ }); | ||
name: name, | ||
path: path }, context.__execution, { isAsync: false, result: result, operatorId: operatorId })); | ||
path: path }, thisExecution, { isAsync: false, result: result })); | ||
return result; | ||
@@ -72,3 +73,3 @@ }; | ||
var currentExecutionId = 0; | ||
return Object.assign(function (value) { | ||
var func = Object.assign(function (value) { | ||
var initialOperator = typeof arguments[1] === 'undefined'; | ||
@@ -90,2 +91,4 @@ var newPath = typeof arguments[2] === 'undefined' ? null : arguments[2]; | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
value: value, | ||
}); | ||
@@ -101,2 +104,3 @@ } | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
}); | ||
@@ -109,2 +113,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
}); | ||
@@ -114,2 +119,3 @@ } | ||
}, this); | ||
return func; | ||
} | ||
@@ -116,0 +122,0 @@ ActionBase.nextActionId = 0; |
@@ -19,4 +19,8 @@ import { EventEmitter } from 'betsy'; | ||
executionId: number; | ||
actionName: string; | ||
value?: any; | ||
}; | ||
export declare type OperatorExecution = ActionExecution & { | ||
export declare type OperatorExecution = { | ||
actionId: number; | ||
executionId: number; | ||
operatorId: number; | ||
@@ -51,3 +55,3 @@ type: string; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
getContext(executionContext: ExecutionContext): { | ||
getContext(thisExecution: Execution, executionContext: ExecutionContext): { | ||
__execution: Execution; | ||
@@ -54,0 +58,0 @@ __path: string[]; |
@@ -14,3 +14,3 @@ import * as tslib_1 from "tslib"; | ||
} | ||
ActionChain.prototype.getContext = function (executionContext) { | ||
ActionChain.prototype.getContext = function (thisExecution, executionContext) { | ||
var _this = this; | ||
@@ -32,7 +32,7 @@ var instance = this; | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
instance.emit('provider', tslib_1.__assign({}, thisExecution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
instance.emit('provider', tslib_1.__assign({}, thisExecution, { name: key, method: prop, result: result })); | ||
} | ||
@@ -39,0 +39,0 @@ return result; |
@@ -48,2 +48,13 @@ import * as tslib_1 from "tslib"; | ||
}); | ||
describe('ACTION', function () { | ||
test('should be able to give the action a name', function () { | ||
expect.assertions(1); | ||
var test = action(); | ||
test.displayName = 'My Name'; | ||
actionChain.once('action:start', function (execution) { | ||
expect(execution.actionName).toEqual('My Name'); | ||
}); | ||
test(); | ||
}); | ||
}); | ||
describe('VALUE', function () { | ||
@@ -58,4 +69,2 @@ test('should run and return result', function () { | ||
expect.assertions(2); | ||
var wut = action(); | ||
console.log(wut.test); | ||
var test = action().test(function (_a) { | ||
@@ -96,3 +105,3 @@ var __execution = _a.__execution, __path = _a.__path; | ||
}); | ||
test('should track execution of clas instance providers', function () { | ||
test('should track execution of class instance providers', function () { | ||
expect.assertions(2); | ||
@@ -99,0 +108,0 @@ var fn = action().test(function (_a) { |
@@ -29,7 +29,5 @@ "use strict"; | ||
}; | ||
var path = executionContextWithPath.__path; | ||
var prevResult = _this.runOperators | ||
? _this.runOperators(props, executionContextWithPath) | ||
: props; | ||
var operatorId = ++executionContextWithPath.__execution.operatorId; | ||
var produceResult = function (currentValue) { | ||
@@ -39,6 +37,9 @@ if (currentValue instanceof StopExecution) { | ||
} | ||
var context = _this.actionChain.getContext(executionContextWithPath); | ||
var thisExecution = tslib_1.__assign({}, executionContextWithPath.__execution, { operatorId: executionContextWithPath.__execution.operatorId + 1 }); | ||
executionContextWithPath.__execution.operatorId++; | ||
var path = executionContextWithPath.__path; | ||
var context = _this.actionChain.getContext(thisExecution, executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, context.__execution, { operatorId: operatorId })); | ||
path: path }, thisExecution)); | ||
var result = cb(context, currentValue); | ||
@@ -48,7 +49,7 @@ if (result instanceof Promise) { | ||
name: name, | ||
path: path, isAsync: true }, context.__execution, { operatorId: operatorId })); | ||
path: path, isAsync: true }, thisExecution)); | ||
return result.then(function (promiseResult) { | ||
_this.actionChain.emit('operator:end', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, context.__execution, { isAsync: true, result: promiseResult, operatorId: operatorId })); | ||
path: path }, thisExecution, { isAsync: true, result: promiseResult })); | ||
return promiseResult; | ||
@@ -59,3 +60,3 @@ }); | ||
name: name, | ||
path: path }, context.__execution, { isAsync: false, result: result, operatorId: operatorId })); | ||
path: path }, thisExecution, { isAsync: false, result: result })); | ||
return result; | ||
@@ -74,3 +75,3 @@ }; | ||
var currentExecutionId = 0; | ||
return Object.assign(function (value) { | ||
var func = Object.assign(function (value) { | ||
var initialOperator = typeof arguments[1] === 'undefined'; | ||
@@ -92,2 +93,4 @@ var newPath = typeof arguments[2] === 'undefined' ? null : arguments[2]; | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
value: value, | ||
}); | ||
@@ -103,2 +106,3 @@ } | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
}); | ||
@@ -111,2 +115,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
}); | ||
@@ -116,2 +121,3 @@ } | ||
}, this); | ||
return func; | ||
} | ||
@@ -118,0 +124,0 @@ ActionBase.nextActionId = 0; |
@@ -19,4 +19,8 @@ import { EventEmitter } from 'betsy'; | ||
executionId: number; | ||
actionName: string; | ||
value?: any; | ||
}; | ||
export declare type OperatorExecution = ActionExecution & { | ||
export declare type OperatorExecution = { | ||
actionId: number; | ||
executionId: number; | ||
operatorId: number; | ||
@@ -51,3 +55,3 @@ type: string; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
getContext(executionContext: ExecutionContext): { | ||
getContext(thisExecution: Execution, executionContext: ExecutionContext): { | ||
__execution: Execution; | ||
@@ -54,0 +58,0 @@ __path: string[]; |
@@ -16,3 +16,3 @@ "use strict"; | ||
} | ||
ActionChain.prototype.getContext = function (executionContext) { | ||
ActionChain.prototype.getContext = function (thisExecution, executionContext) { | ||
var _this = this; | ||
@@ -34,7 +34,7 @@ var instance = this; | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
instance.emit('provider', tslib_1.__assign({}, thisExecution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
instance.emit('provider', tslib_1.__assign({}, thisExecution, { name: key, method: prop, result: result })); | ||
} | ||
@@ -41,0 +41,0 @@ return result; |
@@ -50,2 +50,13 @@ "use strict"; | ||
}); | ||
describe('ACTION', function () { | ||
test('should be able to give the action a name', function () { | ||
expect.assertions(1); | ||
var test = action(); | ||
test.displayName = 'My Name'; | ||
actionChain.once('action:start', function (execution) { | ||
expect(execution.actionName).toEqual('My Name'); | ||
}); | ||
test(); | ||
}); | ||
}); | ||
describe('VALUE', function () { | ||
@@ -60,4 +71,2 @@ test('should run and return result', function () { | ||
expect.assertions(2); | ||
var wut = action(); | ||
console.log(wut.test); | ||
var test = action().test(function (_a) { | ||
@@ -98,3 +107,3 @@ var __execution = _a.__execution, __path = _a.__path; | ||
}); | ||
test('should track execution of clas instance providers', function () { | ||
test('should track execution of class instance providers', function () { | ||
expect.assertions(2); | ||
@@ -101,0 +110,0 @@ var fn = action().test(function (_a) { |
{ | ||
"name": "action-chain", | ||
"version": "1.0.0-1532274233141", | ||
"version": "1.0.0-1532533507115", | ||
"description": "Functional actions", | ||
@@ -34,5 +34,5 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", | ||
"tslib": "^1.9.3", | ||
"betsy": "1.0.0-1532274233141" | ||
"betsy": "1.0.0-1532533507115" | ||
}, | ||
"devDependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102293
1025
+ Addedbetsy@1.0.0-1532533507115(transitive)
- Removedbetsy@1.0.0-1532274233141(transitive)
Updatedbetsy@1.0.0-1532533507115