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


TypeScript rxjs.fromEventPattern函數代碼示例

本文整理匯總了TypeScript中rxjs.fromEventPattern函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromEventPattern函數的具體用法?TypeScript fromEventPattern怎麽用?TypeScript fromEventPattern使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了fromEventPattern函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('should send errors in the selector down the error path', (done: MochaDone) => {
    let target: any;
    const trigger = (value: any) => {
      if (target) {
        target(value);
      }
    };

    const addHandler = (handler: any) => {
      target = handler;
    };
    const removeHandler = (handler: any) => {
      target = null;
    };
    const selector = (x: any) => {
      throw 'bad';
    };

    fromEventPattern(addHandler, removeHandler, selector)
      .subscribe((x: any) => {
        done(new Error('should not be called'));
      }, (err: any) => {
        expect(err).to.equal('bad');
        done();
      }, () => {
        done(new Error('should not be called'));
      });

    trigger('test');
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:30,代碼來源:fromEventPattern-spec.ts

示例2: addHandler

 ('should create an observable from the handler API', () => {
   function addHandler(h: any) {
     timer(50, 20, rxTestScheduler).pipe(
       mapTo('ev'),
       take(2),
       concat(NEVER)
     ).subscribe(h);
   }
   const e1 = fromEventPattern(addHandler);
   const expected = '-----x-x---';
   expectObservable(e1).toBe(expected, {x: 'ev'});
 });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:12,代碼來源:fromEventPattern-spec.ts

示例3: fromEventPattern

 observable1 = constructorZone1.run(() => {
   return fromEventPattern(
       (handler: any) => {
         expect(Zone.current.name).toEqual(constructorZone1.name);
         button.addEventListener('click', handler);
         log.push('addListener');
       },
       (handler: any) => {
         expect(Zone.current.name).toEqual(constructorZone1.name);
         button.removeEventListener('click', handler);
         document.body.removeChild(button);
         log.push('removeListener');
       });
 });
開發者ID:angular,項目名稱:zone.js,代碼行數:14,代碼來源:rxjs.fromEvent.spec.ts

示例4: addHandler

export function fromHistory<LocationState>(
  history: History
): Observable<[Location<LocationState>, Action]> {
  let unregisterCallback: UnregisterCallback;

  function addHandler(handler: LocationListener): void {
    unregisterCallback = history.listen(handler);
    handler(history.location, history.action);
  }

  function removeHandler(): void {
    if (unregisterCallback) {
      unregisterCallback();
    }
  }

  return fromEventPattern<[Location<LocationState>, Action]>(
    addHandler,
    removeHandler
  );
}
開發者ID:evertbouw,項目名稱:rx-history,代碼行數:21,代碼來源:fromHistory.ts


注:本文中的rxjs.fromEventPattern函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。