import isObject from 'lodash/isObject'; import { DvaModel } from 'umi'; import { BaseState } from './interfaces/common'; type State = Record; type DvaModelKey = keyof DvaModel; export const modelExtend = ( baseModel: Partial>, extendModel: DvaModel, ): DvaModel => { return Object.keys(extendModel).reduce>((pre, cur) => { const baseValue = baseModel[cur as DvaModelKey]; const value = extendModel[cur as DvaModelKey]; if (isObject(value) && isObject(baseValue) && typeof value !== 'string') { const key = cur as Exclude, 'namespace'>; pre[key] = { ...baseValue, ...value, } as any; } else { pre[cur as DvaModelKey] = value as any; } return pre; }, {} as DvaModel); }; export const paginationModel: Partial> = { state: { searchString: '', pagination: { total: 0, current: 1, pageSize: 10, }, }, reducers: { setSearchString(state, { payload }) { return { ...state, searchString: payload }; }, setPagination(state, { payload }) { return { ...state, pagination: { ...state.pagination, ...payload } }; }, }, };