Skip to content

Commit

Permalink
chore: use old tree common before refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Oct 18, 2023
1 parent 3a3be2c commit 2d9a332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/cascader/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getTreeValue, getCascaderValue, isEmptyValues, isValueInvalid } from '.
import { treeNodesEffect, treeStoreExpendEffect } from './core/effect';

import useControlled from '../hooks/useControlled';
import {
import type {
TreeNode,
TreeNodeValue,
TdCascaderProps,
Expand All @@ -17,6 +17,8 @@ import {
CascaderValue,
} from './interface';

import type { TypeTreeNodeData } from '../_common/js/tree/types';

export const useCascaderContext = (props: TdCascaderProps) => {
const [innerValue, setInnerValue] = useControlled(props, 'value', props.onChange);
const [innerPopupVisible, setPopupVisible] = useControlled(props, 'popupVisible', props.onPopupVisibleChange);
Expand Down Expand Up @@ -96,7 +98,7 @@ export const useCascaderContext = (props: TdCascaderProps) => {
});
},
});
store.append(options);
store.append(options as Array<TypeTreeNodeData>);
setTreeStore(store);
} else {
treeStore.reload(options);
Expand Down
6 changes: 4 additions & 2 deletions src/tree-select/useTreeSelectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import type { TreeSelectValue } from './type';
import Tree, { TreeNodeValue } from '../tree';
import TreeStore from '../_common/js/tree/tree-store';
import { usePersistFn } from '../_util/usePersistFn';
import type { NodeOptions, TreeSelectProps } from './TreeSelect';
import { treeSelectDefaultProps } from './defaultProps';

import type { NodeOptions, TreeSelectProps } from './TreeSelect';
import type { TypeTreeNodeData } from '../_common/js/tree/types';

export const useTreeSelectUtils = (
{ data, treeProps, valueType }: TreeSelectProps,
treeRef: MutableRefObject<ElementRef<typeof Tree>>,
Expand All @@ -15,7 +17,7 @@ export const useTreeSelectUtils = (
...treeSelectDefaultProps.treeProps,
...treeProps,
});
store.append(data);
store.append(data as Array<TypeTreeNodeData>);
return store;
}, [data, treeProps]);

Expand Down
6 changes: 4 additions & 2 deletions src/tree/hooks/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import useUpdateEffect from '../../_util/useUpdateEffect';
import usePrevious from '../../hooks/usePrevious';
import TreeStore from '../../_common/js/tree/tree-store';
import { usePersistFn } from '../../_util/usePersistFn';

import type { TdTreeProps } from '../type';
import type { TypeEventState } from '../interface';
import type { TypeTreeNodeData } from '../../_common/js/tree/types';

export function useStore(props: TdTreeProps, refresh: () => void): TreeStore {
const storeRef = useRef<TreeStore>();
Expand Down Expand Up @@ -122,7 +124,7 @@ export function useStore(props: TdTreeProps, refresh: () => void): TreeStore {
list = [];
}

store.append(list);
store.append(list as Array<TypeTreeNodeData>);

// 刷新节点,必须在配置选中之前执行
// 这样选中态联动判断才能找到父节点
Expand Down Expand Up @@ -161,7 +163,7 @@ export function useStore(props: TdTreeProps, refresh: () => void): TreeStore {
const checked = store.getChecked();
const actived = store.getActived();
store.removeAll();
store.append(data);
store.append(data as Array<TypeTreeNodeData>);
store.setChecked(checked);
store.setActived(actived);
store.setExpanded(expanded);
Expand Down

0 comments on commit 2d9a332

Please sign in to comment.