Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Idea: auto-wrap callbacks in allowInterop #78

Open
ditman opened this issue Jan 9, 2020 · 0 comments
Open

Idea: auto-wrap callbacks in allowInterop #78

ditman opened this issue Jan 9, 2020 · 0 comments

Comments

@ditman
Copy link
Contributor

ditman commented Jan 9, 2020

In the same way we're wrapping returned Promises in promiseToFuture, so they can be directly used in Dart as Futures, I think we could also wrap callbacks passed as parameters with allowInterop so the users' code in Dart doesn't need to.

On something like:

then(onInit: (googleAuth: GoogleAuth) => any, onFailure?: (reason: {error: string, details: string}) => any): any;

This generates:

external dynamic then(dynamic onInit(GoogleAuth googleAuth),
    [dynamic onFailure(dynamic /*{error: string, details: string}*/ reason)]);

Which in Dart you need to use as:

auth.then(allowInterop((GoogleAuth googleAuth) {
  // onSuccess
}), allowInterop((dynamic reason) {
  // onError
}));

It'd be way more pleasing (and easier to read) to be able to just do:

auth.then((GoogleAuth googleAuth) {
  // onSuccess
}, (dynamic reason) {
  // onError
});

I understand the generator itself can't know if there's going to be a negative performance impact from calling allowInterop automatically, but it'd be cool if there was a flag to control this behavior on a per-usage basis.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant