surrogate
Version:
Object method hooks made easy
36 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseContainer = void 0;
const handler_1 = require("../handler");
const options_1 = require("../options");
const helpers_1 = require("../helpers");
class BaseContainer {
constructor(handler, type, options = new options_1.OptionsHandler()) {
this.handler = handler;
this.type = type;
this.options = options;
}
getHandler(context) {
const { target, receiver } = context;
return (this.shouldReflect(this.handler)
? this.shouldReflectSurrogate(context)
? /**
* @note Removes ability to apply target only
* @todo fix ^^
*/
Reflect.get(receiver, this.handler, receiver)
: Reflect.get(target, this.handler, receiver)
: this.handler);
}
shouldReflect(value) {
return !(0, helpers_1.isFunction)(value);
}
shouldReflectSurrogate(context) {
return context.useSurrogate(this.options.useContext);
}
getHandlerRunner(node) {
return handler_1.HandlerRunner.for(node, this.options);
}
}
exports.BaseContainer = BaseContainer;
//# sourceMappingURL=base.js.map