Skip to content

feat(app_installation, web): migrate web to js_interop to be compatible with WASM #12220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:js_interop';

import 'package:firebase_core_web/firebase_core_web_interop.dart';
import 'package:js/js.dart';

import 'installations_interop.dart' as installations_interop;

Expand All @@ -32,23 +32,26 @@ class Installations
: super.fromJsObject(jsObject);

Future<void> delete() =>
handleThenable(installations_interop.deleteInstallations(jsObject));
(installations_interop.deleteInstallations(jsObject)).toDart;

Future<String> getId() =>
handleThenable(installations_interop.getId(jsObject));
Future<String> getId() => (installations_interop.getId(jsObject))
.toDart
.then((value) => value! as String);

Future<String> getToken([bool forceRefresh = false]) =>
handleThenable(installations_interop.getToken(jsObject, forceRefresh));
(installations_interop.getToken(jsObject, forceRefresh.toJS))
.toDart
.then((value) => value! as String);

Func0? _onIdChangedUnsubscribe;
JSFunction? _onIdChangedUnsubscribe;

StreamController<String>? _idChangeController;

Stream<String> get onIdChange {
if (_idChangeController == null) {
final wrapper = allowInterop((String id) {
final wrapper = ((String id) {
_idChangeController!.add(id);
});
}).toJS;

void startListen() {
assert(_onIdChangedUnsubscribe == null);
Expand All @@ -57,7 +60,7 @@ class Installations
}

void stopListen() {
_onIdChangedUnsubscribe!();
_onIdChangedUnsubscribe?.callAsFunction();
_onIdChangedUnsubscribe = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,37 @@
@JS('firebase_installations')
library firebase_interop.installations;

import 'dart:js_interop';

import 'package:firebase_core_web/firebase_core_web_interop.dart';
import 'package:js/js.dart';

@JS()
@staticInterop
external InstallationsJsImpl getInstallations([AppJsImpl? app]);

@JS()
external PromiseJsImpl<String> getId(InstallationsJsImpl installations);
@staticInterop
external JSPromise /* String */ getId(InstallationsJsImpl installations);

@JS()
external PromiseJsImpl<String> getToken(InstallationsJsImpl installations,
[bool? forceRefresh]);
@staticInterop
external JSPromise /* String */ getToken(InstallationsJsImpl installations,
[JSBoolean? forceRefresh]);

@JS()
external PromiseJsImpl<void> deleteInstallations(
@staticInterop
external JSPromise /* void */ deleteInstallations(
InstallationsJsImpl installations);

@JS()
external Func0 onIdChange(
InstallationsJsImpl installations, Func1<String, void> forceRefresh);
@staticInterop
external JSFunction onIdChange(
InstallationsJsImpl installations, JSFunction forceRefresh);

@JS('Installations')
abstract class InstallationsJsImpl {
@staticInterop
abstract class InstallationsJsImpl {}

extension InstallationsJsImplExtension on InstallationsJsImpl {
external AppJsImpl get app;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage: https://github.com/firebase/flutterfire/tree/master/packages/firebase_
repository: https://github.com/firebase/flutterfire/tree/master/packages/firebase_app_installations/firebase_app_installations_web

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.2.0 <4.0.0'
flutter: '>=3.3.0'

dependencies:
Expand All @@ -18,7 +18,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
js: ^0.6.3

web: ^0.5.1
dev_dependencies:
firebase_core_platform_interface: ^5.0.0
flutter_test:
Expand Down