當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript observable.Observable類代碼示例

本文整理匯總了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;未經允許,請勿轉載。