refactor(WebWorker): move XHR worker side
This commit is contained in:
@ -5,4 +5,3 @@
|
||||
export const RENDERER_CHANNEL = "ng-Renderer";
|
||||
export const EVENT_CHANNEL = "ng-Events";
|
||||
export const ROUTER_CHANNEL = "ng-Router";
|
||||
export const XHR_CHANNEL = "ng-XHR";
|
||||
|
@ -1,24 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {PRIMITIVE} from '../shared/serializer';
|
||||
import {ServiceMessageBrokerFactory} from '../shared/service_message_broker';
|
||||
import {XHR_CHANNEL} from '../shared/messaging_api';
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {FunctionWrapper} from '../../facade/lang';
|
||||
|
||||
/**
|
||||
* XHR requests triggered on the worker side are executed on the UI side.
|
||||
*
|
||||
* This is only strictly required for Dart where the isolates do not have access to XHRs.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@Injectable()
|
||||
export class MessageBasedXHRImpl {
|
||||
constructor(private _brokerFactory: ServiceMessageBrokerFactory, private _xhr: XHR) {}
|
||||
|
||||
start(): void {
|
||||
var broker = this._brokerFactory.createMessageBroker(XHR_CHANNEL);
|
||||
broker.registerMethod("get", [PRIMITIVE], FunctionWrapper.bind(this._xhr.get, this._xhr),
|
||||
PRIMITIVE);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {
|
||||
FnArg,
|
||||
UiArguments,
|
||||
ClientMessageBroker,
|
||||
ClientMessageBrokerFactory
|
||||
} from '../shared/client_message_broker';
|
||||
import {XHR_CHANNEL} from '../shared/messaging_api';
|
||||
|
||||
/**
|
||||
* Implementation of compiler/xhr that relays XHR requests to the UI side where they are sent
|
||||
* and the result is proxied back to the worker.
|
||||
*
|
||||
* This is only strictly required for Dart where isolates do not have access to the XHRs.
|
||||
*/
|
||||
@Injectable()
|
||||
export class WebWorkerXHRImpl extends XHR {
|
||||
private _messageBroker: ClientMessageBroker;
|
||||
|
||||
constructor(messageBrokerFactory: ClientMessageBrokerFactory) {
|
||||
super();
|
||||
this._messageBroker = messageBrokerFactory.createMessageBroker(XHR_CHANNEL);
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
var fnArgs: FnArg[] = [new FnArg(url, null)];
|
||||
var args: UiArguments = new UiArguments("get", fnArgs);
|
||||
return this._messageBroker.runOnService(args, String);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user