action-chain
Advanced tools
Comparing version 1.0.0-1535290136519 to 1.0.0-1535310223782
@@ -1,2 +0,3 @@ | ||
import { ActionChain, ExecutionContext } from './ActionChain'; | ||
import { ActionChain } from './ActionChain'; | ||
import { ExecutionContext } from './types'; | ||
export declare class StopExecution { | ||
@@ -3,0 +4,0 @@ value: any; |
@@ -38,3 +38,3 @@ import * as tslib_1 from "tslib"; | ||
var path = executionContextWithPath.__path; | ||
var effects = _this.actionChain.getEffects(thisExecution, executionContextWithPath); | ||
var effects = Object.assign({}, _this.actionChain.getEffects(thisExecution), executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
@@ -41,0 +41,0 @@ name: name, |
import { EventEmitter } from 'betsy'; | ||
export declare type Execution = { | ||
operatorId: number; | ||
actionId: number; | ||
executionId: number; | ||
}; | ||
export declare type ExecutionContext = { | ||
__execution: Execution; | ||
__path: string[]; | ||
}; | ||
export declare type ActionExecution = { | ||
actionId: number; | ||
executionId: number; | ||
actionName: string; | ||
value?: any; | ||
}; | ||
declare type OperatorExecution = { | ||
actionId: number; | ||
executionId: number; | ||
operatorId: number; | ||
type: string; | ||
name: string; | ||
path: string; | ||
}; | ||
interface ActionChainEvents { | ||
effect: Execution & { | ||
name: string; | ||
method: string | number | symbol; | ||
result: any; | ||
args: any[]; | ||
}; | ||
'action:start': ActionExecution; | ||
'action:end': ActionExecution; | ||
'operator:start': OperatorExecution; | ||
'operator:async': OperatorExecution & { | ||
isAsync: boolean; | ||
}; | ||
'operator:end': OperatorExecution & { | ||
isAsync: boolean; | ||
result: any; | ||
}; | ||
} | ||
import { ActionChainEvents, Execution } from './types'; | ||
export declare class ActionChain<Effects, ExtraEvents = {}> extends EventEmitter<ActionChainEvents & ExtraEvents> { | ||
@@ -49,5 +9,3 @@ private effects; | ||
}); | ||
private createGetHandler; | ||
getEffects(thisExecution: Execution, executionContext: ExecutionContext): Effects & ExecutionContext; | ||
getEffects(thisExecution: Execution): Effects; | ||
} | ||
export {}; |
import * as tslib_1 from "tslib"; | ||
import { EventEmitter } from 'betsy'; | ||
import { proxifyEffects } from './utils'; | ||
var IS_DEVELOPMENT = process.env.NODE_ENV !== 'production'; | ||
function isObject(value) { | ||
return typeof value === 'object' && !Array.isArray(value) && value !== null; | ||
} | ||
var ActionChain = /** @class */ (function (_super) { | ||
@@ -14,53 +12,10 @@ tslib_1.__extends(ActionChain, _super); | ||
_this.options = options; | ||
_this.options.providerExceptions = options.providerExceptions || []; | ||
return _this; | ||
} | ||
ActionChain.prototype.createGetHandler = function (execution, path) { | ||
ActionChain.prototype.getEffects = function (thisExecution) { | ||
var _this = this; | ||
return 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) { | ||
_this.emitAsync('effect', tslib_1.__assign({}, execution, { name: path, method: prop, args: args, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
_this.emitAsync('effect', tslib_1.__assign({}, execution, { name: path, method: prop, args: args, | ||
result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
else if (isObject(target[prop])) { | ||
return new Proxy(target[prop], { | ||
get: _this.createGetHandler(execution, path + '.' + prop), | ||
}); | ||
} | ||
return target[prop]; | ||
}; | ||
}; | ||
ActionChain.prototype.getEffects = function (thisExecution, executionContext) { | ||
var _this = this; | ||
var effects = this.effects; | ||
if (IS_DEVELOPMENT) { | ||
effects = Object.keys(this.effects).reduce(function (currentEffects, key) { | ||
if (_this.options.providerExceptions.indexOf(key) === -1 && | ||
isObject(_this.effects[key])) { | ||
currentEffects[key] = new Proxy(_this.effects[key], { | ||
get: _this.createGetHandler(thisExecution, key), | ||
}); | ||
} | ||
else { | ||
currentEffects[key] = _this.effects[key]; | ||
} | ||
return currentEffects; | ||
}, {}); | ||
return proxifyEffects(this.effects, this.options.providerExceptions, function (effect) { return _this.emitAsync('effect', tslib_1.__assign({}, thisExecution, effect)); }); | ||
} | ||
return Object.assign({}, effects, executionContext); | ||
return this.effects; | ||
}; | ||
@@ -67,0 +22,0 @@ return ActionChain; |
export { ActionBase, StopExecution } from './ActionBase'; | ||
export { ActionChain, ActionExecution, Execution, ExecutionContext, } from './ActionChain'; | ||
export { ActionChain } from './ActionChain'; | ||
export { ActionExecution, Execution, ExecutionContext } from './types'; | ||
export { doNotProxy } from './utils'; |
export { ActionBase, StopExecution } from './ActionBase'; | ||
export { ActionChain, } from './ActionChain'; | ||
export { ActionChain } from './ActionChain'; | ||
export { doNotProxy } from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,3 @@ | ||
import { ActionChain, ExecutionContext } from './ActionChain'; | ||
import { ActionChain } from './ActionChain'; | ||
import { ExecutionContext } from './types'; | ||
export declare class StopExecution { | ||
@@ -3,0 +4,0 @@ value: any; |
@@ -40,3 +40,3 @@ "use strict"; | ||
var path = executionContextWithPath.__path; | ||
var effects = _this.actionChain.getEffects(thisExecution, executionContextWithPath); | ||
var effects = Object.assign({}, _this.actionChain.getEffects(thisExecution), executionContextWithPath); | ||
_this.actionChain.emit('operator:start', tslib_1.__assign({ type: type, | ||
@@ -43,0 +43,0 @@ name: name, |
import { EventEmitter } from 'betsy'; | ||
export declare type Execution = { | ||
operatorId: number; | ||
actionId: number; | ||
executionId: number; | ||
}; | ||
export declare type ExecutionContext = { | ||
__execution: Execution; | ||
__path: string[]; | ||
}; | ||
export declare type ActionExecution = { | ||
actionId: number; | ||
executionId: number; | ||
actionName: string; | ||
value?: any; | ||
}; | ||
declare type OperatorExecution = { | ||
actionId: number; | ||
executionId: number; | ||
operatorId: number; | ||
type: string; | ||
name: string; | ||
path: string; | ||
}; | ||
interface ActionChainEvents { | ||
effect: Execution & { | ||
name: string; | ||
method: string | number | symbol; | ||
result: any; | ||
args: any[]; | ||
}; | ||
'action:start': ActionExecution; | ||
'action:end': ActionExecution; | ||
'operator:start': OperatorExecution; | ||
'operator:async': OperatorExecution & { | ||
isAsync: boolean; | ||
}; | ||
'operator:end': OperatorExecution & { | ||
isAsync: boolean; | ||
result: any; | ||
}; | ||
} | ||
import { ActionChainEvents, Execution } from './types'; | ||
export declare class ActionChain<Effects, ExtraEvents = {}> extends EventEmitter<ActionChainEvents & ExtraEvents> { | ||
@@ -49,5 +9,3 @@ private effects; | ||
}); | ||
private createGetHandler; | ||
getEffects(thisExecution: Execution, executionContext: ExecutionContext): Effects & ExecutionContext; | ||
getEffects(thisExecution: Execution): Effects; | ||
} | ||
export {}; |
@@ -5,6 +5,4 @@ "use strict"; | ||
var betsy_1 = require("betsy"); | ||
var utils_1 = require("./utils"); | ||
var IS_DEVELOPMENT = process.env.NODE_ENV !== 'production'; | ||
function isObject(value) { | ||
return typeof value === 'object' && !Array.isArray(value) && value !== null; | ||
} | ||
var ActionChain = /** @class */ (function (_super) { | ||
@@ -17,53 +15,10 @@ tslib_1.__extends(ActionChain, _super); | ||
_this.options = options; | ||
_this.options.providerExceptions = options.providerExceptions || []; | ||
return _this; | ||
} | ||
ActionChain.prototype.createGetHandler = function (execution, path) { | ||
ActionChain.prototype.getEffects = function (thisExecution) { | ||
var _this = this; | ||
return 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) { | ||
_this.emitAsync('effect', tslib_1.__assign({}, execution, { name: path, method: prop, args: args, result: promisedResult })); | ||
}); | ||
} | ||
else { | ||
_this.emitAsync('effect', tslib_1.__assign({}, execution, { name: path, method: prop, args: args, | ||
result: result })); | ||
} | ||
return result; | ||
}; | ||
} | ||
else if (isObject(target[prop])) { | ||
return new Proxy(target[prop], { | ||
get: _this.createGetHandler(execution, path + '.' + prop), | ||
}); | ||
} | ||
return target[prop]; | ||
}; | ||
}; | ||
ActionChain.prototype.getEffects = function (thisExecution, executionContext) { | ||
var _this = this; | ||
var effects = this.effects; | ||
if (IS_DEVELOPMENT) { | ||
effects = Object.keys(this.effects).reduce(function (currentEffects, key) { | ||
if (_this.options.providerExceptions.indexOf(key) === -1 && | ||
isObject(_this.effects[key])) { | ||
currentEffects[key] = new Proxy(_this.effects[key], { | ||
get: _this.createGetHandler(thisExecution, key), | ||
}); | ||
} | ||
else { | ||
currentEffects[key] = _this.effects[key]; | ||
} | ||
return currentEffects; | ||
}, {}); | ||
return utils_1.proxifyEffects(this.effects, this.options.providerExceptions, function (effect) { return _this.emitAsync('effect', tslib_1.__assign({}, thisExecution, effect)); }); | ||
} | ||
return Object.assign({}, effects, executionContext); | ||
return this.effects; | ||
}; | ||
@@ -70,0 +25,0 @@ return ActionChain; |
export { ActionBase, StopExecution } from './ActionBase'; | ||
export { ActionChain, ActionExecution, Execution, ExecutionContext, } from './ActionChain'; | ||
export { ActionChain } from './ActionChain'; | ||
export { ActionExecution, Execution, ExecutionContext } from './types'; | ||
export { doNotProxy } from './utils'; |
@@ -8,2 +8,4 @@ "use strict"; | ||
exports.ActionChain = ActionChain_1.ActionChain; | ||
var utils_1 = require("./utils"); | ||
exports.doNotProxy = utils_1.doNotProxy; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "action-chain", | ||
"version": "1.0.0-1535290136519", | ||
"version": "1.0.0-1535310223782", | ||
"description": "Functional actions", | ||
@@ -34,5 +34,5 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", | ||
"tslib": "^1.9.3", | ||
"betsy": "1.0.0-1535290136520" | ||
"betsy": "1.0.0-1535310223782" | ||
}, | ||
"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
111357
38
1143
+ Addedbetsy@1.0.0-1535310223782(transitive)
- Removedbetsy@1.0.0-1535290136520(transitive)
Updatedbetsy@1.0.0-1535310223782