本文整理汇总了TypeScript中angular2/src/facade/async.ObservableWrapper.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ObservableWrapper.subscribe方法的具体用法?TypeScript ObservableWrapper.subscribe怎么用?TypeScript ObservableWrapper.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/src/facade/async.ObservableWrapper
的用法示例。
在下文中一共展示了ObservableWrapper.subscribe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: start
start(): void {
this._bus.initChannel(SETUP_CHANNEL, false);
var sink = this._bus.to(SETUP_CHANNEL);
var source = this._bus.from(SETUP_CHANNEL);
ObservableWrapper.subscribe(source, (message: string) => {
if (StringWrapper.equals(message, "ready")) {
ObservableWrapper.callNext(sink, {"rootUrl": this.rootUrl});
}
});
}
示例2: it
it('delivers events asynchronously', inject([AsyncTestCompleter], (async) => {
var e = new EventEmitter();
var log = [];
ObservableWrapper.subscribe(e, (x) => {
log.push(x);
expect(log).toEqual([1, 3, 2]);
async.done();
});
log.push(1);
ObservableWrapper.callEmit(e, 2);
log.push(3);
}));
示例3: inject
inject([AsyncTestCompleter, NgZone], (async, zone: MockNgZone) => {
setup(false, zone);
var wasCalled = false;
ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; });
ObservableWrapper.callEmit(bus.to(CHANNEL), "hi");
flushMessages(() => {
expect(wasCalled).toBeTruthy();
async.done();
});
}), 10000);
示例4: expect
.then((_) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('routerCanActivate')) {
completer.resolve(false);
}
});
rtr.navigateByUrl('/can-activate/a').then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
async.done();
});
});
示例5: it
it('should return the correct status code', inject([AsyncTestCompleter], async => {
var statusCode = 418;
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
new ResponseOptions({status: statusCode}));
ObservableWrapper.subscribe<Response>(connection.response, res => {
expect(res.status).toBe(statusCode);
async.done();
});
existingXHRs[0].setStatusCode(statusCode);
existingXHRs[0].dispatchEvent('load');
}));
示例6: inject
inject([AsyncTestCompleter], (async) => {
const CHANNEL = "CHANNEL 1";
const MESSAGE = "Test message";
bus.initChannel(CHANNEL, false);
var fromEmitter = bus.from(CHANNEL);
ObservableWrapper.subscribe(fromEmitter, (message: any) => {
expect(message).toEqual(MESSAGE);
async.done();
});
var toEmitter = bus.to(CHANNEL);
ObservableWrapper.callEmit(toEmitter, MESSAGE);
}));
示例7: it
it("should return promises to the worker", inject([Serializer], (serializer) => {
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
expect(arg1).toEqual(PASSED_ARG_1);
return PromiseWrapper.wrap(() => { return RESULT; });
});
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => {
expect(data.type).toEqual("result");
expect(data.id).toEqual(ID);
expect(data.value).toEqual(RESULT);
});
}));
示例8: it
it("should fire an event after the value has been updated", inject([AsyncTestCompleter], (async) => {
ObservableWrapper.subscribe(g.valueChanges, (value) => {
expect(g.value).toEqual({
'one': 'new1',
'two': 'old2'
});
expect(value).toEqual({
'one': 'new1',
'two': 'old2'
});
async.done();
});
c1.updateValue("new1");
}));
示例9: inject
inject([AsyncTestCompleter], (async) => {
runNgZoneNoLog(() => macroTask(_log.fn('run')));
ObservableWrapper.subscribe(_zone.onStable, (_) => {
NgZone.assertNotInAngularZone();
_log.add('onMyTaskDone');
});
macroTask(() => {
expect(_log.result())
.toEqual('onUnstable; run; onMicrotaskEmpty; onStable; onMyTaskDone');
async.done();
});
}), testTimeout);
示例10: it
it('deletes micropost when confirmed', done => {
const cmp:Feed = cmpDebugElement.componentInstance;
const testCmp:TestCmp = ctx.fixture.debugElement.componentInstance;
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(true);
spyOn(cmp, 'list');
spyOn(testCmp, 'listenDeleted');
ObservableWrapper.subscribe(cmp.deleted, () => {
expect(cmp.list).toHaveBeenCalled();
expect(testCmp.listenDeleted).toHaveBeenCalled();
done();
});
deleteLink.click();
});