Skip to content

Commit 6e54ae5

Browse files
committed
refactor: remove draft
1 parent 1aaa985 commit 6e54ae5

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

lib/HeTree.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,46 +174,17 @@ export function useHeTree<T extends Record<string, any>>(
174174
}
175175
return stats[id]
176176
}
177-
let draft: T[] | null = null
178-
function getDraft() {
179-
if (!draft) {
180-
const map = new Map<Stat<T> | null, T[]>()
181-
map.set(null, [])
182-
draft = map.get(null)!
183-
for (const [stat, { parent: parentStat }] of walkTreeDataGenerator(rootStats, 'childStats')) {
184-
const newNode = { ...stat.node, [CHILDREN]: [] }
185-
map.set(stat, newNode[CHILDREN])
186-
map.get(parentStat)!.push(newNode)
187-
}
188-
}
189-
return draft
190-
}
191-
function nextData() {
192-
const draft = getDraft()
193-
let result = draft
194-
if (props.dataType === 'flat') {
195-
result = [];
196-
for (const [node, { parent }] of walkTreeDataGenerator(draft, CHILDREN)) {
197-
// @ts-ignore
198-
node[PID] = parent ? parent[ID] : props.rootId
199-
result.push(node)
200-
}
201-
}
202-
return result
203-
}
204177
return {
205178
// root
206179
rootIds, rootNodes, rootStats,
207180
// methods
208181
getStat,
209-
getDraft,
210-
nextData,
211182
}
212183
}, [props.data, props.dataType, ID, PID, openIdSet, checkedIdSet, props.rootId,
213184
isFunctionReactive && props.canDrag,
214185
]
215186
);
216-
const { rootIds, rootStats, getStat, getDraft, nextData } = mainCache;
187+
const { rootIds, rootStats, getStat, } = mainCache;
217188
// about drag ==================================
218189
const indent = props.indent!
219190
const [draggedStat, setDraggedStat] = useState<Stat<T>>();

0 commit comments

Comments
 (0)