Open MulverineX opened 5 months ago
https://github.com/openwebf/mercury/blob/main/mercury%2Fexample%2Flib%2Fmain.dart
https://github.com/RefractureMedia/refracture-music/blob/main/packages%2Fclient-flutter%2Flib%2Fapp%2Fcore.dart https://github.com/RefractureMedia/refracture-music/blob/main/packages%2Fclient-flutter%2Flib%2Fmain.dart#L8
@MulverineX From these examples it is not clear how one can get the results back from javascript calls. Perhaps with MercuryDispatcher
but the workings of it I did not manage to figure out. Any help is appreciated
@mochar
final result = evaluateScripts('path.to.function("bar")')`
This is how Flutter land issues events to JS land and receives a response back synchronously
controller.context.dispatcher?.subscribe('example', (args) {
evaluateScripts(`${args[0]['callback']}('hellooooo')`)
});
let baz = (foo) => console.log(foo)
mercury.dispatcher.dispatch('example', { callback: `baz`});
This is how JS land issues events to Flutter land and receives a response back with a callback (there is no synchronous response mechanism)
If you would like to have synchronous response from Dart somehow for simpler code, you're welcome to create a feature request issue for that, just keep in mind it won't be a priority, it's more likely it'll be implemented if we receive a PR. Remember that you can wrap callback systems like this with a Promise to make it cleaner in asynchronous functions.
@MulverineX Thanks a lot!!
Is there an example we can look at in the meantime?