Repository navigation
Conversation
`context.name` of a private member is only its description, like "#value". The 2022.3 `@observable` and `@computed` decorators used it as the key in the administration, so a class and its subclass that both declare a private member with that name shared one entry: the parent's `#value` read and wrote the subclass's value. Private members are now kept under a symbol of their own. Debug names are unchanged.
🦋 Changeset detectedLatest commit: d1ddc46 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 |
Open
3 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
context.nameof a private member is only its description, like"#value". The 2022.3@observableand@computeddecorators use it as the key in the administration, so two separate private members that happen to have the same name, one on a class and one on its subclass, end up under one key:A write to the parent's field changes the subclass's field as well. A private
@observable accessoron the parent and a private@computedgetter with the same name on the subclass collide the same way: the parent's field returns the computed value.Private members now get a key of their own, a symbol that carries the name as its description. Public members keep
context.name. Debug names are unchanged (Store@1.#value).Behavior change
A private member could not be addressed reliably by its name before, because the name is not unique per object. Now it cannot be addressed by name at all:
isObservableProp(obj, "#value"),getAtom(obj, "#value")andobserve(obj, "#value", ...)no longer find it, and the change events of a private field that object-levelobserveandspyreceive carry the symbol asname.toJSalready left private fields out.Tests
stage3-decorators-inheritance.ts. The accessor/accessor and accessor/computed cases fail on main. The computed/computed case already passed, because the override handling from fix(mobx): create overridden @computed eagerly so super reads get the parent value #4756 covers it, and now guards the new key.toJStest looked up the internal lazy map by"#secret"and is updated to the new key.mobxsuite passes (805 tests).Code change checklist
/docs: no documented behavior changesnpm -w mobx run test:performance): only the key of private members changes, the read and write paths are the same