UNPKG

q-proxyable

Version:
46 lines (45 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProxyableByProxy = void 0; var utils_1 = require("./utils"); var common_1 = require("./common"); var utils_2 = require("./utils"); function ProxyableByProxy(value, option) { if (value && typeof value === 'object') { if (utils_1.isProxyable(value)) { option && utils_1.addHandlersToTarget(value, option); return utils_1.getProxyableTarget(value); } var handlers_1 = utils_1.addProxyableFlagToTarget(value, option).handlers; var ProxyValue = new Proxy(value, { get: function (target, prop) { if (!target.hasOwnProperty(prop)) { return target[prop]; } var res = ProxyableByProxy(target[prop]); common_1.GLOBAL_PROXY_HANDLERS.get.forEach(function (handler) { return handler(target, prop, res); }); handlers_1 === null || handlers_1 === void 0 ? void 0 : handlers_1.get.forEach(function (handler) { return handler(target, prop, res); }); return res; }, set: function (target, prop, v) { var oldValue = target[prop]; var newValue = ProxyableByProxy(v); common_1.GLOBAL_PROXY_HANDLERS.set.forEach(function (handler) { return handler(target, prop, newValue, oldValue); }); handlers_1 === null || handlers_1 === void 0 ? void 0 : handlers_1.set.forEach(function (handler) { return handler(target, prop, newValue, oldValue); }); target[prop] = newValue; return true; }, deleteProperty: function (target, prop) { var oldValue = target[prop]; delete target[prop]; common_1.GLOBAL_PROXY_HANDLERS.delete.forEach(function (handler) { return handler(target, prop, oldValue); }); handlers_1 === null || handlers_1 === void 0 ? void 0 : handlers_1.delete.forEach(function (handler) { return handler(target, prop, oldValue); }); return true; }, }); utils_2.storeProxyableDataWithTarget(value, ProxyValue); return ProxyValue; } return value; } exports.ProxyableByProxy = ProxyableByProxy;