-
-
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
add warn for extending builtins #2769
Conversation
🦋 Changeset detectedLatest commit: 781de7a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
bba9fe5
to
e962f6a
Compare
Thanks for the PR, but please try to handle it like this:
if (hasProp(target, $mobx)) {
if (__DEV__ && !(getAdministration(target) instanceof ObservableObjectAdministration)) {
// Something like
die(`Cannot convert '${getDebugName(target)}' into observable object: The target is already observable of different type. Extending builtins is not supported.`)
}
return target
} That should cover other unsupported cases like |
@urugator Yes, sir. 😃 |
@urugator Hi, sir. Did we need test all types? I found that only
extendObservableMay be it's only use for function/object ? Any suggestion to test it ?makeAutoObservable// https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/api/makeObservable.ts#L50-L55
if (__DEV__) {
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
👇 // user can't extending builtin, so don't need check more
die(`'makeAutoObservable' can only be used for classes that don't have a superclass`)
if (isObservableObject(target))
die(`makeAutoObservable can only be used on objects not already made observable`)
} |
It's not about preventing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks for making this change!
Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatednpm run perf
)PR Background
issue -> fix #2765
Add friendly warn for extending builtins action.
Current 👇
After 👇