In my state I have a dictionary of a flat object:
export interface INodeVisibility {
id: string;
level: number;
isExpanded: boolean;
}
export type NodeVisibilityDict = { [key: string]: INodeVisibility };
In one operation I need to iterate over a list of modifications and add or update the corresponding entries in the dictionary using immutability-helper library. I wonder what would be the best approach:
- In each iteration do a $set operation modifying or adding the dictionary entry.
- In each iteration mutate a "modifications-object" and do a $merge of it only once at the end.
Note the data is normalized. INodeVisibility is declared as an interface but it can be understand as a type because it is used as shown, no more properties added.
I'd vote for the second approach but I want to know what is recommended in this case.