Conversation
…d class members to more closely align the object shape with what a user wrote
0ad095c to
505c0c0
Compare
- add the ability to finalize `@signal` fields without a class decorator by defining a `@signal #finalize` field after all fields are defined - refactor `@signal` on getters/setters to work without a class decorator (add support for `#private` getters/setters, but now requires the `@signal` decorator to be placed on both the getter and the setter, otherwise it won't work and an error will be shown in console) - add support for public and `#private` auto accessors - organize code and tests organize files and tests
387d682 to
5d65660
Compare
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.
BREAKING: There's a breaking change on how to apply
@signalto a getter/setter, see below.@signaldecorator descriptors in the same locations as decorated class members to more closely align the object shape with what a user wrote. For example if a field was decorated with@signal, the signal descriptor will be on the instance, and if an auto or getter/setter accessor was decorated with@signalthen the descriptor will be on the prototype@signalno longer result in own properties on instances, but result in a prototype property. For example, any checks likeObject.hasOwn(this, 'prop')for a property namedpropdefined as@signal get prop() {}will now returnfalseinstead oftrue. Features likeObject.assignwill no longer work on those properties. Etc. If you need the properties to be own, migrate to using@signal propinstead of a getter/setter, or update the dependent code to do something else.@signalfields without a class decorator by defining@signal #finalizeafter all fields are defined. For example instead of this,constructorruns, making it possible to rely on the signal fields insideconstructor. For example the following will not work when using the@reactiveclass decorator approach:@signal #finalizecomes after all class field definitions; any fields that come after@signal #finalizewill not be signalified.It is up to you which form you prefer. If you do not need the signals within
constructor, you might like the aesthetic look of the@reactiveclass decorator more than an unused#finalizefield, or, at an implementation level you might like the purity of the@signal #finalizeapproach because it does not make a subclass like@reactivedoes.@signalon getters/setters to work without a class decorator (adding support for#privategetters/setters, but now requiring the@signaldecorator to be placed on both the getter and the setter otherwise it won't work and an error will be shown in console)@reactiveclass decorator, but the@signaldecorator must now be placed on both the getter and setter of a property definition:@signalto your getter/setter so that both are decorated. Optionally delete the@reactivedecorator from your class if you are using the new@signal #finalizeor no fields at all (f.e. only autoaccessors).#privategetters/setters:#privateauto accessors. For example, and as an alternative to@reactiveor@signal #finalizeapproaches, we can now write "auto accessor" fields:#private"auto accessor" fields:The main benefit of this update is that we now have a way to apply
@signalto#privateproperties, but note that only auto accessors and getters/setters are supported when it comes to making them#private, and fields cannot not be private due to the current version of the decorator spec: