Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/vue3/vuex/src/builder/ |
Upload File : |
/* eslint-disable no-param-reassign */ import { Store } from '../vuex'; import { BuilderModel } from './model'; export class BuilderEntityModel<State, Item> extends BuilderModel { constructor(): BuilderEntityModel { super(); // eslint-disable-next-line no-constructor-return return new Proxy(this, { get: (target: BuilderEntityModel, property: string): function => { if (property in BuilderEntityModel.defaultModel) { return (): Object => ({ ...BuilderEntityModel.defaultModel[property](target), ...target[property]?.(), }); } return target[property]; }, }); } static defaultModel = { getState: () => ({ collection: {}, }), getGetters: () => ({ getAll: (state: State): Item[] => Object.values(state.collection), getIds: (state: State): number[] => Object.values(state.collection).map(({ id }) => id), getById: (state: State) => (id: number | string): Item => state.collection[id], getByIds: (state: State, { getAll }): Item[] => (ids: number[]): Item[] => { return getAll.filter((item: Item) => ids.includes(item.id)); }, }), getActions: () => ({ insert: (store: Store, item: Item): void => { store.commit('insert', item); }, insertMany: (store: Store, items: Item[]): void => { items.forEach((item: Item) => store.commit('insert', item)); }, upsert: (store: Store, item: Item): void => { store.commit('upsert', item); }, upsertMany: (store: Store, items: Item[]): void => { items.forEach((item: Item) => store.commit('upsert', item)); }, update: (store: Store, payload: { id: number | string, fields: Item }): void => { store.commit('update', payload); }, delete: (store: Store, id: number): void => { store.commit('delete', id); }, deleteMany: (store: Store, ids: number[]): void => { ids.forEach((id: number) => store.commit('delete', id)); }, }), getMutations: (target: BuilderEntityModel) => ({ insert: (state: State, item: ?Item): void => { if (item) { state.collection[item.id] ??= { ...target.getElementState?.(), ...item }; } }, upsert: (state: State, item: ?Item): void => { if (item) { state.collection[item.id] = { ...state.collection[item.id] ?? item, ...item }; } }, update: (state: State, { id, fields }: { id: number | string, fields: Item }): void => { const updatedItem = { ...state.collection[id], ...fields }; delete state.collection[id]; state.collection[fields.id ?? id] = updatedItem; }, delete: (state: State, id: number): void => { delete state.collection[id]; }, }), }; }