Skip to content

feat(performance, web): migrate web to js_interop to be compatible with WASM #12515

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 2 commits into from
Mar 22, 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 @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:js_interop';

import 'package:firebase_core_web/firebase_core_web_interop.dart' hide jsify;

import 'performance_interop.dart' as performance_interop;
Expand Down Expand Up @@ -38,45 +40,46 @@ class Performance
: super.fromJsObject(jsObject);

Trace trace(String traceName) =>
Trace.fromJsObject(performance_interop.trace(jsObject, traceName));
Trace.fromJsObject(performance_interop.trace(jsObject, traceName.toJS));

/// Non-null App for this instance of firestore service.
App get app => App.getInstance(jsObject.app);

bool get instrumentationEnabled => jsObject.instrumentationEnabled;
bool get dataCollectionEnabled => jsObject.dataCollectionEnabled;
bool get instrumentationEnabled => jsObject.instrumentationEnabled.toDart;
bool get dataCollectionEnabled => jsObject.dataCollectionEnabled.toDart;
}

class Trace extends JsObjectWrapper<performance_interop.TraceJsImpl> {
Trace.fromJsObject(performance_interop.TraceJsImpl jsObject)
: super.fromJsObject(jsObject);

String getAttribute(String attr) => jsObject.getAttribute(attr);
String getAttribute(String attr) => jsObject.getAttribute(attr.toJS).toDart;

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

int getMetric(String metricName) => jsObject.getMetric(metricName);
int getMetric(String metricName) =>
jsObject.getMetric(metricName.toJS).toDartInt;

void incrementMetric(String metricName, [int? num]) {
if (num != null) {
return jsObject.incrementMetric(metricName, num);
return jsObject.incrementMetric(metricName.toJS, num.toJS);
} else {
return jsObject.incrementMetric(metricName);
return jsObject.incrementMetric(metricName.toJS);
}
}

void putMetric(String metricName, int num) {
return jsObject.putMetric(metricName, num);
return jsObject.putMetric(metricName.toJS, num.toJS);
}

void putAttribute(String attr, String value) {
return jsObject.putAttribute(attr, value);
return jsObject.putAttribute(attr.toJS, value.toJS);
}

void removeAttribute(String attr) {
return jsObject.removeAttribute(attr);
return jsObject.removeAttribute(attr.toJS);
}

void start() {
Expand All @@ -97,8 +100,8 @@ class PerformanceSettings
bool? instrumentationEnabled,
]) {
final jsObject = performance_interop.PerformanceSettingsJsImpl(
dataCollectionEnabled: dataCollectionEnabled,
instrumentationEnabled: instrumentationEnabled,
dataCollectionEnabled: dataCollectionEnabled?.toJS,
instrumentationEnabled: instrumentationEnabled?.toJS,
);
return _expando[jsObject] ??= PerformanceSettings._fromJsObject(jsObject);
}
Expand All @@ -107,13 +110,13 @@ class PerformanceSettings
performance_interop.PerformanceSettingsJsImpl jsObject,
) : super.fromJsObject(jsObject);

bool? get dataCollectionEnabled => jsObject.dataCollectionEnabled;
bool? get dataCollectionEnabled => jsObject.dataCollectionEnabled?.toDart;
set dataCollectionEnabled(bool? b) {
jsObject.dataCollectionEnabled = b;
jsObject.dataCollectionEnabled = b?.toJS;
}

bool? get instrumentationEnabled => jsObject.instrumentationEnabled;
bool? get instrumentationEnabled => jsObject.instrumentationEnabled?.toDart;
set instrumentationEnabled(bool? b) {
jsObject.instrumentationEnabled = b;
jsObject.instrumentationEnabled = b?.toJS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,84 @@
@JS('firebase_performance')
library firebase.performance_interop;

import 'dart:js_interop';

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

@JS()
@staticInterop
external PerformanceJsImpl getPerformance([AppJsImpl? app]);

@JS()
@staticInterop
external PerformanceJsImpl initializePerformance(
AppJsImpl app, [
PerformanceSettingsJsImpl? settings,
]);

@JS()
external TraceJsImpl trace(PerformanceJsImpl performance, String traceName);
@staticInterop
external TraceJsImpl trace(PerformanceJsImpl performance, JSString traceName);

@JS('Performance')
abstract class PerformanceJsImpl {
@staticInterop
abstract class PerformanceJsImpl {}

extension PerformanceJsImplExtension on PerformanceJsImpl {
external AppJsImpl get app;
external bool dataCollectionEnabled;
external bool instrumentationEnabled;
external JSBoolean dataCollectionEnabled;
external JSBoolean instrumentationEnabled;
}

@JS('Trace')
@staticInterop
@anonymous
class TraceJsImpl {
external String getAttribute(String attr);
external Object getAttributes();
external int getMetric(String metricName);
external void incrementMetric(String metricName, [int? num]);
external void putMetric(String metricName, int num);
external void putAttribute(String attr, String value);
external void removeAttribute(String attr);
class TraceJsImpl {}

extension TraceJsImplExtension on TraceJsImpl {
external JSString getAttribute(JSString attr);
external JSAny getAttributes();
external JSNumber getMetric(JSString metricName);
external void incrementMetric(JSString metricName, [JSNumber? num]);
external void putMetric(JSString metricName, JSNumber num);
external void putAttribute(JSString attr, JSString value);
external void removeAttribute(JSString attr);
external void start();
external void record(int number, int duration, [RecordOptions? options]);
external void record(
JSNumber number,
JSNumber duration, [
RecordOptions? options,
]);
external void stop();
}

@JS()
@staticInterop
@anonymous
class RecordOptions {
external factory RecordOptions({JSAny? metrics, JSAny? attributes});
}

extension RecordOptionsExtension on RecordOptions {
/* map of metrics */
external Object? get metrics;
external JSAny? get metrics;
/* map of attributes */
external Object? get attributes;
external factory RecordOptions({Object? metrics, Object? attributes});
external JSAny? get attributes;
}

@JS()
@staticInterop
@anonymous
class PerformanceSettingsJsImpl {
external bool? get dataCollectionEnabled;
external set dataCollectionEnabled(bool? b);
external bool? get instrumentationEnabled;
external set instrumentationEnabled(bool? b);
external factory PerformanceSettingsJsImpl({
bool? dataCollectionEnabled,
bool? instrumentationEnabled,
JSBoolean? dataCollectionEnabled,
JSBoolean? instrumentationEnabled,
});
}

extension PerformanceSettingsJsImplExtension on PerformanceSettingsJsImpl {
external JSBoolean? get dataCollectionEnabled;
external set dataCollectionEnabled(JSBoolean? b);
external JSBoolean? get instrumentationEnabled;
external set instrumentationEnabled(JSBoolean? b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ dependencies:
flutter_web_plugins:
sdk: flutter
js: ^0.6.3
web: ^0.5.1


dev_dependencies:
build_runner: ^2.3.3
flutter_test:
sdk: flutter
mockito: ^5.0.10

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down

This file was deleted.

Loading
Loading