01:20 | <Mathieu Hofman> | Public metadata can be achieved with (1) by using a second decorator. Private metadata can be achieved with (3) by storing an object in the public metadata that is only used as a WeakMap key. can't public metadata be achieved with a single decorator also adding a static initializer? |
01:21 | <Mathieu Hofman> | Which also raises the question of whether the opaque object from (1) actually needs to be installed on the class, or if that could be done by an explicit decorator. |
01:24 | <Mathieu Hofman> | With #465 public and private metadata can still be achieved, but would depend on userland implementations (similar to reflect-metadata ):
-
Private Metadata: use addInitializer(cb, "class") to add a class "extra" initializer regardless of decorator placement. The callback receives the constructor as the this binding and can store the constructor in a WeakMap.
-
Public Metadata: use addInitializer(cb, "class") to add a class "extra" initializer regardless of decorator placement. The callback receives the constructor as the this binding can can store the metadata in a property on the constructor. Caveat: for performance reasons, the property should be declared on the class as well.
The limitation is for multiple decorators working together. We need a context object to key on, and the common class constructor is only available after the extra initializers have been all called |