UNPKG

@magicbell/core

Version:

Official MagicBell API wrapper

25 lines 873 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = wrap; const tslib_1 = require("tslib"); const get_js_1 = tslib_1.__importDefault(require("lodash/get.js")); /** * Decorator factory to wrap the first argument of the method decorated with * this. * * @example * @wrap('notification') * set(json) { Object.assign(this, json) } */ function wrap(wrapKey) { return function (target, propertyKey, descriptor) { const originalMethod = descriptor.value; descriptor.value = function (...args) { const [json, ...otherArgs] = args; const unwrappedJson = (0, get_js_1.default)(json, wrapKey, json); const wrappedJson = { [wrapKey]: unwrappedJson }; return originalMethod.apply(this, [wrappedJson, ...otherArgs]); }; }; } //# sourceMappingURL=wrap.js.map