UNPKG

function-tree

Version:
145 lines 5.36 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ContinueSequenceBuilder = exports.SequenceBuilder = void 0; exports.sequenceFactory = sequenceFactory; exports.Sequence = Sequence; exports.SequenceWithProps = SequenceWithProps; exports.SequenceFactory = SequenceFactory; exports.SequenceWithPropsFactory = SequenceWithPropsFactory; var __1 = require("../../"); var factories_1 = require("../../factories/"); var SequenceBuilder = /** @class */ (function () { function SequenceBuilder(sequenceArray) { this.sequenceArray = sequenceArray; } SequenceBuilder.prototype.action = function () { var _a; var action = []; for (var _i = 0; _i < arguments.length; _i++) { action[_i] = arguments[_i]; } var typeFirst = typeof action[0] === 'string'; var actions = (typeFirst ? action.splice(1) : action); actions.forEach(function (element) { if (typeFirst) { Object.defineProperty(element, 'name', { value: action[0] }); } }); (_a = this.sequenceArray).push.apply(_a, actions); return new SequenceBuilder(this.sequenceArray); }; SequenceBuilder.prototype.branch = function (action) { var _this = this; this.sequenceArray.push(action); return { paths: function (paths) { var outputSequence = generatePathSequence(paths); _this.sequenceArray.push(outputSequence); return new SequenceBuilder(_this.sequenceArray); }, }; }; SequenceBuilder.prototype.parallel = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var result = typeof args[0] === 'string' ? args[1] : args[0]; var name = typeof args[0] === 'string' ? args[0] : ''; this.sequenceArray.push((0, __1.parallel)(name, result)); return new SequenceBuilder(this.sequenceArray); }; SequenceBuilder.prototype.sequence = function (seq) { var _a; (_a = this.sequenceArray).push.apply(_a, seq); return new SequenceBuilder(this.sequenceArray); }; SequenceBuilder.prototype.when = function (callback) { function when(context) { return callback(context) ? context.path.true({}) : context.path.false({}); } return this.branch(when); }; SequenceBuilder.prototype.debounce = function (ms) { return this.branch((0, factories_1.debounce)(ms)); }; SequenceBuilder.prototype.equals = function (callback) { function equals(context) { var result = String(callback(context)); return context.path[result] ? context.path[result]({}) : context.path.otherwise({}); } return this.branch(equals); }; SequenceBuilder.prototype.wait = function (ms) { this.sequenceArray.push((0, factories_1.wait)(ms)); return new ContinueSequenceBuilder(this.sequenceArray); }; return SequenceBuilder; }()); exports.SequenceBuilder = SequenceBuilder; var ContinueSequenceBuilder = /** @class */ (function (_super) { __extends(ContinueSequenceBuilder, _super); function ContinueSequenceBuilder() { return _super !== null && _super.apply(this, arguments) || this; } ContinueSequenceBuilder.prototype.continue = function () { var builder = new SequenceBuilder([]); this.sequenceArray.push({ continue: builder.sequenceArray, }); return builder; }; return ContinueSequenceBuilder; }(SequenceBuilder)); exports.ContinueSequenceBuilder = ContinueSequenceBuilder; function generatePathSequence(paths) { var outputSequence = {}; for (var key in paths) { var cb = new SequenceBuilder([]); var chain = paths[key]; chain(cb); outputSequence[key] = cb.sequenceArray; } return outputSequence; } function sequenceFactory(arg) { var builder = new SequenceBuilder([]); arg(builder); return builder.sequenceArray; } function Sequence(arg) { return sequenceFactory(arg); } function SequenceWithProps(arg) { return sequenceFactory(arg); } function SequenceFactory() { function returned(arg) { return sequenceFactory(arg); } return returned; } function SequenceWithPropsFactory() { function returned(arg) { return sequenceFactory(arg); } return returned; } //# sourceMappingURL=index.js.map