UNPKG

ivue-material-plus

Version:

A high quality UI components Library with Vue.js

68 lines (65 loc) 1.74 kB
import { watch } from 'vue'; import { debounce } from 'lodash-unified'; import useStore from './index.mjs'; import { throwError } from '../../../utils/error.mjs'; const initialState = { rowKey: "rowKey", defaultExpandAll: "defaultExpandAll", selectOnIndeterminate: "selectOnIndeterminate", indent: "indent", lazy: "lazy", data: "data", ["treeProps.hasChildren"]: { key: "lazyColumnIdentifier", default: "hasChildren" }, ["treeProps.children"]: { key: "childrenColumnName", default: "children" } }; function createStore(table, props) { if (!table) { throwError("ivue-table", "Table is required"); } const store = useStore(); store.toggleAllSelection = debounce(store._toggleAllSelection, 10); Object.keys(initialState).forEach((key) => { setStatesValue(getArrKeysValue(props, key), key, store); }); proxyTableProps(store, props); return store; } function proxyTableProps(store, props) { Object.keys(initialState).forEach((key) => { watch( () => getArrKeysValue(props, key), (value) => { setStatesValue(value, key, store); } ); }); } function setStatesValue(value, propsKey, store) { let newVal = value; let storeKey = initialState[propsKey]; if (typeof initialState[propsKey] === "object") { storeKey = storeKey.key; newVal = newVal || initialState[propsKey].default; } store.states[storeKey].value = newVal; } function getArrKeysValue(props, keys) { if (keys.includes(".")) { const keyList = keys.split("."); let value = props; keyList.forEach((key) => { value = value[key]; }); return value; } else { return props[keys]; } } export { createStore }; //# sourceMappingURL=helper.mjs.map