Skip to content
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

Small decorators optimization #2773

Merged
merged 4 commits into from
Feb 2, 2021
Merged

Small decorators optimization #2773

merged 4 commits into from
Feb 2, 2021

Conversation

urugator
Copy link
Collaborator

@urugator urugator commented Feb 2, 2021

Avoids an annotation object copy per decorator application.
Since mixing decorators/annotations is not officialy supported (it may actually work, but there are not tests for it), annotation itself doesn't have to know that it's decorator - once target has storedAnnotationsSymbol - meaning at least one decorator was applied - we assume that all annotations are decorators.
If one would try to mix decorators/annotation (unsupported), this change breaks check for non-existing prop (it won't throw).
The decorator detection could be made a bit more realiable by changing make_ to accept additional isDecorator param and calling: adm.make_(key, annotations![key], !annotations) from makeObservable.
Not sure if worth it ATM, but at least good to have this noted here.

EDIT: Changed to check for specific key, should work equally well in this case.

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2021

🦋 Changeset detected

Latest commit: ffb60fc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx Patch

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

@@ -61,7 +62,7 @@ function make_(adm: ObservableObjectAdministration, key: PropertyKey): void {
}
if (annotated) {
recordAnnotationApplied(adm, this, key)
} else if (!this.isDecorator_) {
} else if (!adm.target_[storedAnnotationsSymbol]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I misunderstand the logic, but should this be adm.target_[storedAnnotationsSymbol]?.[key]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not a bad idea :) I think I was worried it would return false if recordAnnotationApplied is called before (it removes the annotation from adm.target_[storedAnnotationsSymbol]), but that can't happen here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants