I've been experimenting Typescript Decorators recently to try solving a "problem" I have within my application. I'm using a JS bridge to feed TS code to both Android and iOS, and at the moment we declare functions like this:
index.js
import foo from './bar'
global.App = function() {
this.foo = foo;
};
The above will make the foo function to be available on the native side of the bridge
I wanted to write a decorator to apply on that foo method which would "register" itself on the global.App but I've failed in that task.
Here's the decorator that works:
export const Task = (target, propertyKey, descriptor) => {
let originalMethod = descriptor.value;
descriptor.value = (...args) => originalMethod.apply(target, args);
if (!global.App) {
global.App = function () {
this.foo = descriptor.value;
};
}
return descriptor;
}
How could I add another method to that global.App function?