How to do partial reconcile?

I'd like to use reconcile on a partial / subset of my data. How do you do this? My best idea so far is to write this for loop:
for (const key of Object.keys(data)) {
this.setState(key as any, reconcile(data[key as keyof typeof data]))
}
for (const key of Object.keys(data)) {
this.setState(key as any, reconcile(data[key as keyof typeof data]))
}
However this triggers a setState for each key, which isn't that good from a performance point of view, I guess. reconcile seems to require the full state object to be present. Has anyone written a reconcile which can take partial state as input? Should I use batch()? Or a simple reconcile with {...this.state, ...data}?
3 Replies
mdynnl
mdynnl2d ago
both works but batch + selective reconcile should be more optimal reconcile could even provide this through a flag, may be make a case somewhere impactful
hyperknot
hyperknotOP2d ago
thank you by could do you mean, it'd be a nice idea for future development, or it's already supported, I just need to find it? And what's your opinion on produce()? Does that allow similar speedups like reconcile? By speedup, I mean that if the new data is the same as the old data on a sub-part of the tree, then it should not trigger an update.
hyperknot
hyperknotOP2d ago
Summarized all my points on a GitHub issue: https://github.com/solidjs/solid/issues/2475
GitHub
reconcile: support "merge" in objects · Issue #2475 · solidjs/solid
A common pattern I believe is to reconcile partial state updates in stores. For example, part of a store is synced to a backend, so after a push-to-backend operation, it returns an up-to-date data ...

Did you find this page helpful?