UNPKG

@kezios/forest-express-decorator

Version:
36 lines (35 loc) • 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartActionIntegration = exports.SmartActionField = exports.SmartAction = void 0; const lodash_1 = require("lodash"); const SmartAction = (options) => { return function (constructor) { return class extends constructor { constructor() { super(...arguments); this.label = options.label; this.type = options.type; this.onLoad = options.onLoad; } }; }; }; exports.SmartAction = SmartAction; function SmartActionIntegration(classSmartAction) { const smartAction = new classSmartAction(); return function (target, propertyKey) { if (target.actions === undefined) target.actions = {}; target.actions[(0, lodash_1.kebabCase)(propertyKey)] = smartAction; }; } exports.SmartActionIntegration = SmartActionIntegration; const SmartActionField = (options) => { return function (target, propertyKey) { //todo use propery key to create reverser-map propertyKey <--> field if (target.fields === undefined) target.fields = []; target.fields.push(Object.assign(Object.assign({}, (0, lodash_1.omit)(options, 'label')), { field: options.label, name: propertyKey })); }; }; exports.SmartActionField = SmartActionField;