Giter Site home page Giter Site logo

Comments (3)

xaviergonz avatar xaviergonz commented on May 18, 2024

Hey, thanks for the bug report. Non legacy babel decorator support should be fixed in the recently released 0.26.4 (let me know if it is not!).

Sadly @model cannot be moved just as a name of Model since it needs to change the final extended class, the closest it could get is:

class _M extends Model(...) {}
export const M = model(_M, "name")

or similar

for the others (modelAction and modelFlow) it shouldn't be too difficult to change them to something like

{
  someAction = modelAction("actionName", () => {....})
}

however it has a few downsides:

  • it won't be able to get the action name automatically, so it would need to be specified again (duplicated)
  • all actions would need to be specified as a class field rather than class method, so it wouldn't use the prototype (meaning each instance would have a copy of the function), which is a bit slower

I guess a way to avoid those two cons would be to turn model into a decorate alike thing:

class _M extends Model({...}) {
  someAction() {...}
  someFlow = _async(function *() {...})
}

export const M = model(_M, {
  someAction: modelAction,
  someFlow: modelFlow
})

I don't particularly like that syntax since that puts the "decorations" far from the decorated thing, but I see how that can be useful for people that don't want to deal with decorators. Would that last decorate idea be useful to you or is the fix to make it work with babel new decorators good enough?

from mobx-keystone.

nulladdict avatar nulladdict commented on May 18, 2024

Thanks for the quick response

The 0.26.4 fix works and is good enough for me 👍

The decorate idea is not as clean as decorators, but looking at the wider picture, I believe it would be viable alternative for people, who don't want to use decorators yet
However they can already use this approach:

const M = model("M")(_M)
decorate(M, { // from mobx
  someAction: modelAction,
  someFlow: modelFlow
})

I believe we can close this issue since bug is fixed and decorators will eventually make its way into the standard

from mobx-keystone.

xaviergonz avatar xaviergonz commented on May 18, 2024

Thanks for testing! Closing until there are more requests to support this then

from mobx-keystone.

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.