-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
JS interop pain #55012
Comments
This works fine on my end: import 'dart:js_interop';
/// The JS `Accelerometer` as an extension typed JS binding.
///
/// The extension type defines the primary constructor as private.
@JS()
@staticInterop
extension type Accelerometer._(JSObject _) implements JSObject {
external factory Accelerometer([SensorOptions? options]);
external num? get x;
external num? get y;
external num? get z;
external bool? get hasReading;
external bool? get activated;
}
@JS()
@staticInterop
@anonymous
extension type SensorOptions._(JSObject _) implements JSObject {
external factory SensorOptions({double frequency});
} |
FYI - You don't need the I assume you're coming across the bug mentioned in the above link where you need to have an @JS()
library;
import 'dart:js_interop';
extension type CustomSensor._(JSObject _) implements JSObject {
external CustomSensor(SensorOptions sensorOptions);
external void start();
external void stop();
external num get myValue;
external void addEventListener(String type, JSFunction? callback, [JSAny options]);
}
extension type SensorOptions._(JSObject _) implements JSObject {
external factory SensorOptions({num frequency});
external num get frequency;
} Let me know if you're hitting some other bug instead. |
Thank you for the replies! Turns out it wasn't the
|
Ah yeah, you'll need a |
Compiler appeared happier with,
What are my options for handling the |
I'd avoid using
If it's a custom extension type CustomEvent(JSObject o) implements Event {
// declare whatever custom properties here
}
void readingInterop(CustomEvent event) {
// do something with `event`
}
mySensor.addEventListener("reading", readingInterop.toJS); |
Thanks both of you for the help! I was passing in a I used a |
Hey. I have a build of Chromium with a custom Sensor object, and I'm trying to bind to it. The Sensor is similar to this one found in
html_dart2js.dart
:However, the above is using some internal APIs, and I can't seem to get past setting
sensorOptions
on my version.The errors complain about the constructor.
SensorOptions
is supposed to be like a JS dictionary object, so that's why I was trying@anonymous
. Any ideas?The text was updated successfully, but these errors were encountered: