I have two lists of nodes, who shaped like so:
interface TreeNode {
data: {
name: string,
sharedProp: boolean,
oldProp: boolean
},
children: TreeNode[],
parents: TreeNode[],
thereAreSomeShallowProps: any,
}
The full dataset would be an array of TreeNode
What I'd like is to have a function that I can traverse down this tree, merging changes in a changes
tree into the base tree. Some of the feature it'd need:
- Match the values of a specified key (in this case support multilevel keys), and merge the matches
- possibly with
flatten
and groupBy
- When the values of the object are arrays, recurse
- Resistant to circular references
- Able to work with very large objects (over 100k nodes, at least)
Some of the functions I've looked at (but am unsure how to string together to build the function I want):
applySpec
groupBy
mergeWithKey
mergeDeepWithKey
Here is a sandbox to check out, with some tests that should explain better what I'm trying to achieve
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…