I'm experimenting with angular 2 for a large project that would benefit from handing off tasks to web workers.
I've found examples of ng2 web workers for JavaScript and TypeScript but struggling to convert these into dart equivalent.
Has anyone done this? Or know how to do this?
Below is my current main.dart bootstrap file, the AppComponent should have access to the UI, and the CustomerService work in a worker.
import 'package:angular2/platform/browser.dart';
import 'package:angular2/web_worker/ui.dart';
import 'package:ngMegatron/app_component.dart';
import 'package:ngMegatron/services/customer.dart';
main() {
bootstrap(AppComponent, [CustomerService]);
}
last link from guenthers answer seems to be broken. found it under: https://github.com/bwu-dart-playground/angular2/tree/master/web_workers/kitchen_sink
Update 3
web Worker support was removed from Dart Angular2 when the project was split from TypeScript. There seem to be plans to add support back when DDC and Bazel become available and allow to develop with Chrome instead of Dartium.
Update 2
There are some basic examples in
https://github.com/angular/angular/blob/master/modules/angular2/docs/web_workers/web_workers.md#bootstrapping-a-webworker-application
but they seem outdated.
Working example - kitchen_sink
Below is the code of the example from https://github.com/angular/angular/tree/master/modules/playground/src/web_workers/kitchen_sink which is completed and missing parts translated from TypeScript to Dart when the Angular is built (See also
- https://github.com/angular/angular/blob/master/DEVELOPER.md - https://stackoverflow.com/a/36315210/217408)
pubspec.yaml
web/index.html
web/index.dart
web/index_common.dart
I also published the working example to https://github.com/bwu-dart-playground/dart_playground/tree/master/angular2/web_workers/kitchen_sink
Hint
I had to use CtrlF5 to make it work otherwise the newest version wasn't loaded.