Make Decorators workable for Abstract Classes and Getter Properties
CMCDragonkai opened this issue · 6 comments
Specification
Appears to be problems using async init decorators on abstract classes. Should investigate if this is the case and add tests.
Tasks
- - Prototype the application of decorator on abstract classes
- - Fix
- - Add abstract class test including extended child class being able to use the decorated methods
Also getters don't seem to work here too, there's an opportunity to create a decorator for getters too in case we want to use it.
Right now we have just changed to using normal classes in PK, so this is not urgent atm. @tegefaulkes so we'll leave this to post testnet deployment.
Decorators won't work on abstract classes even with the 4.2 addition of the abstract
modifier: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures.
Seems like the way the decorators are defined would need work. And this is pretty experimental.
However the work around is simple.
Either turn the abstract classes into normal classes, or only use the decorator on the derived classes.
I've made it work for abstract classes now. It turns out that it is a bug to use the decorator on both the parent and child class, it causes problems.
If you want to use the decorator on parent and child classes, you must choose either to use the decorator on the parent or to use the decorator on the child.
Using it on both results in incorrect execution. And this is because parent and child are the same instance, and once the child calls destroy, then the parent's destroy cannot be called because the class is already destroyed.
For our GRPCClient situation, the GRPCClient
should be abstract
and not wrapped in a decorator. But GRPCClientClient
and GRPCClientAgent
both should be wrapped in the decorator.
This is now done. Commit cebcbdc supports getters and setters.
Released 1.1.0
of js-async-init
. Updating in js-polykey
.