-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(core, web): migrate web to js_interop to be compatible with WASM #12031
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
Conversation
5413884
to
3568f00
Compare
if (js_util.getProperty(e, 'name') == 'FirebaseError') { | ||
String rawCode = js_util.getProperty(e, 'code'); | ||
FirebaseException _catchJSError(JSObject e) { | ||
if (e.getProperty<JSString?>('name'.toJS)?.toDart == 'FirebaseError') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is valid code, but I'd use an interface to make this more readable. Here's an example:
@JS()
@staticInterop
class JSError {}
extension on JSError {
external String? get name;
external String? get message;
external String? get code;
}
which would let you write simpler code like:
if (e.name == 'FirebaseError')
return r.code ?? ''
and so forth. You may not have access to extension types since that will require >=3.3
, but it's even more concise with one:
extension type Error(JSObject e) {
external String? get name;
external String? get message;
external String? get code;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I've updated this as well.
We don't have access to Dart 3.3 yet, but I'll keep in mind to revisit this once Flutter supports it
|
||
@JS() | ||
external List<AppJsImpl> getApps(); | ||
// List<AppJsImpl> | ||
external JSArray getApps(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once AppJsImpl
is moved to an extension type that implements JSObject
, this can be JSArray<AppJsImpl>
, and a cast won't be needed above, but for now this is the best alternative. :/
@@ -67,7 +67,7 @@ class FirebaseCoreWeb extends FirebasePlatform { | |||
/// own risk as the version might be unsupported or untested against. | |||
@visibleForTesting | |||
String get firebaseSDKVersion { | |||
return context['flutterfire_web_sdk_version'] ?? | |||
return globalContext.getProperty('flutterfire_web_sdk_version'.toJS) ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this works without a toJS
as this returns a JSAny?
iirc. Should this be globalContext.getProperty<JSString?>('flutterfire_web_sdk_version'.toJS)?.toDart
? Or perhaps more concisely, (globalContext['flutterfire_web_sdk_version'] as JSString?)?.toDart
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, surprinsinlgy, declaring it in a variable triggered an analyzer error that wasn't triggered using ??
I've updated with your version
Description
dart:html
topackage:web
dart:js
,dart:js_util
, andpackage:js
todart:js_interop
Related Issues
#12027
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
).This will ensure a smooth and quick review process. Updating the
pubspec.yaml
and changelogs is not required.///
).melos run analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?