UNPKG

amisa-forms

Version:
72 lines (71 loc) 3.72 kB
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _PayloadsManager_formFactory, _PayloadsManager_payLoad, _PayloadsManager_getEmptyPageParameter; export class PayloadsManager { constructor(formFactory) { _PayloadsManager_formFactory.set(this, void 0); _PayloadsManager_payLoad.set(this, void 0); this.addPayloadElement = (element) => { if (__classPrivateFieldGet(this, _PayloadsManager_payLoad, "f") === undefined) { __classPrivateFieldSet(this, _PayloadsManager_payLoad, [], "f"); } __classPrivateFieldGet(this, _PayloadsManager_payLoad, "f").push(element); }; this.otherPayLoad = []; this.addOtherPayLoadKey = (object, payLoadKey, fieldName) => { if (typeof payLoadKey === 'string' && !this.otherPayLoad.find(i => i.payLoadKey === payLoadKey)) { this.otherPayLoad.push({ object, payLoadKey, fieldName }); } }; _PayloadsManager_getEmptyPageParameter.set(this, () => { return { currentPage: 1, itemsPerPage: 50, totalPages: 1, }; }); __classPrivateFieldSet(this, _PayloadsManager_formFactory, formFactory, "f"); this.pageParameter = __classPrivateFieldGet(this, _PayloadsManager_getEmptyPageParameter, "f").call(this); this.customPayLoad = {}; this.filters = {}; } get formFactory() { return __classPrivateFieldGet(this, _PayloadsManager_formFactory, "f"); } get headPayLoad() { const convertOtherToObject = () => { const initialValue = {}; return this.otherPayLoad?.reduce((obj, item) => { return { ...obj, [item.payLoadKey]: item.object.getProp(item.fieldName), }; }, initialValue); }; const other = convertOtherToObject(); const convertPayloadToObject = () => { const initialValue = {}; return __classPrivateFieldGet(this, _PayloadsManager_payLoad, "f")?.reduce((obj, item) => { return { ...obj, [item.payLoadKey]: item.value, }; }, initialValue); }; const payload = convertPayloadToObject(); return { ...other, ...payload, ...this.customPayLoad }; } get searchParameter() { return { ...this.filters, ...this.pageParameter, ...this.headPayLoad }; } } _PayloadsManager_formFactory = new WeakMap(), _PayloadsManager_payLoad = new WeakMap(), _PayloadsManager_getEmptyPageParameter = new WeakMap();