See #421. Breaking change so for next major
For migration purposes MobX should warn in a next minor if an function is passed without marking it either with asReference, computed or get
So this change will mark the beginning of 3.0.0?
On Sep 1, 2016 4:21 PM, "Michel Weststrate" [email protected]
wrote:
See #421 https://github.com/mobxjs/mobx/issues/421. Breaking change so
for next majorFor migration purposes MobX should warn in a next minor if an function is
passed without marking it either with asReference, computed or get—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx/issues/532, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIrcmwntQwtWGcj6D5MTA9CHOpAvcsYks5ql0HBgaJpZM4JzJOY
.
Sounds like a welcome change. In my case it shouldn't even break anything. I usually only pass pure data into observable and extendObservable and let the decorators take care of computed, observable and action.
@mweststrate, just to make it clear, we replacing syntax like this:
observable({
x: () => this.y
});
with equal alternative:
observable({
x: computed(() => this.y)
});
right?
Both are still supported, first will be deprecated by this story, idiomatic will be:
observable({
get x() { return this.y }
});
Biggest advantage is that it avoids subtle errors with this (your example for example would have an undefined this)
@mweststrate, basically, ability to define getter in current context may be very useful, and thats how it worked before, so I wouldn't undervalue it, especially in terms of 3.0.0 migration
Ha yeah makes me wonder, is get x () => this.y valid syntax? But anyway computed should still be supported as it is concinsistent with the modifiers approach.
Ha yeah makes me wonder, is
get x () => this.yvalid syntax?
I think, no :-) What makes you assume this?
This change can be tested using [email protected]
Closing this issue as [email protected] is now available, which addresses this issue. Changelog: https://github.com/mobxjs/mobx/blob/mobx3/CHANGELOG.md#300. The changes in more details: https://github.com/mobxjs/mobx/pull/725/files. Feel free to re-open if questions arise!
@mweststrate It is very pleasure to hear that mobx 3.0 will be out. I was taken to this thread by use computed in 2.7.0's warning message:
[mobx] Deprecated:
In MobX 2.* passing a function without arguments to (extend)observable will automatically be inferred to be a computed value.
This behavior is ambiguous and will change in MobX 3 to create just an observable reference to the value passed in.
To disambiguate, please pass the function wrapped with a modifier: use 'computed(fn)' (for current behavior; automatic conversion), or 'asReference(fn)' (future behavior, just store reference) or 'action(fn)'.
Note that the idiomatic way to write computed properties is 'observable({ get propertyName() { ... }})'.
For more details, see https://github.com/mobxjs/mobx/issues/532)in: [email protected]
I just try to install 3.0.0-rc.1, but find it is a bit hard to understand how to upgrade the exist code base to this version. Maybe I should wait?
I also find the change log of 2.7.0, but still confused how to use with decorator(could you explain how to upgrade the example below? Example from the official doc):
class Timer {
@observable start = Date.now();
@observable current = Date.now();
@computed get elapsedTime() {
return (this.current - this.start) + "seconds"
}
@action tick() {
this.current = Date.now()
}
}
maybe create the new series of egghead videos will be great :grin:
Anyone help upgrade this code?
...
@observable panResponder = null;
constructor() {
this.initPanResponder();
}
@action initPanResponder() {
this.panResponder = PanResponder.create({
...
I tried this but then it does not get called correctly:
this.panResponder = computed(()=> PanResponder.create({
@HaveF @indivisable be aware of commenting on closed issues, comments are easily missed :)
@HaveF your example is valid in both MobX 2 & 3
@indivisable
Your question lacks some information to be clear, but I think @observable.ref panResponder = null; is what you need; panResponder is a build in RN thing afaik, so probably you don't want to convert that into an observable itself
@mweststrate Thanks! By simply removing the observable seemed to do the trick.
//@observable panResponder = null;
thanks @mweststrate
Most helpful comment
@HaveF @indivisable be aware of commenting on closed issues, comments are easily missed :)
@HaveF your example is valid in both MobX 2 & 3
@indivisable
Your question lacks some information to be clear, but I think
@observable.ref panResponder = null;is what you need; panResponder is a build in RN thing afaik, so probably you don't want to convert that into an observable itself