UNPKG

surrogate

Version:

Object method hooks made easy

90 lines (80 loc) 2.9 kB
var $fcfa68ed0c91f741$exports = require("./surrogate.c2e9f688.js"); var $cad375f6cfe6fa82$exports = require("./surrogate.f983ed05.js"); var $173529f42333421b$exports = require("./surrogate.014ad084.js"); var $f1AJz$jfrazxasarray = require("@jfrazx/asarray"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "BaseNext", () => $6d0fe89abc51fb27$export$dbf06c60898cd742); class $6d0fe89abc51fb27$export$dbf06c60898cd742 { constructor(controller, proxy, container, hookFor){ this.controller = controller; this.proxy = proxy; this.container = container; this.hookFor = hookFor; controller.addNext(this); } skip(times = 1) { return this.skipWith(times); } next({ using: using = [], ...options } = {}) { this.controller.timeTracker.setHookEnd(); this.replace(options); const rules = [ new (0, $fcfa68ed0c91f741$exports.ErrorRule)({ ...options, using: using }), new (0, $fcfa68ed0c91f741$exports.BailRule)({ ...options, using: using }), new (0, $fcfa68ed0c91f741$exports.ProgressRule)({ ...options, using: using }) ]; const rule = rules.find((rule)=>rule.shouldRun()); rule.run(this); } shouldRun(using) { const runParameters = new (0, $cad375f6cfe6fa82$exports.RunConditionProvider)(this, using, this.prevNode?.didError); const { options: options } = this.container; const context = this.useContext; return (0, $f1AJz$jfrazxasarray.asArray)(options.runConditions).every((condition)=>{ const result = condition.call(context, runParameters); runParameters.reset(); return result; }); } get instance() { return this.context.target; } get hookType() { return this.hookFor === (0, $173529f42333421b$exports.HookType).PRE ? (0, $173529f42333421b$exports.HookType).PRE : (0, $173529f42333421b$exports.HookType).POST; } get context() { return this.controller.context; } addNext(next) { if (this.nextNode) return this.nextNode.addNext(next); this.nextNode = next; next.prevNode = this; } get useContext() { return this.context.determineContext(this.container.options); } shouldReplace(options) { return 'replace' in options; } replace(options) { if (this.shouldReplace(options)) this.controller.updateLatestArgs(options.replace); } bail(bailOptions = {}) { this.next({ ...bailOptions, bail: true }); } } //# sourceMappingURL=surrogate.71122426.js.map