mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 12:07:54 +08:00
f0385d7c24
* feat: tree * refactor: select * refactor: select * refactor: select * refactor: vc-tree-select * refactor: tree-select * refactor: tree-select * feat: add showLeafIcon * refactor: remove lod vc-tree-select * feat: tree-select add tag-render * refactor: cascader * refactor: cascader * refactor: cascader * refactor: cascader * fix: maxTagmaxTagPlaceholder not work
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { Ref } from 'vue';
|
|
import { computed, shallowRef } from 'vue';
|
|
import type { LabeledValueType, RawValueType } from '../TreeSelect';
|
|
|
|
/**
|
|
* This function will try to call requestIdleCallback if available to save performance.
|
|
* No need `getLabel` here since already fetch on `rawLabeledValue`.
|
|
*/
|
|
export default (values: Ref<LabeledValueType[]>): [Ref<LabeledValueType[]>] => {
|
|
const cacheRef = shallowRef({
|
|
valueLabels: new Map<RawValueType, any>(),
|
|
});
|
|
|
|
const newFilledValues = computed(() => {
|
|
const { valueLabels } = cacheRef.value;
|
|
const valueLabelsCache = new Map<RawValueType, any>();
|
|
|
|
const filledValues = values.value.map(item => {
|
|
const { value } = item;
|
|
const mergedLabel = item.label ?? valueLabels.get(value);
|
|
|
|
// Save in cache
|
|
valueLabelsCache.set(value, mergedLabel);
|
|
|
|
return {
|
|
...item,
|
|
label: mergedLabel,
|
|
};
|
|
});
|
|
|
|
cacheRef.value.valueLabels = valueLabelsCache;
|
|
|
|
return filledValues;
|
|
});
|
|
return [newFilledValues];
|
|
};
|