I have implemented a TypeScript class Decorator function which allows me to decorate classes of the same kind. If Decorator is present above some class, that class should look into Decorator stored values for highest priority class of that kind. If newly decorated class has smaller priority of currently stored highest priority class, that new class should become that stored class.
In other words, all decorated classes of some kind should become the same as highest priority class.
Let’s say I have GeneralClassA(priority 0), SpecificClassA(priority 1) and ClassA(priority 0).
All classes should point to the same class, and that’s the SpecificClassA, because it has highest priority.
The plan is to have General classes already predefined and decorated, but allow the developer to define Specific class and decorate it as a higher priority class.
Everything works correctly, but the issue I have is that decorated highest priority class must be declared BEFORE all other decorated classes. Otherwise, decorated classes, declared BEFORE the highest priority class, won’t be overridden.
Is there a way to retroactively override all decorated classes (I can store their constructors), once the higher priority class gets declared and decorated? Or somehow declare all Specific classes before everything?
I have replicated my problem here: StackBlitz
I have tried to store all of my decorated classes, and once the higher priority class got decorated, I tried to Object.assign one constuctor and prototype to another. That didn’t work, and even if it did, what if I already used the lower priority class somewhere before I even declared higher priority class (class declaration only happens once the class is being used somewhere, at import).
I would like to get a suggestion how to initialize (declare) all Specific classes before everything, maybe even before main.js file ever get’s executed.