Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normative: Add initializer callback for side effects (#165)
* Normative: Add `kind: "initializer"` for side effects Many decorators will want to perform a side effect when instantiating a class, for example: - To select [[Set]] rather than [[DefineOwnProperty]] semantics for defining a field - To store the field in an entirely different place, neither an ordinary property or private field (e.g., MobX stores some fields in a Map) - To register the instance under construction in some way (e.g., from a class decorator). "Instance finishers" have been proposed for this purpose, but it's not clear when to run such a finisher. For many use cases (e.g., interacting with the DOM), an instance "starter" is just as good, due to run-to-completion semantics. This patch permits decorators to create elements of the form { kind: "initializer", placement: "own", initializer: fn } to be used purely for their side effect, with evaluation semantics and ordering identical to fields, and interspersed with them in evaluation order. * Fix most of the errors from review * Normative: Throw an exception on a missing initializer * Normative: Permit prototype and static initializers Also move error checks in ToElementDescriptor to happen ASAP * Normative: Throw a TypeError if an initializer returns undefined * Documentation for initializers * Add Oxford commas
- Loading branch information
Showing
2 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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