UNPKG

linkmore-design

Version:

🌈 🚀lm组件库。🚀

57 lines 1.54 kB
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import { createContext, useContext, useReducer } from 'react'; // =============== context ============== // var TableContext = /*#__PURE__*/createContext({ state: null, dispatch: null, instance: {} }); var useStore = function useStore() { return useContext(TableContext); }; var initialState = { // 行高度 rowHeight: 0, columnsLen: 0, // 总行数 totalLen: 0, // 分割后的列数组 sliceColumns: { leftColumns: [], centerColumns: [], rightColumns: [] } }; var reducer = function reducer(state, action) { var totalLen = action.totalLen, columnsLen = action.columnsLen, rowHeight = action.rowHeight, sliceColumns = action.sliceColumns; switch (action.type) { // 数据数量 case 'changeTotalLen': return _objectSpread(_objectSpread({}, state), {}, { totalLen: totalLen }); // 列数量 case 'changeColumnsLen': return _objectSpread(_objectSpread({}, state), {}, { columnsLen: columnsLen }); // 初始化行高度 case 'initHeight': return _objectSpread(_objectSpread({}, state), {}, { rowHeight: rowHeight }); case 'changeSliceColumns': return _objectSpread(_objectSpread({}, state), {}, { sliceColumns: sliceColumns }); default: throw new Error(); } }; var useRealive = function useRealive() { return useReducer(reducer, initialState); }; export { TableContext, useStore, useRealive };