mobx-state-tree
mobx-state-tree copied to clipboard
Introduce `applyPartialSnapshot`
like applySnapshot, but leaves unmentioned fields as is (so a bit like Object.assign, etc). Second argument, defaulting to true, to indicate whether non-represented items from old collections should be removed? (false would make the method only additative)
I'm going to take a stab at this one if that's alright
Hey @mweststrate & @mattiamanzati I think I'm getting close for this... but to be sure I'm in line with what you're thinking, could you provide some example situations with your expected input / output?
The thing I am unsure about is how to handle maps / arrays. Should we assume applyPartialSnapshot is incremental only and cannot be used to drop items? Also I think that it is important that for objects that have an identifier, the identifier is included in the snapshot to make sure reconciliation works as expected
Op di 17 okt. 2017 om 02:34 schreef Albatross [email protected]:
Hey @mweststrate https://github.com/mweststrate & @mattiamanzati https://github.com/mattiamanzati I think I'm getting close for this... but to be sure I'm in line with what you're thinking, could you provide some example situations with your expected input / output?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-state-tree/issues/120#issuecomment-337082668, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvGhH8aWTe216Gyo6rflapddqpQVxIEks5ss_YZgaJpZM4NXL1u .
Am I correct that the a current way to do this is to get a snapshot, deepmerge it with the changes into an empty object?
So something like this?
import * as deepmerge from "deepmerge";
applySnapshot(todoStore, deepmerge.all([
{},
getSnapshot(todoStore), {
todos: {
"2" : {
id: 2,
title: "Get coffee"
}
},
selectedTodo: 2
}])))
If so, a better example in the docs could be helpful until applyPartialSnapshot is ready.
Based on the usage stated above by @mweststrate i'm wondering if this should actually be called mergeSnapshot?
No updates on this? This would be a really valuable feature!
+1 for this feature.
+1 !
Hey folks,
This MobX-State-Tree issue is pretty old and hasn't had movement for a while.
I'm gonna close it out as unplanned, but it's a great idea and we're always happy to review PRs. Personally, I prioritize PR review over my own work, so if anyone wants to build this out, please submit a PR and we will get to it in a timely manner!
Thanks for your time.