Skip to content
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

feat(web): remove the dependency on package:js in favor of dart:js_interop #12534

Merged
merged 25 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests?
  • Loading branch information
Lyokone committed Mar 26, 2024
commit 0ab7006a31bb69ad68d939898a8d385ce031c8e3
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class DatabaseReference<T extends database_interop.ReferenceJsImpl>
/// Overwrites any existing data at actual location and all child locations.
///
/// The [value] must be a Dart basic type or the error is thrown.
Future set(Object value) =>
database_interop.set(jsObject, value.toJSBox).toDart;
Future set(Object? value) =>
database_interop.set(jsObject, value?.toJSBox).toDart;

/// Sets a priority for data at actual database location.
///
Expand All @@ -154,8 +154,8 @@ class DatabaseReference<T extends database_interop.ReferenceJsImpl>
/// The [newVal] must be a Dart basic type or the error is thrown.
/// The [newPriority] must be a [String], [num] or `null`, or the error
/// is thrown.
Future setWithPriority(Object newVal, newPriority) => database_interop
.setWithPriority(jsObject, newVal.toJSBox, newPriority)
Future setWithPriority(Object? newVal, newPriority) => database_interop
.setWithPriority(jsObject, newVal?.toJSBox, newPriority)
.toDart;

/// Atomically updates data at actual database location.
Expand Down Expand Up @@ -541,7 +541,7 @@ class DataSnapshot
bool exists() => jsObject.exists().toDart;

/// Exports the contents of the DataSnapshot as a Dart object.
dynamic exportVal() => dartify(jsObject.exportVal());
dynamic exportVal() => jsObject.exportVal().dartify();

/// Enumerates the top-level children of the DataSnapshot in their query-order.
/// [action] is called for each child DataSnapshot.
Expand All @@ -561,10 +561,10 @@ class DataSnapshot
bool hasChildren() => jsObject.hasChildren().toDart;

/// Returns Dart value from a DataSnapshot.
dynamic val() => dartify(jsObject.val());
dynamic val() => (jsObject.val()).dartify();

/// Returns a JSON-serializable representation of this object.
dynamic toJson() => dartify(jsObject.toJSON());
dynamic toJson() => (jsObject.toJSON()).dartify();
}

/// The OnDisconnect class allows you to write or clear data when your client
Expand All @@ -588,20 +588,20 @@ class OnDisconnect
/// when the client is disconnected.
///
/// The [value] must be a Dart basic type or the error is thrown.
Future set(value) => (jsObject.set(jsify(value))).toDart;
Future set(Object? value) => (jsObject.set((value)?.toJSBox)).toDart;

/// Ensures the data for actual location is set to the specified [value]
/// and [priority] when the client is disconnected.
///
/// The [value] must be a Dart basic type or the error is thrown.
/// The [priority] must be a [String], [num] or `null`, or the error is thrown.
Future setWithPriority(value, priority) =>
(jsObject.setWithPriority(jsify(value), priority)).toDart;
Future setWithPriority(Object? value, priority) =>
(jsObject.setWithPriority((value)?.toJSBox, priority)).toDart;

/// Writes multiple [values] at actual location when the client is disconnected.
///
/// The [values] must be a Dart basic type or the error is thrown.
Future update(values) => (jsObject.update(jsify(values))).toDart;
Future update(Object? values) => (jsObject.update((values)?.toJSBox)).toDart;
}

/// The ThenableReference class represents [DatabaseReference] with a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class MessagePayload
NotificationPayload? get notification => jsObject.notification == null
? null
: NotificationPayload._fromJsObject(jsObject.notification!);
Map<String, dynamic>? get data => dartify(jsObject.data);
Map<String, dynamic>? get data =>
jsObject.data.dartify() as Map<String, dynamic>?;
String? get from => jsObject.from?.toDart;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Trace extends JsObjectWrapper<performance_interop.TraceJsImpl> {
String getAttribute(String attr) => jsObject.getAttribute(attr.toJS).toDart;

Map<String, String> getAttributes() {
return dartify(jsObject.getAttributes()).cast<String, String>();
return (jsObject.getAttributes().dartify()! as Map<String, String>)
.cast<String, String>();
}

int getMetric(String metricName) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ class RemoteConfig
/// defaultsMap['x'] = 1; // remoteConfig.defaultConfig will not be updated.
/// remoteConfig.defaultConfig['x'] = 1; // Runtime error: attempt to modify an unmodifiable map.
/// ```
Map<String, dynamic> get defaultConfig =>
Map.unmodifiable(dartify(jsObject.defaultConfig));
Map<String, dynamic> get defaultConfig => Map.unmodifiable(
jsObject.defaultConfig.dartify()! as Map<String, dynamic>,
);

set defaultConfig(Map<String, dynamic> value) {
jsObject.defaultConfig = jsify(value);
jsObject.defaultConfig = value.toJSBox;
}

/// Returns the timestamp of the last *successful* fetch.
Expand Down Expand Up @@ -105,7 +106,8 @@ class RemoteConfig

/// Returns all config values.
Map<String, RemoteConfigValue> getAll() {
final keys = objectKeys(remote_config_interop.getAll(jsObject));
final keys =
remote_config_interop.getAll(jsObject).dartify()! as List<String>;
final entries = keys.map<MapEntry<String, RemoteConfigValue>>(
(dynamic k) => MapEntry<String, RemoteConfigValue>(k, getValue(k)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class UploadMetadata
contentLanguage: contentLanguage?.toJS,
contentType: contentType?.toJS,
customMetadata:
(customMetadata != null) ? jsify(customMetadata) : null));
(customMetadata != null) ? customMetadata.toJSBox : null));

/// Creates a new UploadMetadata from a [jsObject].
UploadMetadata.fromJsObject(storage_interop.UploadMetadataJsImpl jsObject)
Expand Down Expand Up @@ -447,7 +447,7 @@ class SettableMetadata
contentLanguage: contentLanguage?.toJS,
contentType: contentType?.toJS,
customMetadata:
(customMetadata != null) ? jsify(customMetadata) : null));
(customMetadata != null) ? customMetadata.toJSBox : null));

/// Creates a new SettableMetadata from a [jsObject].
SettableMetadata.fromJsObject(storage_interop.SettableMetadataJsImpl jsObject)
Expand Down Expand Up @@ -496,16 +496,13 @@ abstract class _SettableMetadataBase<

/// Additional user-defined custom metadata.
Map<String, String> get customMetadata {
Map<String, dynamic>? metadata = dartify(jsObject.customMetadata);
if (metadata != null) {
return Map<String, String>.from(metadata);
} else {
return {};
}
Map<String, dynamic>? metadata =
jsObject.customMetadata?.dartify() as Map<String, dynamic>?;
return Map<String, String>.from(metadata ?? {});
}

set customMetadata(Map<String, String> m) {
jsObject.customMetadata = jsify(m);
jsObject.customMetadata = m.toJSBox;
}
}

Expand Down
Loading