-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce support for setters for computed properties #463
Comments
How would this work? Isn't the point of |
note to self: use actions. @jeffijoe yes, it can't be used to change the computed, but it could be used to change the observable behind the computed, e.g.: class Distance {
@observable distance = 1
@computed get distanceInMiles() {
return this.distance * 1.6
}
set distanceInMiles(newValue) {
this.distance = newValue / 1.6
}
} |
@mweststrate that's what I imagine as well - will that example you posted not work today? |
That could nicely fit my proposal #421 extendObservable(this, {
distance: 1,
distanceInMiles: computed(
() => this.count * 1.6, // get
miles => this.distance = miles / 1.6, // set
)
});
// or:
extendObservable(this, {
distance: 1,
distanceInMiles: computed({
get: () => this.count * 1.6,
set: miles => this.distance = miles / 1.6,
})
}); |
Currently implementing proposal 1 of @andykog 's example. The ES6 variant class something {
@observable x = 1
@computed get y() {
return this. x * 2
}
set(v) {
this.x = v / 2
}
} See #421 I thin using |
@mweststrate you mean |
Closing, this was released as 2.5.0 |
No description provided.
The text was updated successfully, but these errors were encountered: