Mobx-state-tree: Introduce `applyPartialSnapshot`

Created on 10 May 2017  Â·  8Comments  Â·  Source: mobxjs/mobx-state-tree

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)

enhancement helPR welcome

Most helpful comment

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

All 8 comments

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 notifications@github.com:

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 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShootingStarr picture ShootingStarr  Â·  4Comments

mreed picture mreed  Â·  3Comments

mshibl picture mshibl  Â·  3Comments

misantronic picture misantronic  Â·  3Comments

erkieh picture erkieh  Â·  4Comments