feat(core, web): migrate web to js_interop to be compatible with WASM#12031
feat(core, web): migrate web to js_interop to be compatible with WASM#12031
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.
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.
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.
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. :/
| @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.
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.
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:htmltopackage:webdart:js,dart:js_util, andpackage:jstodart:js_interopRelated 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.yamland 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?