action-chain
Advanced tools
Comparing version 1.0.0-1532598454955 to 1.0.0-1532612418339
@@ -6,13 +6,14 @@ import { ActionChain, Execution } from './ActionChain'; | ||
} | ||
export declare class ActionBase<Context, InitialValue, Value = InitialValue> { | ||
export declare class ActionBase<Effects> { | ||
private actionChain; | ||
private initialActionId; | ||
private runOperators?; | ||
static nextActionId: number; | ||
private initialActionId; | ||
private actionChain; | ||
private runOperators; | ||
constructor(actionChain: ActionChain<Context>, initialActionId?: number, runOperators?: (value: any, executionContext: { | ||
private currentExecutionId; | ||
constructor(actionChain: ActionChain<Effects>, initialActionId?: number, runOperators?: (value: any, executionContext: { | ||
__execution: Execution; | ||
__path: string[]; | ||
}, newPath?: string) => any | Promise<any>); | ||
getActionChain: () => ActionChain<Context>; | ||
createOperatorResult: (type: string, name: string, cb: any) => [ActionChain<Context>, number, any]; | ||
getActionChain: () => ActionChain<Effects>; | ||
createOperatorResult: (type: string, name: string, cb: any) => [ActionChain<Effects>, number, any]; | ||
} |
@@ -13,2 +13,6 @@ import * as tslib_1 from "tslib"; | ||
var _this = this; | ||
this.actionChain = actionChain; | ||
this.initialActionId = initialActionId; | ||
this.runOperators = runOperators; | ||
this.currentExecutionId = 0; | ||
this.getActionChain = function () { | ||
@@ -38,7 +42,7 @@ return _this.actionChain; | ||
var path = executionContextWithPath.__path; | ||
var context = _this.actionChain.getContext(thisExecution, executionContextWithPath); | ||
var effects = _this.actionChain.getEffects(thisExecution, executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, thisExecution)); | ||
var result = cb(context, currentValue); | ||
var result = cb(effects, currentValue); | ||
if (result instanceof Promise) { | ||
@@ -67,7 +71,3 @@ _this.actionChain.emit('operator:async', tslib_1.__assign({ type: type, | ||
}; | ||
this.actionChain = actionChain; | ||
this.runOperators = runOperators; | ||
this.initialActionId = initialActionId; | ||
var currentExecutionId = 0; | ||
var func = Object.assign(function (value) { | ||
var instance = Object.assign(function (value) { | ||
var initialOperator = typeof arguments[1] === 'undefined'; | ||
@@ -80,3 +80,3 @@ var newPath = typeof arguments[2] === 'undefined' ? null : arguments[2]; | ||
actionId: initialActionId, | ||
executionId: currentExecutionId++, | ||
executionId: instance.currentExecutionId++, | ||
}, | ||
@@ -90,3 +90,3 @@ __path: [], | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
value: value, | ||
@@ -103,3 +103,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
}); | ||
@@ -112,3 +112,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
}); | ||
@@ -118,3 +118,3 @@ } | ||
}, this); | ||
return func; | ||
return instance; | ||
} | ||
@@ -121,0 +121,0 @@ ActionBase.nextActionId = 0; |
@@ -51,8 +51,8 @@ import { EventEmitter } from 'betsy'; | ||
} | ||
export declare class ActionChain<Context> extends EventEmitter<ActionChainEvents> { | ||
private context; | ||
export declare class ActionChain<Effects> extends EventEmitter<ActionChainEvents> { | ||
private effects; | ||
private options; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
constructor(effects: Effects, options?: ActionChainOptions); | ||
private createGetHandler; | ||
getContext(thisExecution: Execution, executionContext: ExecutionContext): Context & ExecutionContext; | ||
getEffects(thisExecution: Execution, executionContext: ExecutionContext): Effects & ExecutionContext; | ||
} |
@@ -9,6 +9,6 @@ import * as tslib_1 from "tslib"; | ||
tslib_1.__extends(ActionChain, _super); | ||
function ActionChain(context, options) { | ||
function ActionChain(effects, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.context = context; | ||
_this.effects = effects; | ||
_this.options = options; | ||
@@ -48,10 +48,10 @@ _this.options.providerExceptions = options.providerExceptions || []; | ||
}; | ||
ActionChain.prototype.getContext = function (thisExecution, executionContext) { | ||
ActionChain.prototype.getEffects = function (thisExecution, executionContext) { | ||
var _this = this; | ||
var context = this.context; | ||
var effects = this.effects; | ||
if (IS_DEVELOPMENT) { | ||
context = Object.keys(this.context).reduce(function (currentContext, key) { | ||
effects = Object.keys(this.effects).reduce(function (currentEffects, key) { | ||
if (_this.options.providerExceptions.indexOf(key) === -1 && | ||
isObject(_this.context[key])) { | ||
currentContext[key] = new Proxy(_this.context[key], { | ||
isObject(_this.effects[key])) { | ||
currentEffects[key] = new Proxy(_this.effects[key], { | ||
get: _this.createGetHandler(thisExecution, key), | ||
@@ -61,8 +61,8 @@ }); | ||
else { | ||
currentContext[key] = _this.context[key]; | ||
currentEffects[key] = _this.effects[key]; | ||
} | ||
return currentContext; | ||
return currentEffects; | ||
}, {}); | ||
} | ||
return Object.assign({}, context, executionContext); | ||
return Object.assign({}, effects, executionContext); | ||
}; | ||
@@ -69,0 +69,0 @@ return ActionChain; |
@@ -90,3 +90,3 @@ import * as tslib_1 from "tslib"; | ||
describe('PROVIDER', function () { | ||
test('should track execution of providers', function () { | ||
test('should track execution of effects', function () { | ||
expect.assertions(2); | ||
@@ -110,3 +110,3 @@ var fn = action().test(function (_a) { | ||
}); | ||
test('should track execution of namespaced providers', function () { | ||
test('should track execution of namespaced effects', function () { | ||
expect.assertions(2); | ||
@@ -130,3 +130,3 @@ var fn = action().test(function (_a) { | ||
}); | ||
test('should track execution of class instance providers', function () { | ||
test('should track execution of class instance effects', function () { | ||
expect.assertions(2); | ||
@@ -133,0 +133,0 @@ var fn = action().test(function (_a) { |
@@ -6,13 +6,14 @@ import { ActionChain, Execution } from './ActionChain'; | ||
} | ||
export declare class ActionBase<Context, InitialValue, Value = InitialValue> { | ||
export declare class ActionBase<Effects> { | ||
private actionChain; | ||
private initialActionId; | ||
private runOperators?; | ||
static nextActionId: number; | ||
private initialActionId; | ||
private actionChain; | ||
private runOperators; | ||
constructor(actionChain: ActionChain<Context>, initialActionId?: number, runOperators?: (value: any, executionContext: { | ||
private currentExecutionId; | ||
constructor(actionChain: ActionChain<Effects>, initialActionId?: number, runOperators?: (value: any, executionContext: { | ||
__execution: Execution; | ||
__path: string[]; | ||
}, newPath?: string) => any | Promise<any>); | ||
getActionChain: () => ActionChain<Context>; | ||
createOperatorResult: (type: string, name: string, cb: any) => [ActionChain<Context>, number, any]; | ||
getActionChain: () => ActionChain<Effects>; | ||
createOperatorResult: (type: string, name: string, cb: any) => [ActionChain<Effects>, number, any]; | ||
} |
@@ -15,2 +15,6 @@ "use strict"; | ||
var _this = this; | ||
this.actionChain = actionChain; | ||
this.initialActionId = initialActionId; | ||
this.runOperators = runOperators; | ||
this.currentExecutionId = 0; | ||
this.getActionChain = function () { | ||
@@ -40,7 +44,7 @@ return _this.actionChain; | ||
var path = executionContextWithPath.__path; | ||
var context = _this.actionChain.getContext(thisExecution, executionContextWithPath); | ||
var effects = _this.actionChain.getEffects(thisExecution, executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
name: name, | ||
path: path }, thisExecution)); | ||
var result = cb(context, currentValue); | ||
var result = cb(effects, currentValue); | ||
if (result instanceof Promise) { | ||
@@ -69,7 +73,3 @@ _this.actionChain.emit('operator:async', tslib_1.__assign({ type: type, | ||
}; | ||
this.actionChain = actionChain; | ||
this.runOperators = runOperators; | ||
this.initialActionId = initialActionId; | ||
var currentExecutionId = 0; | ||
var func = Object.assign(function (value) { | ||
var instance = Object.assign(function (value) { | ||
var initialOperator = typeof arguments[1] === 'undefined'; | ||
@@ -82,3 +82,3 @@ var newPath = typeof arguments[2] === 'undefined' ? null : arguments[2]; | ||
actionId: initialActionId, | ||
executionId: currentExecutionId++, | ||
executionId: instance.currentExecutionId++, | ||
}, | ||
@@ -92,3 +92,3 @@ __path: [], | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
value: value, | ||
@@ -105,3 +105,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
}); | ||
@@ -114,3 +114,3 @@ }); | ||
executionId: executionContext.__execution.executionId, | ||
actionName: func.displayName, | ||
actionName: instance.displayName, | ||
}); | ||
@@ -120,3 +120,3 @@ } | ||
}, this); | ||
return func; | ||
return instance; | ||
} | ||
@@ -123,0 +123,0 @@ ActionBase.nextActionId = 0; |
@@ -51,8 +51,8 @@ import { EventEmitter } from 'betsy'; | ||
} | ||
export declare class ActionChain<Context> extends EventEmitter<ActionChainEvents> { | ||
private context; | ||
export declare class ActionChain<Effects> extends EventEmitter<ActionChainEvents> { | ||
private effects; | ||
private options; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
constructor(effects: Effects, options?: ActionChainOptions); | ||
private createGetHandler; | ||
getContext(thisExecution: Execution, executionContext: ExecutionContext): Context & ExecutionContext; | ||
getEffects(thisExecution: Execution, executionContext: ExecutionContext): Effects & ExecutionContext; | ||
} |
@@ -11,6 +11,6 @@ "use strict"; | ||
tslib_1.__extends(ActionChain, _super); | ||
function ActionChain(context, options) { | ||
function ActionChain(effects, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.context = context; | ||
_this.effects = effects; | ||
_this.options = options; | ||
@@ -50,10 +50,10 @@ _this.options.providerExceptions = options.providerExceptions || []; | ||
}; | ||
ActionChain.prototype.getContext = function (thisExecution, executionContext) { | ||
ActionChain.prototype.getEffects = function (thisExecution, executionContext) { | ||
var _this = this; | ||
var context = this.context; | ||
var effects = this.effects; | ||
if (IS_DEVELOPMENT) { | ||
context = Object.keys(this.context).reduce(function (currentContext, key) { | ||
effects = Object.keys(this.effects).reduce(function (currentEffects, key) { | ||
if (_this.options.providerExceptions.indexOf(key) === -1 && | ||
isObject(_this.context[key])) { | ||
currentContext[key] = new Proxy(_this.context[key], { | ||
isObject(_this.effects[key])) { | ||
currentEffects[key] = new Proxy(_this.effects[key], { | ||
get: _this.createGetHandler(thisExecution, key), | ||
@@ -63,8 +63,8 @@ }); | ||
else { | ||
currentContext[key] = _this.context[key]; | ||
currentEffects[key] = _this.effects[key]; | ||
} | ||
return currentContext; | ||
return currentEffects; | ||
}, {}); | ||
} | ||
return Object.assign({}, context, executionContext); | ||
return Object.assign({}, effects, executionContext); | ||
}; | ||
@@ -71,0 +71,0 @@ return ActionChain; |
@@ -92,3 +92,3 @@ "use strict"; | ||
describe('PROVIDER', function () { | ||
test('should track execution of providers', function () { | ||
test('should track execution of effects', function () { | ||
expect.assertions(2); | ||
@@ -112,3 +112,3 @@ var fn = action().test(function (_a) { | ||
}); | ||
test('should track execution of namespaced providers', function () { | ||
test('should track execution of namespaced effects', function () { | ||
expect.assertions(2); | ||
@@ -132,3 +132,3 @@ var fn = action().test(function (_a) { | ||
}); | ||
test('should track execution of class instance providers', function () { | ||
test('should track execution of class instance effects', function () { | ||
expect.assertions(2); | ||
@@ -135,0 +135,0 @@ var fn = action().test(function (_a) { |
{ | ||
"name": "action-chain", | ||
"version": "1.0.0-1532598454955", | ||
"version": "1.0.0-1532612418339", | ||
"description": "Functional actions", | ||
@@ -34,5 +34,5 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", | ||
"tslib": "^1.9.3", | ||
"betsy": "1.0.0-1532598454955" | ||
"betsy": "1.0.0-1532612418339" | ||
}, | ||
"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
1107
108481
+ Addedbetsy@1.0.0-1532612418339(transitive)
- Removedbetsy@1.0.0-1532598454955(transitive)
Updatedbetsy@1.0.0-1532612418339