mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

Introduce `applyPartialSnapshot`

Open mweststrate opened this issue 8 years ago • 8 comments

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)

mweststrate avatar May 10 '17 20:05 mweststrate

I'm going to take a stab at this one if that's alright

DyingAlbatross avatar Oct 07 '17 18:10 DyingAlbatross

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?

DyingAlbatross avatar Oct 17 '17 00:10 DyingAlbatross

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 .

mweststrate avatar Oct 17 '17 10:10 mweststrate

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.

jrmyio avatar Feb 07 '18 12:02 jrmyio

Based on the usage stated above by @mweststrate i'm wondering if this should actually be called mergeSnapshot?

ashconnell avatar May 21 '18 03:05 ashconnell

No updates on this? This would be a really valuable feature!

mrahhal avatar Dec 13 '18 16:12 mrahhal

+1 for this feature.

holgersindbaek avatar Oct 14 '19 07:10 holgersindbaek

+1 !

maccman avatar Dec 16 '20 02:12 maccman

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.

coolsoftwaretyler avatar Nov 28 '23 07:11 coolsoftwaretyler