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


TypeScript fromEvent.fromEvent函數代碼示例

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


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

示例1: constructor

 constructor(private sanitizer: DomSanitizer, private orientation: ScreenOrientation) {
   this.fullscreen = merge(
     fromEvent(document, 'fullscreenchange'),
     fromEvent(document, 'webkitfullscreenchange'),
     fromEvent(document, 'mozfullscreenchange'),
   );
 }
開發者ID:ifiske,項目名稱:iFiske,代碼行數:7,代碼來源:youtube.ts

示例2: dragOver

    private dragOver() {
        const dragEnter = fromEvent(this.el, this.domEvents.ON_DRAG_ENTER_EVENT);
        const dragLeave = fromEvent(this.el, this.domEvents.ON_DRAG_LEAVE_EVENT);

        return dragEnter.pipe(
            flatMap(mouseDrag => of(mouseDrag).pipe(
                delay(500),
                takeUntil(dragLeave)
            ))
        );
    }
開發者ID:hmenager,項目名稱:composer,代碼行數:11,代碼來源:drag-over.directive.ts

示例3: switchMap

        switchMap(scroll => {
            if (!scroll) return empty();
            return fromEvent(document, "scroll", true).pipe(
                map((e: Event) => e.target),
                withLatestFrom(canSync$, elemMap$),
                filter(([, canSync]) => Boolean(canSync)),
                map(([target, canSync, elemMap]: [any, boolean, any[]]) => {
                    if (target === document) {
                        return ScrollEvent.outgoing(
                            getScrollPosition(window, document),
                            "document",
                            0
                        );
                    }

                    const elems = document.getElementsByTagName(target.tagName);
                    const index = Array.prototype.indexOf.call(
                        elems || [],
                        target
                    );

                    return ScrollEvent.outgoing(
                        getScrollPositionForElement(target),
                        target.tagName,
                        index,
                        elemMap.indexOf(target)
                    );
                })
            );
        })
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:30,代碼來源:scroll.listener.ts

示例4: hookToButtonKeyPressAndSubscribeToEvents

  hookToButtonKeyPressAndSubscribeToEvents() {
    const inputElement = document.getElementById('inputstuff');
    const keyPress$ = fromEvent<ElementRef>(inputElement, 'keypress')
      .pipe(delay(500));

    keyPress$.subscribe(
      (keypressevent: any) => {
        this.inputdata = (this.inputdata ? this.inputdata : '') + keypressevent.key;
      }
    );
  }
開發者ID:mewing200,項目名稱:KenticoAngularJS,代碼行數:11,代碼來源:keystroke.component.ts

示例5: showAt

    showAt(container: ViewContainerRef, menuItems: MenuItem[], coordinates: { x: number, y: number }) {
        this.close();
        const factory = this.resolver.resolveComponentFactory(MenuComponent);
        this.embeddedComponent = container.createComponent<MenuComponent>(factory);
        this.embeddedComponent.instance.setItems(menuItems);

        const nEl = this.embeddedComponent.location.nativeElement as HTMLElement;

        const {x, y} = coordinates;
        nEl.style.position = "fixed";
        nEl.style.left = x + "px";
        nEl.style.top = y + "px";

        fromEvent(nEl, "contextmenu").subscribe((ev: MouseEvent) => {
            ev.stopPropagation();
        });

        fromEvent(document, "click").pipe(
            take(1)
        ).subscribe(() => {
            this.close();
        });
    }
開發者ID:hmenager,項目名稱:composer,代碼行數:23,代碼來源:context.service.ts

示例6: switchMap

        switchMap(canToggle => {
            if (!canToggle) {
                return empty();
            }
            return fromEvent(document, "change", true).pipe(
                map((e: Event) => e.target || e.srcElement),
                filter((elem: HTMLInputElement) => elem.tagName === "SELECT"),
                withLatestFrom(canSync$),
                filter(([, canSync]) => canSync),
                map(([elem, canSync]: [HTMLInputElement, boolean]) => {
                    const data = getElementData(elem);

                    return FormToggleEvent.outgoing(data, {
                        type: elem.type,
                        checked: elem.checked,
                        value: elem.value
                    });
                })
            );
        })
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:20,代碼來源:form-toggles.listener.ts

示例7: switchMap

        switchMap(formInputs => {
            if (!formInputs) {
                return empty();
            }
            return fromEvent(document.body, "keyup", true).pipe(
                map((e: Event) => e.target || e.srcElement),
                filter(
                    (target: Element) =>
                        target.tagName === "INPUT" ||
                        target.tagName === "TEXTAREA"
                ),
                withLatestFrom(canSync$),
                filter(([, canSync]) => canSync),
                map(([eventTarget]) => {
                    const target = getElementData(eventTarget);
                    const value = eventTarget.value;

                    return KeyupEvent.outgoing(target, value);
                })
            );
        })
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:21,代碼來源:form-inputs.listener.ts

示例8: switchMap

 switchMap(canClick => {
     if (!canClick) {
         return empty();
     }
     return fromEvent(document, "click", true).pipe(
         map((e: Event) => e.target),
         filter((target: any) => {
             if (target.tagName === "LABEL") {
                 const id = target.getAttribute("for");
                 if (id && document.getElementById(id)) {
                     return false;
                 }
             }
             return true;
         }),
         withLatestFrom(canSync$),
         filter(([, canSync]) => canSync),
         map(([target]): OutgoingSocketEvent => {
             return ClickEvent.outgoing(getElementData(target));
         })
     );
 })
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:22,代碼來源:clicks.listener.ts

示例9: fromEvent

 this._change = platform.isBrowser ? ngZone.runOutsideAngular(() => {
   return merge<Event>(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange'));
 }) : observableOf();
開發者ID:GuzmanPI,項目名稱:material2,代碼行數:3,代碼來源:viewport-ruler.ts

示例10: fromEvent

import { fromEvent } from 'rxjs/observable/fromEvent';
import { ajax } from 'rxjs/observable/dom/ajax';
import { map, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';

const searchBox = document.getElementById('search-box');

const typeahead = fromEvent(searchBox, 'input').pipe(
  map((e: KeyboardEvent) => e.target.value),
  filter(text => text.length > 2),
  debounceTime(10),
  distinctUntilChanged(),
  switchMap(() => ajax('/api/endpoint'))
);

typeahead.subscribe(data => {
 // Handle the data from the API
});
開發者ID:cironunes,項目名稱:angular,代碼行數:17,代碼來源:typeahead.ts


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