当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.fromEvent方法代码示例

本文整理汇总了TypeScript中rxjs.Observable.fromEvent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.fromEvent方法的具体用法?TypeScript Observable.fromEvent怎么用?TypeScript Observable.fromEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.fromEvent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

	constructor(private _socket: SocketIO.Socket){
      this.id = _socket.id;
      this.messages = Observable.fromEvent(_socket, 'message');
	  let disconnect = Observable.fromEvent(_socket, 'disconnect');
	  let outgoing = (message) => _socket.send(message);
	  this.broadcasts = this.messages.filter(message => message.broadcast);
	  this.pings = this.messages.filter(message => message.action === 'ping');
	}
开发者ID:mckennatim,项目名称:rx-socket-demo,代码行数:8,代码来源:main.ts

示例2:

export const heroShots$Fac = (heroShots: iHeroShot[], heroShip$: Observable<iHeroShip>): Observable<iHeroShot[]> => {
  return Observable.fromEvent(canvas, 'click')
    .throttleTime(100)
    .withLatestFrom(heroShip$, (event, heroShip) => heroShip)
    .scan((acc, heroShip) => {
      acc.push(Object.assign({}, heroShip))
      return acc
    }, heroShots)
    .startWith(heroShots)
    .switchMap(heroShots => {
      return Observable.interval(config.commons.moveInterval)
        .map(tick => {
          // return heroShots.reduce((newHeroShots, heroShot) => {
          //   heroShot.y -= config.heroShot.moveSpeed.y;
          //   if (heroShot.y >= 0 - config.heroShot.halfBottomLength) {
          //     newHeroShots.push(Object.assign({}, heroShot));
          //   }
          //   return newHeroShots;
          // }, []);
          heroShots.forEach((heroShot, index, heroShots) => {
            heroShot.y -= config.heroShot.moveSpeed.y;
            if (heroShot.y <= 0 - config.heroShot.halfBottomLength) {
              heroShots.splice(index, 1);
            }
          })
          return heroShots
        })
    })
    .startWith(heroShots)
}
开发者ID:timathon,项目名称:rx-space,代码行数:30,代码来源:heroShots.ts

示例3: showNotification

    showNotification(channelId: ChannelId, from: string, text: string): void {
        const settings = this._config.get();
        if (settings.notification) {
            // FIXME: should call in `NotificationActionCreator.showNotification()`
            this._notifyAction.playSound();
        }

        if (settings.badge && Notification.permission === 'granted') {
            let notification = new Notification(from + ' says:', {
                body: text,
                icon: ICON_URL,
            });

            const timeout: Rx.Observable<void> = Rx.Observable.empty<void>().delay(5 * 1000);
            const click: Rx.Observable<void> = Rx.Observable.fromEvent<void>(notification, 'click').take(1).do<void>(() => {
                this._uiAction.focusWindow();
                this._uiAction.selectChannel(channelId);
            });

            const close: Rx.Observable<void> = click.race(timeout);
            close.subscribe(function(){}, function(){}, function(){
                notification.close();
                notification = null;
            });
        }
    }
开发者ID:karen-irc,项目名称:karen,代码行数:26,代码来源:NotificationPresenter.ts

示例4: run

export function run(){

    const clickStream = Observable.fromEvent(document.getElementById('refresh'),'click');
    
    clickStream.subscribe(
        (event:Event) => console.log(event.type)
    );   
}
开发者ID:cyrilpanicker,项目名称:rxjs-demo,代码行数:8,代码来源:fromEvent.ts

示例5: constructor

    constructor() {
        let windowSize$ = new BehaviorSubject(getWindowSize());
        this.width$ = (windowSize$.pluck('width') as Observable<number>).distinctUntilChanged();
        this.height$ = (windowSize$.pluck('height') as Observable<number>).distinctUntilChanged();

        Observable.fromEvent(window, 'resize')
            .map(getWindowSize)
            .subscribe(windowSize$);
    }
开发者ID:revnique,项目名称:ng4end2end,代码行数:9,代码来源:windowResize.ts

