-
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
dart:js_interop
should provide a Function.toJS
call that automatically binds zones
#54507
Comments
Maybe it didn't work because Angular detects changes based on zones?, and when you put a function in AllowInterop, my suspicion is that anything that runs inside it will escape its current zone? |
I don't think |
Yeah, you'll likely need to manage the zones manually here. |
@natebosch |
The specifics will depend on how many arguments your function takes. For instance if it takes no arguments: void Function() theCallback;
final zoneBound = Zone.current.bindCallback(theCallback);
final jsCallable = allowInterop(zoneBound); If there is 1 or 2 arguments, you can use https://api.dart.dev/stable/3.2.4/dart-async/Zone/bindUnaryCallback.html or https://api.dart.dev/stable/3.2.4/dart-async/Zone/bindBinaryCallback.html The other option is to store the current zone and wrap in a lambda that uses final currentZone = Zone.current;
final jsCallable = allowInterop((arg1, arg2, arg3) {
return currentZone.run(() {
return theCallback(arg1, arg2, arg3);
});
}); |
For the record, there is no such thing as Dart code running outside of any Dart zone. If it's running Dart code, then Most likely it will be in whichever zone was current when control last entered the native JS code. If that happened from the event loop, maybe it'll be the root zone. Maybe. Using the |
perhaps it would be interesting in the future if allowInterop had a second boolean argument to enable capturing the current zone of the calling site and using this zone to execute the callback, just like dart:html already manages this altomatically |
I just saw that there are some inconsistencies in the dart2js and ddc compilers, if you try to call a function or property that you know exists in the event object, this function is normally called in ddc, but it is not called in dart2js, several errors occur, in addition If you compile the code with dart2js -o0 the application is completely broken I was trying to debug my application with dart2js -o0 and I started getting a lot of bugs canvas.on('selection:cleared', allowInterop((event) {
currentWidth = stage!.getScaledWidth();
currentHeight = stage!.getScaledHeight();
})); |
Indeed, this came up in our discussion when we talked about moving to
Can you file a separate issue for this with a minimal repro? There's an ongoing issue in dart2js with certain compiler flags due to precedence that may be related to it breaking: #54534. |
Function.toJS
call that automatically binds zones
Function.toJS
call that automatically binds zonesdart:js_interop
should provide a Function.toJS
call that automatically binds zones
I'm currently building a small web application with AngularDart and Fabric.js, and I have many fabric event callbaks that I need to pass Dart functions that will be called by these events and within these functions I change variables of the component class, and these variables are linked to the html elements of the template, but changes to variables are not being reflected in the elements
angulardart-community/angular#69
Dart SDK version: 3.2.1 (stable) (Wed Nov 22 08:59:13 2023 +0000) on "windows_x64"
The text was updated successfully, but these errors were encountered: