Skip to content

Commit

Permalink
fix(core, web): fix some JS interop that were incorrectly migrated (#…
Browse files Browse the repository at this point in the history
…12239)

* fix(core, web): fix some JS interop that were incorrectly migrated

* test

* tests

* test

* tests
  • Loading branch information
Lyokone authored Feb 1, 2024
1 parent 110e5f6 commit e38a510
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// them public.

import 'package:firebase_core/firebase_core.dart';

import 'src/interop_shimmer.dart'
if (dart.library.js) 'package:firebase_core_web/firebase_core_web_interop.dart'
as core_interop;
Expand Down
4 changes: 2 additions & 2 deletions packages/_flutterfire_internals/lib/src/interop_shimmer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// BSD-style license that can be found in the LICENSE file.

// A library that mimicks package:firebase_core_web/firebase_core_web_interop.dart
// for platforms that do not target dart2js
// for platforms that do not target dart2js``

abstract class FirebaseError {
String get code;
String get message;
String get name;
String get stack;
Object get serverResponse;
dynamic get serverResponse;
}
2 changes: 1 addition & 1 deletion packages/_flutterfire_internals/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/_flutte
version: 1.3.17

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

dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/_flutterfire_internals/test/guard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _FirebaseError implements FirebaseError {
String get name => '';

@override
Object get serverResponse => '';
String get serverResponse => '';

@override
String get stack => '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ FirebaseAppPlatform _createFromJsApp(firebase.App jsApp) {
/// Returns a [FirebaseOptions] instance from [firebase.FirebaseOptions].
FirebaseOptions _createFromJsOptions(firebase.FirebaseOptions options) {
return FirebaseOptions(
apiKey: options.apiKey,
authDomain: options.authDomain,
databaseURL: options.databaseURL,
projectId: options.projectId,
storageBucket: options.storageBucket,
messagingSenderId: options.messagingSenderId,
appId: options.appId,
measurementId: options.measurementId,
apiKey: options.apiKey.toDart,
authDomain: options.authDomain.toDart,
databaseURL: options.databaseURL.toDart,
projectId: options.projectId.toDart,
storageBucket: options.storageBucket.toDart,
messagingSenderId: options.messagingSenderId.toDart,
appId: options.appId.toDart,
measurementId: options.measurementId.toDart,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class FirebaseCoreWeb extends FirebasePlatform {
// check to see if options are roughly identical (so we don't unnecessarily
// throw on minor differences such as platform specific keys missing,
// e.g. hot reloads/restarts).
if (options.apiKey != app!.options.apiKey ||
options.databaseURL != app.options.databaseURL ||
options.storageBucket != app.options.storageBucket) {
if (options.apiKey != app!.options.apiKey.toDart ||
options.databaseURL != app.options.databaseURL.toDart ||
options.storageBucket != app.options.storageBucket.toDart) {
// Options are different; throw.
throw duplicateApp(defaultFirebaseAppName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class App extends JsObjectWrapper<AppJsImpl> {
static final _expando = Expando<App>();

/// Name of the app.
String get name => jsObject.name;
String get name => jsObject.name.toDart;

/// Options used during [firebase.initializeApp()].
FirebaseOptions get options => jsObject.options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@JS('firebase_core')
library firebase_interop.core.app;

import 'dart:js_interop';

import 'package:js/js.dart';

import 'core_interop.dart';
Expand All @@ -17,6 +19,6 @@ import 'core_interop.dart';
abstract class AppJsImpl {}

extension AppJsImplExtension on AppJsImpl {
external String get name;
external JSString get name;
external FirebaseOptions get options;
}
38 changes: 28 additions & 10 deletions packages/firebase_core/firebase_core_web/lib/src/interop/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,40 @@ App initializeApp({
return App.getInstance(
firebase_interop.initializeApp(
firebase_interop.FirebaseOptions(
apiKey: apiKey,
authDomain: authDomain,
databaseURL: databaseURL,
projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId,
measurementId: measurementId,
appId: appId,
apiKey: apiKey?.toJS,
authDomain: authDomain?.toJS,
databaseURL: databaseURL?.toJS,
projectId: projectId?.toJS,
storageBucket: storageBucket?.toJS,
messagingSenderId: messagingSenderId?.toJS,
measurementId: measurementId?.toJS,
appId: appId?.toJS,
),
name,
name.toJS,
),
);
}

App app([String? name]) {
return App.getInstance(
name != null ? firebase_interop.getApp(name) : firebase_interop.getApp(),
name != null
? firebase_interop.getApp(name.toJS)
: firebase_interop.getApp(),
);
}

class FirebaseError {
final String code;
final String message;
final String name;
final String stack;
final dynamic serverResponse;

FirebaseError({
required this.code,
required this.message,
required this.name,
required this.stack,
required this.serverResponse,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ external JSArray getApps();
external String get SDK_VERSION;

@JS()
external AppJsImpl initializeApp(FirebaseOptions options, [String? name]);
external AppJsImpl initializeApp(FirebaseOptions options, [JSString? name]);

@JS()
external AppJsImpl getApp([String? name]);
external AppJsImpl getApp([JSString? name]);

@JS()
external JSPromise deleteApp(AppJsImpl app);
Expand All @@ -35,16 +35,16 @@ external JSPromise deleteApp(AppJsImpl app);
/// In addition to a message string, it contains a string-valued code.
///
/// See: <https://firebase.google.com/docs/reference/js/firebase.FirebaseError>.
@JS()
@JS('FirebaseError')
@anonymous
@staticInterop
abstract class FirebaseError {}
abstract class FirebaseErrorJSImpl {}

extension FirebaseErrorExtension on FirebaseError {
external String get code;
external String get message;
external String get name;
external String get stack;
extension FirebaseErrorExtension on FirebaseErrorJSImpl {
external JSString get code;
external JSString get message;
external JSString get name;
external JSString get stack;

/// Not part of the core JS API, but occasionally exposed in error objects.
external JSAny get serverResponse;
Expand All @@ -56,32 +56,32 @@ extension FirebaseErrorExtension on FirebaseError {
@staticInterop
class FirebaseOptions {
external factory FirebaseOptions({
String? apiKey,
String? authDomain,
String? databaseURL,
String? projectId,
String? storageBucket,
String? messagingSenderId,
String? measurementId,
String? appId,
JSString? apiKey,
JSString? authDomain,
JSString? databaseURL,
JSString? projectId,
JSString? storageBucket,
JSString? messagingSenderId,
JSString? measurementId,
JSString? appId,
});
}

extension FirebaseOptionsExtension on FirebaseOptions {
external String get apiKey;
external set apiKey(String s);
external String get authDomain;
external set authDomain(String s);
external String get databaseURL;
external set databaseURL(String s);
external String get projectId;
external set projectId(String s);
external String get storageBucket;
external set storageBucket(String s);
external String get messagingSenderId;
external set messagingSenderId(String s);
external String get measurementId;
external set measurementId(String s);
external String get appId;
external set appId(String s);
external JSString get apiKey;
external set apiKey(JSString s);
external JSString get authDomain;
external set authDomain(JSString s);
external JSString get databaseURL;
external set databaseURL(JSString s);
external JSString get projectId;
external set projectId(JSString s);
external JSString get storageBucket;
external set storageBucket(JSString s);
external JSString get messagingSenderId;
external set messagingSenderId(JSString s);
external JSString get measurementId;
external set measurementId(JSString s);
external JSString get appId;
external set appId(JSString s);
}

0 comments on commit e38a510

Please sign in to comment.