GithubHelp home page GithubHelp logo

Comments (5)

dangreen avatar dangreen commented on May 29, 2024 1

why not just copy object before reduce it?

return keysList.reduce((props, key) => { ... }, { ...declaredProps })

Before optimization object was copied on every loop step, in that way it will be copied only once.

from mobx-state-tree.

dangreen avatar dangreen commented on May 29, 2024

@coolsoftwaretyler @jamonholmgren fyi

from mobx-state-tree.

coolsoftwaretyler avatar coolsoftwaretyler commented on May 29, 2024

Ah good point, @dangreen. I don't think we considered the use case where you'd want to have the original object stay un-modified. Most of the time, I think of model instantiation like:

const Model1 = types.model('Model1', { num: 0, str: ''})

In which case, the in-place modification wouldn't be a problem. I can see how you would consider this a breaking change, though we certainly didn't. It can be tough to determine the right classification for changes in MST, where there is a lot of undocumented and untested behavior.

I really prefer the changed version of this, but I wonder if we can put it behind an opt-in flag instead, to restore the prior behavior, but allow people to get the benefits of faster model instantiation when they know their second parameter is safe to modify.

I'll label this as a bug and we'll see what we can do here. Thanks for the issue, and would be happy to review a PR!

from mobx-state-tree.

coolsoftwaretyler avatar coolsoftwaretyler commented on May 29, 2024

That works, too! I was just writing my first idea, haha. I like yours better.

Do you want to open a PR to that effect?

from mobx-state-tree.

coolsoftwaretyler avatar coolsoftwaretyler commented on May 29, 2024

This fix is available in 5.4.2 now: https://github.com/mobxjs/mobx-state-tree/releases/tag/v5.4.2, will be shipped with v6 as well.

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.