linkmore-design
Version:
🌈 🚀lm组件库。🚀
66 lines (65 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useStore = exports.useRealive = exports.TableContext = void 0;
var _react = require("react");
// =============== context ============== //
const TableContext = /*#__PURE__*/(0, _react.createContext)({
state: null,
dispatch: null,
instance: {}
});
exports.TableContext = TableContext;
const useStore = () => (0, _react.useContext)(TableContext);
exports.useStore = useStore;
const initialState = {
// 行高度
rowHeight: 0,
columnsLen: 0,
// 总行数
totalLen: 0,
// 分割后的列数组
sliceColumns: {
leftColumns: [],
centerColumns: [],
rightColumns: []
}
};
const reducer = (state, action) => {
const {
totalLen,
columnsLen,
rowHeight,
sliceColumns
} = action;
switch (action.type) {
// 数据数量
case 'changeTotalLen':
return {
...state,
totalLen
};
// 列数量
case 'changeColumnsLen':
return {
...state,
columnsLen
};
// 初始化行高度
case 'initHeight':
return {
...state,
rowHeight
};
case 'changeSliceColumns':
return {
...state,
sliceColumns
};
default:
throw new Error();
}
};
const useRealive = () => (0, _react.useReducer)(reducer, initialState);
exports.useRealive = useRealive;