Home » JavaScript » JavaScript: Upgrading from MobX 2.6.0 to 2.7.0

About Shannon Behrens

Shannon -JJ Behrens
Catholic, father of eight, open source enthusiast, Python, JavaScript, Ruby, Scala, Go, etc. programmer.

JavaScript: Upgrading from MobX 2.6.0 to 2.7.0

As usual, you should check out the CHANGELOG. However, let me point out a few things specifically:

If you have something like:

observable({
    @computed get someProp() { ... }
});

your code will work in 2.6.0, but in 2.7.0 reactions won’t occur properly. Your tests will end up timing out. It needs to be:

observable({
    get someProp() { ... }
});

Note, there’s no deprecation warning or anything. Also note that this doesn’t apply to situations where you’re using a class. Those will continue working as before.

As of 2.6.2, toJS no longer recurses once it hits something that isn’t observable. Hence, if you have an observable object with a non-observable array with observable objects in it, MobX will only convert the outer object “to JS”. You’ll need to call toJS again for the things inside the non-observable array. This can cause painful to debug errors.

This change was announced for 2.6.0, but it actually happened in 2.6.2 which means that upgrading from 2.6.0 to 2.6.2 isn’t actually as safe as it might appear.

You should also pay careful attention to the section “Automatic inference of computed properties has been deprecated.” However, that’s at least well-documented and results in deprecation warnings. There were a bunch of places where I had code that was passing in a callback. The callback took one parameter. However, in my tests, the callbacks were fake. Hence, they didn’t need that parameter. Our ESLint rules say that you should leave out the parameter in that case since it’s unused. However, once I left out the parameter, MobX kept trying to change the function into a cached, computed getter. The solution was to leave the parameter in place and write the following above each such instance:

// See: https://github.com/mobxjs/mobx/issues/421
// eslint-disable-next-line no-unused-vars

I also added asReference to a few such places when it made sense.

Published on Web Code Geeks with permission by Shannon Behrens, partner at our WCG program. See the original article here: JavaScript: Upgrading from MobX 2.6.0 to 2.7.0

Opinions expressed by Web Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Web Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. Building web apps with Node.js
2. HTML5 Programming Cookbook
3. CSS Programming Cookbook
4. AngularJS Programming Cookbook
5. jQuery Programming Cookbook
6. Bootstrap Programming Cookbook
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments