refactor(platform-webworker): cleanup

This commit is contained in:
Victor Berchet
2017-02-19 00:23:45 -08:00
parent 3517f28609
commit cdf99cf68b
15 changed files with 301 additions and 314 deletions

View File

@ -7,7 +7,7 @@
*/
import {PlatformRef} from '@angular/core';
import {ClientMessageBrokerFactory, FnArg, PRIMITIVE, UiArguments, bootstrapWorkerUi} from '@angular/platform-webworker';
import {ClientMessageBrokerFactory, FnArg, SerializerTypes, UiArguments, bootstrapWorkerUi} from '@angular/platform-webworker';
const ECHO_CHANNEL = 'ECHO';
@ -23,14 +23,10 @@ function afterBootstrap(ref: PlatformRef) {
const val = (<HTMLInputElement>document.getElementById('echo_input')).value;
// TODO(jteplitz602): Replace default constructors with real constructors
// once they're in the .d.ts file (#3926)
const args = new UiArguments('echo');
args.method = 'echo';
const fnArg = new FnArg(val, PRIMITIVE);
fnArg.value = val;
fnArg.type = PRIMITIVE;
args.args = [fnArg];
const fnArg = new FnArg(val);
const args = new UiArguments('echo', [fnArg]);
broker.runOnService(args, PRIMITIVE).then((echo_result: string) => {
broker.runOnService(args, SerializerTypes.PRIMITIVE).then((echo_result: string) => {
document.getElementById('echo_result').innerHTML =
`<span class='response'>${echo_result}</span>`;
});

View File

@ -7,7 +7,7 @@
*/
import {Component} from '@angular/core';
import {PRIMITIVE, ServiceMessageBrokerFactory} from '@angular/platform-webworker';
import {SerializerTypes, ServiceMessageBrokerFactory} from '@angular/platform-webworker';
const ECHO_CHANNEL = 'ECHO';
@ -15,16 +15,9 @@ const ECHO_CHANNEL = 'ECHO';
export class App {
constructor(private _serviceBrokerFactory: ServiceMessageBrokerFactory) {
const broker = _serviceBrokerFactory.createMessageBroker(ECHO_CHANNEL, false);
broker.registerMethod('echo', [PRIMITIVE], this._echo, PRIMITIVE);
broker.registerMethod(
'echo', [SerializerTypes.PRIMITIVE], this._echo, SerializerTypes.PRIMITIVE);
}
private _echo(val: string) {
return new Promise((res, rej) => {
try {
res(val);
} catch (e) {
rej(e);
}
});
}
private _echo(val: string) { return new Promise((res) => res(val)); }
}