本文整理汇总了TypeScript中pow-core/observable.Observable类的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable类的具体用法?TypeScript Observable怎么用?TypeScript Observable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observable类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should remove a listener from the obs when unsubscribe is called', () => {
var o:any = new Observable<void>();
var generator:IGenerator<void> = {};
o.subscribe({});
var s:ISubscription = o.subscribe(generator);
expect(o._listeners.length).toBe(2);
expect(s.unsubscribe).toBeDefined();
s.unsubscribe();
expect(o._listeners.length).toBe(1);
});
开发者ID:justindujardin,项目名称:pow-core,代码行数:10,代码来源:observable.spec.ts
示例2: expectNotCalledAfterUnsubscribe
function expectNotCalledAfterUnsubscribe(operation:string) {
var count:number = 0;
var o:any = new Observable<void>();
var generator:any = {};
generator[operation] = (value?:void):any => count++;
var subscription:ISubscription = o.subscribe(generator);
o[operation]();
expect(count).toBe(1);
subscription.unsubscribe();
o[operation]();
expect(count).toBe(1);
}
开发者ID:justindujardin,项目名称:pow-core,代码行数:12,代码来源:observable.spec.ts
示例3: expectUnsubscribeOnDoneTrue
function expectUnsubscribeOnDoneTrue(operation:string) {
var o:any = new Observable<void>();
var generator:any = {};
generator[operation] = (value?:void):any => {
return {
done: true
};
};
o.subscribe(generator);
expect(o._listeners.length).toBe(1);
o[operation]();
expect(o._listeners.length).toBe(0);
}
开发者ID:justindujardin,项目名称:pow-core,代码行数:13,代码来源:observable.spec.ts
示例4: expectThrowOnCallbackThrow
function expectThrowOnCallbackThrow(operation:string) {
var called:boolean = false;
var o:any = new Observable<void>();
var e = new Error('Test Error');
var generator:any = {
throw: (error:string) => {
expect(error).toBe(e);
called = true;
}
};
generator[operation] = (value?:any):any => {
throw e;
};
o.subscribe(generator);
o[operation]();
expect(called).toBe(operation !== 'throw');
}
开发者ID:justindujardin,项目名称:pow-core,代码行数:17,代码来源:observable.spec.ts
示例5: expectNoThrowOnMissing
function expectNoThrowOnMissing(operation:string) {
var o:any = new Observable();
var count = 0;
if (operation !== 'throw') {
o.subscribe({
throw: (e:any) => count++
});
o[operation]();
expect(count).toBe(0);
}
else {
o.subscribe({});
o.subscribe({
throw: (e:any) => expect(e).toBe('foo')
});
o[operation]('foo');
}
}
开发者ID:justindujardin,项目名称:pow-core,代码行数:18,代码来源:observable.spec.ts
注:本文中的pow-core/observable.Observable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论