Note that there are some explanatory texts on larger screens.

plurals
  1. POdart js-interop FunctionProxy callback relationship to js.context
    text
    copied! <p>I have a Dart js-interop callback that in turn takes a javascript callback as an argument. The dart callback implementation looks like this:</p> <pre class="lang-dart prettyprint-override"><code>void callBackToDartCode(String query, js.FunctionProxy completionCallback) { js.context.completionCallback = completionCallback; doSomethingAscyn(query).then( (result) { // hand the query result back to the javascript code js.context.completionCallback(js.map(result)); }); </code></pre> <p>This works. The key to making this work is to save the FunctionProxy in the js.context so that it is available when it comes time to execute it in the async "then" method. This line of code is important:</p> <pre class="lang-dart prettyprint-override"><code>js.context.completionCallback = completionCallback; </code></pre> <p>If that's not done then the completeCallback is not retained and hence cannot be called when the async operation completes.</p> <p>I have not seen examples like this and I am not sure I have really done this properly.</p> <p>It raises questions:</p> <ol> <li>How do I disassociate "completeCallback" from js.context after I've called it? Does it remain associated with js.context forever?</li> <li>It appears there will be conflicting use of the name "completionCallback" within js.context if multiple async operations are in progress at the same time. That strikes me as a common problem. Does js-interop have a way to deal with that or is it my job to manage that?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload