acenturyandabit / acenturyandabit/workflowish
move this function into the Model class, so that we can optimize it with the mem...
- 主要語言
- TypeScript
- 星號
- 0
- 分支
- 1
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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;
}
```
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
Open `src/Workflowish/index.tsx` at the TODO shown and review `mergeKeyedNodesAndTree` where it is passed into ``. Trace how `getSetTodoItems`, `props.keyedNodes`, and `props.itemTree` are used to merge updates, then locate the project `Model` class and move this helper there with call sites updated to use it. Done is the function no longer in `index.tsx`, behavior remains equivalent for merged tree output, and `Item` wiring still compiles.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- react, typescript
- 領域
- frontend
- Issue 類型
- 重構
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100