-
I have read the document https://mobx.js.org/subclassing.html, and I understand the But I'm not sure the reason. In fact, I try to comment out this line . It works as expects. 🤔
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 15 replies
-
The situation where the extended classes are abstract (can't be instantiated) - meaning you can call |
Beta Was this translation helpful? Give feedback.
-
That's awesome! Thank you!
Fwiw this seems like a common ask from users, i.e. I nearly opened a brand
new discussion/issue asking the same question (just to ask specifically
what makeAutoObservables sharp edges are with subclasses to verify whether
we could avoid them and afaict we are/can).
What do you think about addong your snippet to mobx with an appropriate
name and docs of "only use this if you know what you are doing in these x
scenarios"?
Or if anything maybe a link in makeAutoObservables docs that "if you really
want subclasses see this gist that you can copy/paste and be on your own".
:-)
|
Beta Was this translation helpful? Give feedback.
-
I'm getting the message: I'm doing maintenance on an app that had development frozen for 2 years, so it's probably a migration issue with new package versions. Unfortunately, there is no stack trace or other hint what / where exactly it goes wrong, this would be nice to have. I do have some subclassing, but that's only a common constructor to fill the stores with data. It used to work. I'll grab the docs and see if I can solve it. If I encounter something weird I'll post it here. For now, thanks for being a rubber duck :) |
Beta Was this translation helpful? Give feedback.
The situation where the extended classes are abstract (can't be instantiated) - meaning you can call
makeAutoObservable
only once in the "subbest" class - is kinda supportable, the problem is if the extended class is egReact.Component
- in such casemakeAutoObservable
should ignore all it's fields and prototype.In other cases, you must be able to call
makeAutoObservable
multiple times on the same object - this is problematic, because we don't know which fields of the object were already annotated and which were not (this is mostly due to the ability to provideoverrides
option tomakeAutoObservable
or when you would combine it withmakeObservable
). It would also prevented some optimizat…