UNPKG

deleight

Version:

A library with 9 modules for writing more expressive web applications with traditional HTML, CSS and JavaScript.

48 lines (47 loc) 1.18 kB
"use strict"; /** * A proxy object which calls a wrapped function when object operations * (like get, set and delete) are done on it, using the specified * key as the first parameter. * * Pending tests. Please report bugs. * * @module */ Object.defineProperty(exports, "__esModule", { value: true }); exports.dyn = exports.Dynamic = void 0; const own_js_1 = require("../../object/member/own/own.js"); /** * A proxy object which calls a wrapped function when object operations * (like get, set and delete) are done on it, using the specified * key as the first parameter. * * This can be used to create 'dynamic' getters, setters and 'deleters'. * * Pending tests. Please report bugs. * * @example * * */ function Dynamic(fn) { return new Proxy(fn, fHandler); } exports.Dynamic = Dynamic; /** * Alias for {@link Dynamic} */ exports.dyn = Dynamic; const fHandler = { get(target, p) { return target((0, own_js_1.realKey)(p)); }, set(target, p, value) { target((0, own_js_1.realKey)(p), value); return true; }, deleteProperty(target, p) { target((0, own_js_1.realKey)(p)); return true; } };