Giter Club home page Giter Club logo

Comments (3)

agilgur5 avatar agilgur5 commented on July 16, 2024

Just noting that this and redux-persist's State Reconcilers are both only for initial state. This should be made very explicit in any docs for this. Merging existing, in-memory data is out-of-scope and should be done in application code / actions, not in mst-persist as it's in-memory and not related to persisting to disk.

That being said, we could expose some of these functions if users want to use elsewhere in their code I guess, but they should all be pretty simple.

Another note is that this is related to implementing Transforms. We could just not have merge strategies built-in and leave them up to the user to implement as transforms. If we do have merge strategies built-in, then the order between them and transforms needs to be defined (and merge strategies should probably just be implemented as a transform).
I would assume the merge goes first, then future transforms, but I'm actually not sure that's optimal, or that having the merge order be pre-defined is intuitive. It may be more intuitive to have merge strategies be mutually exclusive with transforms, so the user has to explicitly add it to their list of transforms.
The only issue there is that redux-persist has transforms per key while state reconcilers are for the whole store. It might just make sense to have transforms in mst-persist be on the whole store as well -- the user chooses what to do with each key on their own, and this allows for transforms involving multiple keys as well. Migrations seem to be done that way as well, so that way a migration would just be a transform as well.
(Getting a bit too into the details of transforms in the wrong issue, but so I don't forget again, transforms should probably receive a dereferenced snapshot instead of an MST object so that mutable changes don't accidentally change the state of the running app. EDIT: and then I forgot again that we're acting on a snapshot by definition: all transforms run inside of onSnapshot)

from mst-persist.

airtonix avatar airtonix commented on July 16, 2024

Since I don't really understand most of what you're talking about, but can mostly assume it's to do with how to persist selected parts of our tree:

Assume you're making a game, where you have something roughly like

Game: <Game>
  Player: <Player>
    Characters: <Character[]>
      - Id: <Guid>
         name: <string>
         type: <Ref<CharacterClass>>
         hp: <number>
         entities: <Entity[]>
         modifiers: <Modifier[]>
    currentCharacter: <Ref<Character>>
  Meta: <GameMeta>
    CharacterClasses: <CharacterClass[]>
    
  Zones: <Zone[]>
    - Id: <Guid>
      Entities: <Entity[]>
        - Id: <Guid>
           name: 'Loot Chest'
           entities: <Entity[]>
             -  Id: <Guid>
                name: 'Coins'
                qty: 100
      Layers: <MapLayer[]>
        - Id: <Guid>
           depth: <number>
      Map: <Map>
        tileMap: <String>
        tileSet: <String>
  currentZone: <Ref<Zone>>

Some of this I want to persist, some of it i want to come from initial data:

Game.Player > persist
Game.currentZone > persist
Game.Zones[] > initial data
Game.Zones[].Entities > persist

Suggestions on how to do this without:

  • merge strategy
  • rewriting the Store to delineate peristable vs non persistable items?

from mst-persist.

agilgur5 avatar agilgur5 commented on July 16, 2024

@airtonix sorry for the delayed response

but can mostly assume it's to do with how to persist selected parts of our tree:

Sorry that's not correct. This issue is about how to merge persisted data with data created during .create. It currently overwrites data from .create as that is applySnapshot's default. It does use the defaults defined inside of your model itself though.

Assume you're making a game, where you have something roughly like

This is a fairly complex model -- minimal examples are much more helpful and significantly easier to respond to. I saw this when you commented, but given the complexity here, I did not really have the time to respond. I also did not see your edits until now

Some of this I want to persist, some of it i want to come from initial data:

You might be looking for #27, but I can see that this would be useful for the initial data portion as well.

Suggestions on how to do this without:

  • merge strategy
  • rewriting the Store to delineate peristable vs non persistable items? [sic]
  1. I'd say the main workaround would be to delete persisted data and add the initial data after persist runs.
  2. The other would be to add some defaults to the model itself since applySnapshot will use those in the case of undefined (i.e. if no data is persisted for a part of a model). But due to the nested nature of your data, I don't think this would solve your problem without #27. For simpler models, this does work though and is how I've done defaults myself.

from mst-persist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.