Replies: 6 comments 4 replies
-
Hi @lbwexler Have you tried I've never tried but I think the following should work: class Store {
item = observable.box(1)
constructor() {
makeAutoObservable(this)
}
} The following probably also work, but you won't get correct TS types: class Store {
item = 1; // TS will think it's a regular primitive, not an object with getter/setter
constructor() {
makeObservable(this, { item: observable.box })
}
} |
Beta Was this translation helpful? Give feedback.
-
Atm it's not possible to implement such decorator due to how decorators and field initializers work. Unless you would call something extra in |
Beta Was this translation helpful? Give feedback.
-
Thanks for the really fast and thoughtful replies! So I was actually able to get something to work, doing something similar to your first suggestion urugator! We want to allow the following minimal property definition:
First we have the following:
and then, we "override" the native
|
Beta Was this translation helpful? Give feedback.
-
Thanks! Note we are currently using babel transpiler and we allow it to process the decorators using its `plugin-proposal-decorators'. So we have the initializer. (We do use Typescript, but not for the decorators.) |
Beta Was this translation helpful? Give feedback.
-
You can, yes, and that is how we originally had it, but that leaves the property definition on the prototype. To get the property as enumerable 'on the instance' (the way you would expect for a bare-bones class property.), you need to define it in the constructor. |
Beta Was this translation helpful? Give feedback.
-
https://www.youtube.com/watch?v=8Ab3ArE8W3s&t=2012s |
Beta Was this translation helpful? Give feedback.
-
Am looking to use the very useful
@box
annotation created by sonaye, several years back, and discussed in this interesting thread.The source is quite simple, and is below -- however, I am unable to make this work on mobx6.
Anybody still using this? Any pointers -- thought I saw some reference to an update here, but unable to find it.
(from 'sonaye')
Beta Was this translation helpful? Give feedback.
All reactions