UNPKG

surrogate

Version:

Object method hooks made easy

85 lines (77 loc) 2.8 kB
import {BailRule as $gwlmQ$BailRule, ErrorRule as $gwlmQ$ErrorRule, ProgressRule as $gwlmQ$ProgressRule} from "./surrogate.35af5771.js"; import {RunConditionProvider as $gwlmQ$RunConditionProvider} from "./surrogate.7156328e.js"; import {HookType as $96586206eab52612$export$b3a402ce9f993bc7} from "./surrogate.5d082a84.js"; import {asArray as $gwlmQ$asArray} from "@jfrazx/asarray"; class $9c2157ee2c882141$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, $gwlmQ$ErrorRule)({ ...options, using: using }), new (0, $gwlmQ$BailRule)({ ...options, using: using }), new (0, $gwlmQ$ProgressRule)({ ...options, using: using }) ]; const rule = rules.find((rule)=>rule.shouldRun()); rule.run(this); } shouldRun(using) { const runParameters = new (0, $gwlmQ$RunConditionProvider)(this, using, this.prevNode?.didError); const { options: options } = this.container; const context = this.useContext; return (0, $gwlmQ$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, $96586206eab52612$export$b3a402ce9f993bc7).PRE ? (0, $96586206eab52612$export$b3a402ce9f993bc7).PRE : (0, $96586206eab52612$export$b3a402ce9f993bc7).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 }); } } export {$9c2157ee2c882141$export$dbf06c60898cd742 as BaseNext}; //# sourceMappingURL=surrogate.7cb16335.js.map