diff --git a/flutter_package/lib/src/interface_web.dart b/flutter_package/lib/src/interface_web.dart index 4210136e..07a2ab79 100644 --- a/flutter_package/lib/src/interface_web.dart +++ b/flutter_package/lib/src/interface_web.dart @@ -15,8 +15,8 @@ void setCompiledLibPathReal(String path) { Future prepareInterfaceReal( AssignRustSignal assignRustSignal, ) async { - // Prepare JavaScript bindings. - prepareBindings(); + // Load the JavaScript module. + await loadJsFile(); // Listen to Rust via JavaScript. rinfBindingsObject['send_rust_signal_extern'] = ( @@ -32,9 +32,6 @@ Future prepareInterfaceReal( } assignRustSignal(messageId, messageBytes, binary); }; - - // Load the JavaScript module. - await loadJsFile(); } void startRustLogicReal() { diff --git a/flutter_package/lib/src/load_web.dart b/flutter_package/lib/src/load_web.dart index 3044926c..ec38690c 100644 --- a/flutter_package/lib/src/load_web.dart +++ b/flutter_package/lib/src/load_web.dart @@ -14,23 +14,20 @@ bool wasAlreadyLoaded = false; js.JsObject rinfBindingsObject = js.context['rinfBindings']; js.JsObject wasmBindingsObject = js.context['wasmBindings']; -void prepareBindings() { +Future loadJsFile() async { // When Dart performs hot restart, // the `rinfBindings` JavaScript object is already defined // as a global JavaScript variable. wasAlreadyLoaded = js.context.hasProperty('rinfBindings'); - if (!wasAlreadyLoaded) { + + if (wasAlreadyLoaded) { + return; + } else { // Create the namespace JavaScript object. // This namespace object is used by Rust // to call functions defined in Dart. js.context['rinfBindings'] = js.JsObject.jsify({}); } -} - -Future loadJsFile() async { - if (wasAlreadyLoaded) { - return; - } final loadCompleter = Completer(); rinfBindingsObject['completeRinfLoad'] = loadCompleter.complete;