action-chain
Advanced tools
Comparing version 1.0.0-1532031987960 to 1.0.0-1532080068892
@@ -6,6 +6,2 @@ import * as EventEmitter from 'eventemitter3'; | ||
}; | ||
export interface ActionChain<Context> extends EventEmitter { | ||
getOptions(): ActionChainOptions; | ||
getContext(executionContext: ExecutionContext): Context & ExecutionContext; | ||
} | ||
export declare type ActionChainOptions = { | ||
@@ -20,2 +16,11 @@ actionWrapper?: any; | ||
}; | ||
export declare class ActionChain<Context> extends EventEmitter { | ||
private context; | ||
private options; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
getContext(executionContext: ExecutionContext): { | ||
__execution: Execution; | ||
__path: string[]; | ||
}; | ||
} | ||
export declare function actionChainFactory<Context>(context: Context, options?: ActionChainOptions): ActionChain<Context>; |
import * as tslib_1 from "tslib"; | ||
import * as EventEmitter from 'eventemitter3'; | ||
var IS_DEVELOPMENT = process.env.NODE_ENV !== 'production'; | ||
var ActionChain = /** @class */ (function (_super) { | ||
tslib_1.__extends(ActionChain, _super); | ||
function ActionChain(context, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.context = context; | ||
_this.options = options; | ||
_this.options.providerExceptions = options.providerExceptions || []; | ||
return _this; | ||
} | ||
ActionChain.prototype.getContext = function (executionContext) { | ||
var _this = this; | ||
var instance = this; | ||
var providers = Object.keys(this.context).reduce(function (currentContext, key) { | ||
if (IS_DEVELOPMENT && | ||
_this.options.providerExceptions.indexOf(key) === -1) { | ||
currentContext[key] = new Proxy(_this.context[key], { | ||
get: function (target, prop) { | ||
if (typeof target[prop] === 'function') { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var result = target[prop].apply(target, args); | ||
if (result instanceof Promise) { | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
return target[prop]; | ||
}, | ||
}); | ||
} | ||
else { | ||
currentContext[key] = _this.context[key]; | ||
} | ||
return currentContext; | ||
}, {}); | ||
return tslib_1.__assign({}, providers, executionContext); | ||
}; | ||
return ActionChain; | ||
}(EventEmitter)); | ||
export { ActionChain }; | ||
export function actionChainFactory(context, options) { | ||
if (options === void 0) { options = {}; } | ||
options.providerExceptions = options.providerExceptions || []; | ||
return Object.assign(new EventEmitter(), { | ||
getOptions: function () { | ||
return options; | ||
}, | ||
getContext: function (executionContext) { | ||
var instance = this; | ||
var providers = Object.keys(context).reduce(function (currentContext, key) { | ||
if (IS_DEVELOPMENT && options.providerExceptions.indexOf(key) === -1) { | ||
currentContext[key] = new Proxy(context[key], { | ||
get: function (target, prop) { | ||
if (typeof target[prop] === 'function') { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var result = target[prop].apply(target, args); | ||
if (result instanceof Promise) { | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
return target[prop]; | ||
}, | ||
}); | ||
} | ||
else { | ||
currentContext[key] = context[key]; | ||
} | ||
return currentContext; | ||
}, {}); | ||
return Object.assign({}, providers, executionContext); | ||
}, | ||
}); | ||
return new ActionChain(context, options); | ||
} | ||
//# sourceMappingURL=ActionChain.js.map |
export { actionBaseFactory, StopExecution, } from './ActionBase'; | ||
export { actionChainFactory, } from './ActionChain'; | ||
export { actionChainFactory, ActionChain, } from './ActionChain'; | ||
//# sourceMappingURL=index.js.map |
@@ -62,7 +62,7 @@ import { actionChainFactory, actionBaseFactory, } from './'; | ||
expect.assertions(1); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var foo = _a.foo; | ||
expect(foo.bar()).toBe('baz'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -73,3 +73,3 @@ }); | ||
expect.assertions(2); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var foo = _a.foo; | ||
@@ -88,7 +88,7 @@ expect(foo.bar()).toBe('baz'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
test('should track execution of clas instance providers', function () { | ||
expect.assertions(2); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var test = _a.test; | ||
@@ -107,3 +107,3 @@ expect(test.foo()).toBe('bar'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -114,3 +114,3 @@ }); | ||
expect.assertions(4); | ||
var foo = action().test(function () { return 'foo'; }); | ||
var fn = action().test(function () { return 'foo'; }); | ||
actionChain.once('action:start', function (data) { | ||
@@ -150,3 +150,3 @@ expect(data).toEqual({ | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -153,0 +153,0 @@ test('should track async execution', function () { |
@@ -6,6 +6,2 @@ import * as EventEmitter from 'eventemitter3'; | ||
}; | ||
export interface ActionChain<Context> extends EventEmitter { | ||
getOptions(): ActionChainOptions; | ||
getContext(executionContext: ExecutionContext): Context & ExecutionContext; | ||
} | ||
export declare type ActionChainOptions = { | ||
@@ -20,2 +16,11 @@ actionWrapper?: any; | ||
}; | ||
export declare class ActionChain<Context> extends EventEmitter { | ||
private context; | ||
private options; | ||
constructor(context: Context, options?: ActionChainOptions); | ||
getContext(executionContext: ExecutionContext): { | ||
__execution: Execution; | ||
__path: string[]; | ||
}; | ||
} | ||
export declare function actionChainFactory<Context>(context: Context, options?: ActionChainOptions): ActionChain<Context>; |
@@ -6,47 +6,57 @@ "use strict"; | ||
var IS_DEVELOPMENT = process.env.NODE_ENV !== 'production'; | ||
var ActionChain = /** @class */ (function (_super) { | ||
tslib_1.__extends(ActionChain, _super); | ||
function ActionChain(context, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.context = context; | ||
_this.options = options; | ||
_this.options.providerExceptions = options.providerExceptions || []; | ||
return _this; | ||
} | ||
ActionChain.prototype.getContext = function (executionContext) { | ||
var _this = this; | ||
var instance = this; | ||
var providers = Object.keys(this.context).reduce(function (currentContext, key) { | ||
if (IS_DEVELOPMENT && | ||
_this.options.providerExceptions.indexOf(key) === -1) { | ||
currentContext[key] = new Proxy(_this.context[key], { | ||
get: function (target, prop) { | ||
if (typeof target[prop] === 'function') { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var result = target[prop].apply(target, args); | ||
if (result instanceof Promise) { | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
return target[prop]; | ||
}, | ||
}); | ||
} | ||
else { | ||
currentContext[key] = _this.context[key]; | ||
} | ||
return currentContext; | ||
}, {}); | ||
return tslib_1.__assign({}, providers, executionContext); | ||
}; | ||
return ActionChain; | ||
}(EventEmitter)); | ||
exports.ActionChain = ActionChain; | ||
function actionChainFactory(context, options) { | ||
if (options === void 0) { options = {}; } | ||
options.providerExceptions = options.providerExceptions || []; | ||
return Object.assign(new EventEmitter(), { | ||
getOptions: function () { | ||
return options; | ||
}, | ||
getContext: function (executionContext) { | ||
var instance = this; | ||
var providers = Object.keys(context).reduce(function (currentContext, key) { | ||
if (IS_DEVELOPMENT && options.providerExceptions.indexOf(key) === -1) { | ||
currentContext[key] = new Proxy(context[key], { | ||
get: function (target, prop) { | ||
if (typeof target[prop] === 'function') { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var result = target[prop].apply(target, args); | ||
if (result instanceof Promise) { | ||
result.then(function (promisedResult) { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
instance.emit('provider', tslib_1.__assign({}, executionContext.__execution, { name: key, method: prop, result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
return target[prop]; | ||
}, | ||
}); | ||
} | ||
else { | ||
currentContext[key] = context[key]; | ||
} | ||
return currentContext; | ||
}, {}); | ||
return Object.assign({}, providers, executionContext); | ||
}, | ||
}); | ||
return new ActionChain(context, options); | ||
} | ||
exports.actionChainFactory = actionChainFactory; | ||
//# sourceMappingURL=ActionChain.js.map |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.actionChainFactory = ActionChain_1.actionChainFactory; | ||
exports.ActionChain = ActionChain_1.ActionChain; | ||
//# sourceMappingURL=index.js.map |
@@ -64,7 +64,7 @@ "use strict"; | ||
expect.assertions(1); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var foo = _a.foo; | ||
expect(foo.bar()).toBe('baz'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -75,3 +75,3 @@ }); | ||
expect.assertions(2); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var foo = _a.foo; | ||
@@ -90,7 +90,7 @@ expect(foo.bar()).toBe('baz'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
test('should track execution of clas instance providers', function () { | ||
expect.assertions(2); | ||
var foo = action().test(function (_, _a) { | ||
var fn = action().test(function (_, _a) { | ||
var test = _a.test; | ||
@@ -109,3 +109,3 @@ expect(test.foo()).toBe('bar'); | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -116,3 +116,3 @@ }); | ||
expect.assertions(4); | ||
var foo = action().test(function () { return 'foo'; }); | ||
var fn = action().test(function () { return 'foo'; }); | ||
actionChain.once('action:start', function (data) { | ||
@@ -152,3 +152,3 @@ expect(data).toEqual({ | ||
}); | ||
foo(); | ||
fn(); | ||
}); | ||
@@ -155,0 +155,0 @@ test('should track async execution', function () { |
{ | ||
"name": "action-chain", | ||
"version": "1.0.0-1532031987960", | ||
"version": "1.0.0-1532080068892", | ||
"description": "Functional actions", | ||
@@ -5,0 +5,0 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", |
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
100198
924