function-tree
Advanced tools
Comparing version 3.2.0-1521141520687 to 3.2.0-1521491486243
@@ -27,3 +27,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
_this.latestExecutionId = null; | ||
_this.version = "3.2.0-1521141520687"; | ||
_this.version = "3.2.0-1521491486243"; | ||
_this.init(); | ||
@@ -30,0 +30,0 @@ return _this; |
@@ -11,3 +11,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
import { parallel as _parallel } from "../../"; | ||
import { parallel as _parallel } from '../../'; | ||
import { debounce as _debounce, wait as _wait } from '../../factories/'; | ||
@@ -23,3 +23,3 @@ | ||
_createClass(SequenceBuilder, [{ | ||
key: "action", | ||
key: 'action', | ||
value: function action() { | ||
@@ -32,6 +32,6 @@ var _sequenceArray; | ||
var typeFirst = typeof _action[0] === "string"; | ||
var typeFirst = typeof _action[0] === 'string'; | ||
var actions = typeFirst ? _action.splice(1) : _action; | ||
actions.forEach(function (element) { | ||
typeFirst && Object.defineProperty(element, "name", { value: _action[0] }); | ||
typeFirst && Object.defineProperty(element, 'name', { value: _action[0] }); | ||
}); | ||
@@ -42,3 +42,3 @@ (_sequenceArray = this.sequenceArray).push.apply(_sequenceArray, _toConsumableArray(actions)); | ||
}, { | ||
key: "branch", | ||
key: 'branch', | ||
value: function branch(action) { | ||
@@ -57,7 +57,7 @@ var _this = this; | ||
}, { | ||
key: "parallel", | ||
key: 'parallel', | ||
value: function parallel() { | ||
var cb = new SequenceBuilder([]); | ||
var callback = typeof (arguments.length <= 0 ? undefined : arguments[0]) == "string" ? arguments.length <= 1 ? undefined : arguments[1] : arguments.length <= 0 ? undefined : arguments[0]; | ||
var name = typeof (arguments.length <= 0 ? undefined : arguments[0]) == "string" ? arguments.length <= 0 ? undefined : arguments[0] : ""; | ||
var callback = typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string' ? arguments.length <= 1 ? undefined : arguments[1] : arguments.length <= 0 ? undefined : arguments[0]; | ||
var name = typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string' ? arguments.length <= 0 ? undefined : arguments[0] : ''; | ||
var result = callback(cb); | ||
@@ -68,3 +68,3 @@ this.sequenceArray.push(_parallel(name, result.sequenceArray)); | ||
}, { | ||
key: "sequence", | ||
key: 'sequence', | ||
value: function sequence(seq) { | ||
@@ -77,3 +77,3 @@ var _sequenceArray2; | ||
}, { | ||
key: "when", | ||
key: 'when', | ||
value: function when(callback) { | ||
@@ -86,3 +86,3 @@ function when(context) { | ||
}, { | ||
key: "debounce", | ||
key: 'debounce', | ||
value: function debounce(ms) { | ||
@@ -92,3 +92,3 @@ return this.branch(_debounce(ms)); | ||
}, { | ||
key: "equals", | ||
key: 'equals', | ||
value: function equals(callback) { | ||
@@ -102,3 +102,3 @@ function equals(context) { | ||
}, { | ||
key: "wait", | ||
key: 'wait', | ||
value: function wait(ms) { | ||
@@ -125,3 +125,3 @@ this.sequenceArray.push(_wait(ms)); | ||
_createClass(ContinueSequenceBuilder, [{ | ||
key: "continue", | ||
key: 'continue', | ||
value: function _continue(arg) { | ||
@@ -128,0 +128,0 @@ var builder = new SequenceBuilder([]); |
@@ -1,50 +0,126 @@ | ||
import { Primitive } from "../"; | ||
import { Primitive } from '../' | ||
export interface IContext<TProps> { | ||
props: TProps; | ||
props: TProps | ||
} | ||
export interface IBranchContext<TPaths, TProps> extends IContext<TProps> { | ||
path: { | ||
[key in keyof TPaths]: (props: TPaths[key]) => TPaths[key]; | ||
}; | ||
path: { [key in keyof TPaths]: (props: TPaths[key]) => TPaths[key] } | ||
} | ||
export declare class SequenceBuilder<TContext = {}, TProps = {}, TState = {}> { | ||
private sequenceArray; | ||
constructor(sequenceArray: any[]); | ||
action<TOutput>(...action: ((props: TContext & IContext<TProps>) => TOutput | Promise<TOutput>)[]): SequenceBuilder<TContext, TProps & TOutput>; | ||
action<TOutput>(name: string, ...action: ((props: TContext & IContext<TProps>) => TOutput | Promise<TOutput>)[]): SequenceBuilder<TContext, TProps & TOutput>; | ||
branch<TPaths, TOutput = {}>(action: ((props: TContext & IBranchContext<TPaths, TProps>) => TOutput | Promise<TOutput>)): { | ||
paths: (paths: { | ||
[key in keyof TPaths]: (props: SequenceBuilder<TContext, TProps & TPaths[key]>) => SequenceBuilder<TContext, TProps & TPaths[key]>; | ||
}) => SequenceBuilder<TContext, TProps & TOutput>; | ||
}; | ||
parallel<TOutput>(name: string, chain: ((props: SequenceBuilder<TContext, TProps>) => SequenceBuilder<TContext, TOutput>)): SequenceBuilder<TContext, TProps & TOutput>; | ||
parallel<TOutput>(chain: ((props: SequenceBuilder<TContext, TProps>) => SequenceBuilder<TContext, TOutput>)): SequenceBuilder<TContext, TProps & TOutput>; | ||
sequence<TOutput = void>(seq: (props: TProps) => TOutput | (() => TOutput)): SequenceBuilder<TContext, TProps & TOutput>; | ||
when<TPaths extends { true: {}, false: {} }>(callback: (input: TContext & IBranchContext<TPaths, TProps>) => boolean): { | ||
paths: (paths: {[key in keyof TPaths]: (input: SequenceBuilder<TContext, TProps & TPaths[key]>) => SequenceBuilder<TContext, TProps & TPaths[key]>; }) => SequenceBuilder<TContext, TProps>; | ||
}; | ||
debounce<TPaths extends { continue: {}; discard: {}; }>(ms: number): { | ||
paths: (paths: {[key in keyof TPaths]: (input: SequenceBuilder<TContext, TProps & TPaths[key]>) => SequenceBuilder<TContext, TProps & TPaths[key]>; }) => SequenceBuilder<TContext, TProps>; | ||
}; | ||
equals<TPaths extends { [key: string]: {}; }, TValue>(callback: (input: TContext & IBranchContext<TPaths, TProps>) => TValue): { | ||
paths: (paths: {[key in keyof TPaths]: (input: SequenceBuilder<TContext, TProps & TPaths[key]>) => SequenceBuilder<TContext, TProps & TPaths[key]>; }) => SequenceBuilder<TContext, TProps>; | ||
}; | ||
wait(ms: number): ContinueSequenceBuilder<TContext, TProps>; | ||
private sequenceArray | ||
constructor(sequenceArray: any[]) | ||
action<TOutput>( | ||
...action: (( | ||
props: TContext & IContext<TProps> | ||
) => TOutput | Promise<TOutput>)[] | ||
): SequenceBuilder<TContext, TProps & TOutput> | ||
action<TOutput>( | ||
name: string, | ||
...action: (( | ||
props: TContext & IContext<TProps> | ||
) => TOutput | Promise<TOutput>)[] | ||
): SequenceBuilder<TContext, TProps & TOutput> | ||
branch<TPaths, TOutput = {}>( | ||
action: (( | ||
props: TContext & IBranchContext<TPaths, TProps> | ||
) => TOutput | Promise<TOutput>) | ||
): { | ||
paths: ( | ||
paths: { | ||
[key in keyof TPaths]: ( | ||
props: SequenceBuilder<TContext, TProps & TPaths[key]> | ||
) => SequenceBuilder<TContext, TProps & TPaths[key]> | ||
} | ||
) => SequenceBuilder<TContext, TProps & TOutput> | ||
} | ||
parallel<TOutput>( | ||
name: string, | ||
chain: (( | ||
props: SequenceBuilder<TContext, TProps> | ||
) => SequenceBuilder<TContext, TOutput>) | ||
): SequenceBuilder<TContext, TProps & TOutput> | ||
parallel<TOutput>( | ||
chain: (( | ||
props: SequenceBuilder<TContext, TProps> | ||
) => SequenceBuilder<TContext, TOutput>) | ||
): SequenceBuilder<TContext, TProps & TOutput> | ||
sequence<TOutput = void>( | ||
seq: (props: TProps) => TOutput | (() => TOutput) | ||
): SequenceBuilder<TContext, TProps & TOutput> | ||
when<TPaths extends { true: {}; false: {} }>( | ||
callback: (input: TContext & IBranchContext<TPaths, TProps>) => boolean | ||
): { | ||
paths: ( | ||
paths: { | ||
[key in keyof TPaths]: ( | ||
input: SequenceBuilder<TContext, TProps & TPaths[key]> | ||
) => SequenceBuilder<TContext, TProps & TPaths[key]> | ||
} | ||
) => SequenceBuilder<TContext, TProps> | ||
} | ||
debounce<TPaths extends { continue: {}; discard: {} }>( | ||
ms: number | ||
): { | ||
paths: ( | ||
paths: { | ||
[key in keyof TPaths]: ( | ||
input: SequenceBuilder<TContext, TProps & TPaths[key]> | ||
) => SequenceBuilder<TContext, TProps & TPaths[key]> | ||
} | ||
) => SequenceBuilder<TContext, TProps> | ||
} | ||
equals<TPaths extends { [key: string]: {} }, TValue>( | ||
callback: (input: TContext & IBranchContext<TPaths, TProps>) => TValue | ||
): { | ||
paths: ( | ||
paths: { | ||
[key in keyof TPaths]: ( | ||
input: SequenceBuilder<TContext, TProps & TPaths[key]> | ||
) => SequenceBuilder<TContext, TProps & TPaths[key]> | ||
} | ||
) => SequenceBuilder<TContext, TProps> | ||
} | ||
wait(ms: number): ContinueSequenceBuilder<TContext, TProps> | ||
} | ||
export declare class ContinueSequenceBuilder<TContext = {}, TProps = {}> extends SequenceBuilder<TContext, TProps> { | ||
continue(arg: (builder: SequenceBuilder<TContext, TProps>) => SequenceBuilder<TContext, TProps>): SequenceBuilder<TContext, TProps>; | ||
export declare class ContinueSequenceBuilder< | ||
TContext = {}, | ||
TProps = {} | ||
> extends SequenceBuilder<TContext, TProps> { | ||
continue( | ||
arg: ( | ||
builder: SequenceBuilder<TContext, TProps> | ||
) => SequenceBuilder<TContext, TProps> | ||
): SequenceBuilder<TContext, TProps> | ||
} | ||
export declare function sequenceFactory<TContext, TProps>(arg: (props: SequenceBuilder<TContext, TProps>) => SequenceBuilder<TContext, TProps>): Primitive; | ||
export declare function sequenceFactory<TContext, TProps>( | ||
arg: ( | ||
props: SequenceBuilder<TContext, TProps> | ||
) => SequenceBuilder<TContext, TProps> | ||
): Primitive | ||
export declare function Sequence<Context, Output = {}>(arg: (props: SequenceBuilder<Context, {}>) => SequenceBuilder<Context, Output>): () => Output; | ||
export declare function Sequence<Context, Output = {}>( | ||
arg: (props: SequenceBuilder<Context, {}>) => SequenceBuilder<Context, Output> | ||
): () => Output | ||
export declare function SequenceWithProps<Context, Props, Output = Props>(arg: (props: SequenceBuilder<Context, Props>) => SequenceBuilder<Context, Output>): (props: Props) => Output; | ||
export declare function SequenceWithProps<Context, Props, Output = Props>( | ||
arg: ( | ||
props: SequenceBuilder<Context, Props> | ||
) => SequenceBuilder<Context, Output> | ||
): (props: Props) => Output | ||
export declare function SequenceFactory<Context>(): <Output = {}>(arg: (props: SequenceBuilder<Context, {}>) => SequenceBuilder<Context, Output>) => () => Output; | ||
export declare function SequenceFactory<Context>(): <Output = {}>( | ||
arg: (props: SequenceBuilder<Context, {}>) => SequenceBuilder<Context, Output> | ||
) => () => Output | ||
export declare function SequenceWithPropsFactory<Context>(): <Props, Output = Props>(arg: (props: SequenceBuilder<Context, Props>) => SequenceBuilder<Context, Output>) => (props: Props) => Output; | ||
export declare function SequenceWithPropsFactory<Context>(): < | ||
Props, | ||
Output = Props | ||
>( | ||
arg: ( | ||
props: SequenceBuilder<Context, Props> | ||
) => SequenceBuilder<Context, Output> | ||
) => (props: Props) => Output |
@@ -8,3 +8,3 @@ import { EventEmitter } from 'eventemitter3' | ||
items: Array<Primitive> | ||
type: "parallel" | "sequence" | ||
type: 'parallel' | 'sequence' | ||
_functionTreePrimitive: boolean | ||
@@ -20,3 +20,7 @@ outputs?: { [name: string]: Primitive } | ||
export type TFunctionTreeExecutable = Primitive | Function | TPath | TSequenceArray | ||
export type TFunctionTreeExecutable = | ||
| Primitive | ||
| Function | ||
| TPath | ||
| TSequenceArray | ||
@@ -43,20 +47,28 @@ interface IPayload { | ||
export interface IBaseContext { | ||
[providerName: string]: any | ||
[providerName: string]: any | ||
resolve: IResolve | ||
} | ||
export interface IContext<T={}> extends IBaseContext { | ||
export interface IContext<T = {}> extends IBaseContext { | ||
props: T | ||
} | ||
type TTagFactory<T> = (path: TemplateStringsArray | string[], ...values: any[]) => Tag<T> | ||
type TTagFactory<T> = ( | ||
path: TemplateStringsArray | string[], | ||
...values: any[] | ||
) => Tag<T> | ||
export function createTemplateTag<T=any>(tagName: string, getValue: (path: string, context: IBaseContext) => T): TTagFactory<T> | ||
export function createTemplateTag<T = any>( | ||
tagName: string, | ||
getValue: (path: string, context: IBaseContext) => T | ||
): TTagFactory<T> | ||
export function extractValueWithPath<T=any>(obj: any, path: string): T | ||
export function extractValueWithPath<T = any>(obj: any, path: string): T | ||
export function resolveObject<T=any>(obj: any): ResolveValue<T> | ||
export function resolveObject<T = any>(obj: any): ResolveValue<T> | ||
export class Provider<IContext = {}> { | ||
constructor (definition: { [key: string]: (this: { context: IContext }, ...args : any[]) => void }) | ||
constructor(definition: { | ||
[key: string]: (this: { context: IContext }, ...args: any[]) => void | ||
}) | ||
} | ||
@@ -76,5 +88,5 @@ | ||
export class ResolveValue<T=any> {} | ||
export class ResolveValue<T = any> {} | ||
export class Tag<T=any> extends ResolveValue<T> { | ||
export class Tag<T = any> extends ResolveValue<T> { | ||
constructor() | ||
@@ -92,3 +104,3 @@ getPath(getters: any): string | ||
value<T>(value: ResolveValue<T>, overrideContext?: any): T | ||
value<T=any>(value: ResolveValue<T> | T, overrideContext?: any): T | ||
} | ||
value<T = any>(value: ResolveValue<T> | T, overrideContext?: any): T | ||
} |
@@ -48,3 +48,3 @@ 'use strict'; | ||
_this.latestExecutionId = null; | ||
_this.version = "3.2.0-1521141520687"; | ||
_this.version = "3.2.0-1521491486243"; | ||
_this.init(); | ||
@@ -51,0 +51,0 @@ return _this; |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -16,5 +16,5 @@ Object.defineProperty(exports, "__esModule", { | ||
var _ = require("../../"); | ||
var _ = require('../../'); | ||
var _factories = require("../../factories/"); | ||
var _factories = require('../../factories/'); | ||
@@ -37,3 +37,3 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
_createClass(SequenceBuilder, [{ | ||
key: "action", | ||
key: 'action', | ||
value: function action() { | ||
@@ -46,6 +46,6 @@ var _sequenceArray; | ||
var typeFirst = typeof _action[0] === "string"; | ||
var typeFirst = typeof _action[0] === 'string'; | ||
var actions = typeFirst ? _action.splice(1) : _action; | ||
actions.forEach(function (element) { | ||
typeFirst && Object.defineProperty(element, "name", { value: _action[0] }); | ||
typeFirst && Object.defineProperty(element, 'name', { value: _action[0] }); | ||
}); | ||
@@ -56,3 +56,3 @@ (_sequenceArray = this.sequenceArray).push.apply(_sequenceArray, _toConsumableArray(actions)); | ||
}, { | ||
key: "branch", | ||
key: 'branch', | ||
value: function branch(action) { | ||
@@ -71,7 +71,7 @@ var _this = this; | ||
}, { | ||
key: "parallel", | ||
key: 'parallel', | ||
value: function parallel() { | ||
var cb = new SequenceBuilder([]); | ||
var callback = typeof (arguments.length <= 0 ? undefined : arguments[0]) == "string" ? arguments.length <= 1 ? undefined : arguments[1] : arguments.length <= 0 ? undefined : arguments[0]; | ||
var name = typeof (arguments.length <= 0 ? undefined : arguments[0]) == "string" ? arguments.length <= 0 ? undefined : arguments[0] : ""; | ||
var callback = typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string' ? arguments.length <= 1 ? undefined : arguments[1] : arguments.length <= 0 ? undefined : arguments[0]; | ||
var name = typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string' ? arguments.length <= 0 ? undefined : arguments[0] : ''; | ||
var result = callback(cb); | ||
@@ -82,3 +82,3 @@ this.sequenceArray.push((0, _.parallel)(name, result.sequenceArray)); | ||
}, { | ||
key: "sequence", | ||
key: 'sequence', | ||
value: function sequence(seq) { | ||
@@ -91,3 +91,3 @@ var _sequenceArray2; | ||
}, { | ||
key: "when", | ||
key: 'when', | ||
value: function when(callback) { | ||
@@ -100,3 +100,3 @@ function when(context) { | ||
}, { | ||
key: "debounce", | ||
key: 'debounce', | ||
value: function debounce(ms) { | ||
@@ -106,3 +106,3 @@ return this.branch((0, _factories.debounce)(ms)); | ||
}, { | ||
key: "equals", | ||
key: 'equals', | ||
value: function equals(callback) { | ||
@@ -116,3 +116,3 @@ function equals(context) { | ||
}, { | ||
key: "wait", | ||
key: 'wait', | ||
value: function wait(ms) { | ||
@@ -139,3 +139,3 @@ this.sequenceArray.push((0, _factories.wait)(ms)); | ||
_createClass(ContinueSequenceBuilder, [{ | ||
key: "continue", | ||
key: 'continue', | ||
value: function _continue(arg) { | ||
@@ -142,0 +142,0 @@ var builder = new SequenceBuilder([]); |
{ | ||
"name": "function-tree", | ||
"version": "3.2.0-1521141520687", | ||
"version": "3.2.0-1521491486243", | ||
"description": "When a function is not enough", | ||
@@ -10,4 +10,4 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "cross-env BABEL_ENV=test mocha --compilers js:babel-register \"src/**/*.test.js\" \"__test__/**/*.test.js\"", | ||
"test:ts": "cross-env mocha --require ts-runtime.js \"src/**/*.test.ts\" \"__test__/**/*.test.ts\"", | ||
"test": "cross-env BABEL_ENV=test mocha --require babel-register \"src/**/*.test.js\"", | ||
"test:ts": "cross-env mocha --require ts-runtime.js \"src/**/*.test.ts\"", | ||
"test:watch": "npm run test -- --watch", | ||
@@ -21,3 +21,2 @@ "build:cjs": "cross-env BABEL_ENV=cjs babel src/ --out-dir=lib/ -s", | ||
"dependencies": { | ||
"@types/eventemitter3": "^1.2.0", | ||
"chalk": "^1.1.3", | ||
@@ -29,3 +28,3 @@ "eventemitter3": "^2.0.2", | ||
"@types/assert": "0.0.31", | ||
"@types/mocha": "^2.2.47", | ||
"@types/mocha": "^2.2.48", | ||
"mock-socket": "6.0.4" | ||
@@ -32,0 +31,0 @@ }, |
import { Tag } from '../' | ||
export function props<T=any>(path: TemplateStringsArray | string[], ...values: any[]): Tag<T> | ||
export function string(path: TemplateStringsArray | string[], ...values: any[]): Tag<string> | ||
export function props<T = any>( | ||
path: TemplateStringsArray | string[], | ||
...values: any[] | ||
): Tag<T> | ||
export function string( | ||
path: TemplateStringsArray | string[], | ||
...values: any[] | ||
): Tag<string> |
@@ -6,2 +6,3 @@ { | ||
"strict": true, | ||
"strictPropertyInitialization": false, | ||
"moduleResolution": "node" | ||
@@ -8,0 +9,0 @@ }, |
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
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
352579
3
3566
- Removed@types/eventemitter3@^1.2.0
- Removed@types/eventemitter3@1.2.0(transitive)