2015-07-10 16:09:18 -07:00
|
|
|
library angular2.examples.message_broker.index;
|
|
|
|
|
|
|
|
import "package:angular2/src/web-workers/ui/application.dart"
|
2015-08-07 13:17:54 -07:00
|
|
|
show spawnWebWorker, UIMessageBus, UIMessageBusSink, UIMessageBusSource;
|
2015-07-10 16:09:18 -07:00
|
|
|
|
|
|
|
import "dart:html";
|
|
|
|
|
|
|
|
main() {
|
|
|
|
var VALUE = 5;
|
2015-08-07 13:17:54 -07:00
|
|
|
spawnWebWorker(Uri.parse("background_index.dart")).then((bus) {
|
2015-07-10 16:09:18 -07:00
|
|
|
querySelector("#send_echo").addEventListener("click", (e) {
|
|
|
|
var val = (querySelector("#echo_input") as InputElement).value;
|
|
|
|
bus.sink.send({'type': 'echo', 'value': val});
|
|
|
|
});
|
2015-07-10 16:09:18 -07:00
|
|
|
bus.source.addListener((message) {
|
2015-07-10 16:09:18 -07:00
|
|
|
var data = message['data'];
|
|
|
|
if (identical(data['type'], "echo_response")) {
|
|
|
|
querySelector("#echo_result")
|
|
|
|
.appendHtml("<span class='response'>${data['value']}</span>");
|
|
|
|
} else if (identical(data['type'], "test")) {
|
2015-08-04 12:05:30 -07:00
|
|
|
bus.sink.send({'type': "result", 'id': data['id'], 'value': VALUE});
|
2015-07-10 16:09:18 -07:00
|
|
|
} else if (identical(data['type'], "result")) {
|
|
|
|
querySelector("#ui_result")
|
|
|
|
.appendHtml("<span class='result'>${data['value']}</span>");
|
|
|
|
} else if (identical(data['type'], "ready")) {
|
|
|
|
bus.sink.send({'type': "init"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|