示例6: getCharacters

 public getCharacters(){
     const txt = document.getElementById("character");
     let keyups$ = Observable.fromEvent(txt, "keyup");
     let letters$ = keyups$.map((ev:any) => ev.target.value);
     return letters$.switchMap(p => this.http
     .get("api/region/" + this.region + "/realm/" + this.realm + "/character/" + p))
     .map((res:Response) => res.json())
     .catch((err:any, caught:Observable<any>) => caught);
 }
开发者ID:revuniversal,项目名称:QueueDodge,代码行数:9,代码来源:character-lookup.component.ts

示例7: switch

    let event = (() => {
      let event = Observable.fromEvent(this.client, eventType)

      switch (eventType) {
        case 'message':
          return event.filter((m: Message) => m.author.id != this.client.user.id && !m.author.bot)
        default:
          return event
      }
    })()
开发者ID:goodmind,项目名称:cycle-discord,代码行数:10,代码来源:MainDiscordSource.ts

示例8: initDrag

  /**
   * 初始化元素拖拽
   */
  initDrag(target: HTMLElement, fn: Function, options?: any): { destroy: Function } {
    let dragObj: any = {};
    let subArr: Array<Subscription> = [];
    let sub;
    // 鼠标按下时,标记拖拽开始
    sub = Observable.fromEvent(target, 'mousedown')
      .subscribe((e: MouseEvent) => {
        dragObj = {
          pageX: e.pageX,
          pageY: e.pageY,
          draging: true
        };
        if (typeof options.processDragObj === 'function') {
          options.processDragObj(dragObj);
        }
      });
    subArr.push(sub);
    // 鼠标移动时,开始执行拖拽
    sub = Observable.fromEvent(document, 'mousemove')
      .throttleTime(options.throttleTime || 20)
      .subscribe((e: MouseEvent) => {
        if (!dragObj.draging) {
          return;
        }
        fn(dragObj, e);
      });
    subArr.push(sub);
    // 鼠标松开时,停止拖拽
    sub = Observable.fromEvent(document, 'mouseup')
      .subscribe((e: MouseEvent) => {
        dragObj.draging = false;
      });
    subArr.push(sub);

    return {
      destroy() {
        subArr.forEach(sub => sub.unsubscribe());
      }
    }
  }
开发者ID:hstarorg,项目名称:book-store,代码行数:43,代码来源:util.service.ts

示例9: fun

    Array.prototype.forEach.call(element.querySelectorAll('[on-click]'), (elem) => {

      if (obj[elem.getAttribute('on-click')] instanceof Subject) {
        Observable.fromEvent(elem, 'click').subscribe((event) =>
          Listeners.convertStringToAtrrCall(elem, 'on-click', obj).next(event)
        );
      }

      if (typeof obj[elem.getAttribute('on-click')] === 'function') {
        elem.addEventListener('click', (event) => {
          const fun = Listeners.convertStringToAtrrCall(event.currentTarget, 'on-click', obj).bind(obj);
          fun(event);
        });
      }
    });
开发者ID:dakolech,项目名称:tags-input-code-comparison,代码行数:15,代码来源:listeners.ts

示例10: _handleClickEvent

 private _handleClickEvent(): Rx.Subscription {
     // tslint:disable-next-line:no-non-null-assertion
     return Rx.Observable.fromEvent<Element>(this._element!, 'click', (event: UIEvent) => event.target as Element)
         .filter((target: Element): boolean => (target.localName === 'button'))
         .subscribe((target: Element) => {
             if (target.classList.contains('lt')) {
                 const shouldOpen: boolean = !this._vm.isOpenedLeftPane.value();
                 this._vm.isOpenedLeftPane.setValue(shouldOpen);
                 this._uiAction.toggleLeftPane(shouldOpen);
             }
             else if (target.classList.contains('rt')) {
                 const shouldOpen: boolean = !this._vm.isOpenedRightPane.value();
                 this._vm.isOpenedRightPane.setValue(shouldOpen);
             }
         });
 }
开发者ID:karen-irc,项目名称:karen,代码行数:16,代码来源:AppView.ts


注:本文中的rxjs.Observable.fromEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。