Skip to content

Commit

Permalink
Merge two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Oct 23, 2024
1 parent 97e6d22 commit 0fb6365
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
7 changes: 2 additions & 5 deletions flutter_package/lib/src/interface_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void setCompiledLibPathReal(String path) {
Future<void> prepareInterfaceReal(
AssignRustSignal assignRustSignal,
) async {
// Prepare JavaScript bindings.
prepareBindings();
// Load the JavaScript module.
await loadJsFile();

// Listen to Rust via JavaScript.
rinfBindingsObject['send_rust_signal_extern'] = (
Expand All @@ -32,9 +32,6 @@ Future<void> prepareInterfaceReal(
}
assignRustSignal(messageId, messageBytes, binary);
};

// Load the JavaScript module.
await loadJsFile();
}

void startRustLogicReal() {
Expand Down
13 changes: 5 additions & 8 deletions flutter_package/lib/src/load_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ bool wasAlreadyLoaded = false;
js.JsObject rinfBindingsObject = js.context['rinfBindings'];
js.JsObject wasmBindingsObject = js.context['wasmBindings'];

void prepareBindings() {
Future<void> 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<void> loadJsFile() async {
if (wasAlreadyLoaded) {
return;
}

final loadCompleter = Completer<void>();
rinfBindingsObject['completeRinfLoad'] = loadCompleter.complete;
Expand Down

0 comments on commit 0fb6365

Please sign in to comment.