acenturyandabit / acenturyandabit/workflowish

move this function into the Model class, so that we can optimize it with the mem...

Aperta
#50 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
todo
Lingua principale
TypeScript
Stelle
0
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

https://api.github.com/acenturyandabit/workflowish/blob/7238fd3d1e0ee71c3eda7926212fad61fa084819/src/Workflowish/index.tsx#L124

```javascript

focusThisEnd: topLevelTakeFocus,
focusRecentlyIndentedItem: topLevelTakeFocus,
focusMyNextSibling: () => {
if (ii < props.itemTree.children.length - 1) {
itemsRefArray.current[ii + 1]?.focusThis()
} else {
itemsRefArray.current[ii]?.focusThis()
}
},
},
disableDelete: () => (props.itemTree.children.length == 1),
getSetItems: (keys: string[], getSetter: TreeNodesGetSetter) => {
const oldItems = keys.map(key => props.keyedNodes[key])
const newNodes = getSetter(oldItems);
const newRootNode = mergeKeyedNodesAndTree(newNodes, props.keyedNodes[virtualRootId]);
props.getSetTodoItems(newRootNode);
},
thisItem: props.itemTree
})}
>)
})}
}

// TODO: move this function into the Model class, so that we can optimize it with the memory of the parents
const mergeKeyedNodesAndTree = (newNodes: ItemTreeNode[], oldRoot: ItemTreeNode): ItemTreeNode => {
const newNodesByKey: Record = newNodes.reduce((nodesByKey, current) => {
nodesByKey[current.id] = current;
return nodesByKey;
}, {} as Record)

const newRootNode = newNodesByKey[virtualRootId] || oldRoot;

const DFSStack: ItemTreeNode[] = [newRootNode];
const cycleDetectionSet: Set = new Set([virtualRootId]);
while (DFSStack.length > 0) {
const top = DFSStack.pop();
if (top) {
top.children = top.children.map((child) =>
newNodesByKey[child.id] || child
);
top.children.forEach(child => {
if (!cycleDetectionSet.has(child.id)){
cycleDetectionSet.add(child.id);
DFSStack.push(child)
}
});
}
}
return newRootNode;
}

```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.