@magicbell/core
Version:
Official MagicBell API wrapper
21 lines • 700 B
JavaScript
import get from '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) }
*/
export default function wrap(wrapKey) {
return function (target, propertyKey, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args) {
const [json, ...otherArgs] = args;
const unwrappedJson = get(json, wrapKey, json);
const wrappedJson = { [wrapKey]: unwrappedJson };
return originalMethod.apply(this, [wrappedJson, ...otherArgs]);
};
};
}
//# sourceMappingURL=wrap.js.map