2015-07-10 16:09:18 -07:00
|
|
|
import {
|
2015-08-17 10:28:47 -07:00
|
|
|
PostMessageBus,
|
|
|
|
PostMessageBusSink,
|
|
|
|
PostMessageBusSource
|
|
|
|
} from 'angular2/src/web-workers/shared/post_message_bus';
|
2015-07-10 16:09:18 -07:00
|
|
|
import {Type, BaseException} from "angular2/src/facade/lang";
|
|
|
|
import {Binding} from "angular2/di";
|
2015-08-17 10:28:47 -07:00
|
|
|
import {Map} from 'angular2/src/facade/collection';
|
|
|
|
import {Promise} from 'angular2/src/facade/async';
|
2015-08-07 13:17:54 -07:00
|
|
|
import {bootstrapWebWorkerCommon} from "angular2/src/web-workers/worker/application_common";
|
2015-08-20 17:18:27 -07:00
|
|
|
import {ApplicationRef} from "angular2/src/core/application_ref";
|
2015-07-10 16:09:18 -07:00
|
|
|
import {Injectable} from "angular2/di";
|
2015-07-10 16:09:18 -07:00
|
|
|
|
2015-07-31 10:33:22 -07:00
|
|
|
// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492)
|
2015-08-17 10:28:47 -07:00
|
|
|
interface PostMessageInterface {
|
|
|
|
(message: any, transferrables?:[ArrayBuffer]): void;
|
|
|
|
}
|
|
|
|
var _postMessage: PostMessageInterface = <any>postMessage;
|
2015-07-31 10:33:22 -07:00
|
|
|
|
2015-07-10 16:09:18 -07:00
|
|
|
/**
|
|
|
|
* Bootstrapping a Webworker Application
|
|
|
|
*
|
|
|
|
* You instantiate the application side by calling bootstrapWebworker from your webworker index
|
|
|
|
* script.
|
|
|
|
* You can call bootstrapWebworker() exactly as you would call bootstrap() in a regular Angular
|
|
|
|
* application
|
|
|
|
* See the bootstrap() docs for more details.
|
|
|
|
*/
|
2015-08-07 13:17:54 -07:00
|
|
|
export function bootstrapWebWorker(
|
2015-07-10 16:09:18 -07:00
|
|
|
appComponentType: Type, componentInjectableBindings: List<Type | Binding | List<any>> = null):
|
|
|
|
Promise<ApplicationRef> {
|
2015-08-17 10:28:47 -07:00
|
|
|
var sink = new PostMessageBusSink({
|
|
|
|
postMessage:
|
|
|
|
(message: any, transferrables?:[ArrayBuffer]) => { _postMessage(message, transferrables); }
|
|
|
|
});
|
|
|
|
var source = new PostMessageBusSource();
|
|
|
|
var bus = new PostMessageBus(sink, source);
|
2015-07-10 16:09:18 -07:00
|
|
|
|
2015-08-07 13:17:54 -07:00
|
|
|
return bootstrapWebWorkerCommon(appComponentType, bus, componentInjectableBindings);
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|