New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make JavaProxy extends lazy #2031
Conversation
@jasssonpet I though we won't sacrifice TypeScript in the process. When TS Class is wrapped in function you cannot instantiate in. I guess that is why you need |
return global.__native(this); | ||
} | ||
lazyExtend(exports, () => | ||
__decorate([JavaProxy("com.tns.NativeScriptApplication")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 can we find a way to not use __decorate
here? I suggest we kill the JavaProxy
decorator completely, and provide an API that adds a Java-JavaScript mapping. The result could probably look like:
javaClass("com.tns.NativeScriptActivity", () =>
class NativeScriptActivity {
//...
}
);
This way the async thing needed by the snapshot will amount to a change in the javaClass
code.
Oh, and I like the benefit of defining "Java" classes in closures to prevent access to those from the rest of the JS code.
@hshristov I understand it's tough to use TypeScript in such edge cases. According to the ES7 draft specification "A decorator is an expression", but TypeScript is emitting the following error: I'm opening this PR to raise a discussion about the issue so that we can find the best solution for it. |
If we are going to have such 'workarounds` I would vote for writing the whole class in Java and exposing some listener so that we don't need to extend/override it in JavaScript. In my opinion this is probably the best solution. |
b0499da
to
ea8665e
Compare
Hello there, @PanayotCankov helped me to update this old pull request with your suggestions. Please review it one more time and say whether this is acceptable. |
export function lazyExtend<T>(nativeName: string, classExtend: () => T): { value: T } { | ||
let result = { value: null }; | ||
let register = () => result.value = global.__decorate([JavaProxy(nativeName)], classExtend()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, this won't work because the static binding generator isn't able to make the link.
ea8665e
to
0bede36
Compare
Updating the PR one more time. |
-100 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Related to: #1563
ping @atanasovg, @KristinaKoeva
P.S. To view the diff without whitespaces: https://github.com/NativeScript/NativeScript/pull/2031/files?w=1