GithubHelp home page GithubHelp logo

Comments (2)

mweststrate avatar mweststrate commented on May 22, 2024

This should give a rough idea:

https://github.com/mweststrate/mobx-state-tree/blob/0d0c5e1c70ff0dcea7fce53d1f10d97e661f33de/examples/boxes/src/stores/domain-state.js#L44

The referenceTo is interesting; it creates a normal string property in which the identifier is stored, and a setter and computed getter to resolve the identifier with the provided path.

Note that you don't have to resolve via strings, you can also introduce a computed property yourself, and write something like:

selectionId: '123'
get selection() {
   if (hasParent(this))
     return getParent(this).boxes.get(this.selectionId)
   return null
}

Resolving a list of identifiers is still on the todo list, but will be part of the first version :)

Sorry for not having docs yet, they will be added, but ATM this is quite alpha :)

from mobx-state-tree.

antitoxic avatar antitoxic commented on May 22, 2024

I'm kind of lost :)

I understand it's alpha, no worries. With the risk of sounding silly, what's the benefit of using mobx-state-tree?

Or more specifically isn't there a away to do the same thing without mobx-state-tree? Looking at the example you linked above to me hasParent() and getParent() look evil. Why isn't parent just a property instead of magically inferred from outside? Also selection looks like it's better if it's a @computed property based on any box that has isSelected property equal true.

Moreover referenceTo or resolve use some sort of string-based identifier. This all looks very odd to me. It's kind of query language like xpath. Is it an official thing? Otherwise why introduce a new one?

As you mentioned - using getters and setters is enough to do resolving logic. It is also as custom as a person like. Why not stop there?

Wouldn't it be better if mobx-state-tree just takes care of getSnapshot and applySnapshot by requiring the developer to create stores that implement a specific interface?

from mobx-state-tree.

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.