How to use the rxjs.fromEvent function in rxjs

To help you get started, we’ve selected a few rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wardbell / rxjs-in-ng / src / app / app.component.ts View on Github external
templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  hasArt = false;
  numberOfBackgrounds = 16;
  movingBg$ = new Subject().pipe(startWith(true));

  backgroundArr = randommizeArrayOrder(
    Array.from(
      { length: this.numberOfBackgrounds },
      (e, i) => `Url(/assets/mainbg${i + 1}.jpg`
    )
  );

  key$ = fromEvent(this.document, 'keyup').pipe(
    filter((ev: KeyboardEvent) => ['F2', 'F4'].includes(ev.key)),
    tap(ev => ev.preventDefault()), // side effect take away original meaning of key   map((ev: KeyboardEvent) => ev.key),
    map(ev => ev.key),
    tap(k => console.log('key', k))
  );

  @ViewChild('main') main;

  constructor(
    public raki: RakiService,
    private swUrlService: SwUrlService,
    @Inject(DOCUMENT) private document: any
  ) {}

  ngOnInit() {
    if (this.hasArt) {
github Verseghy / website_frontend / apps / math-competition / src / app / modules / competition / components / competitionscreen / competitionscreen.component.ts View on Github external
ngOnInit() {
    this.problems = this.store.select('competition').pipe(
      map(x => {
        return x.problem
      })
    )
    this.store.dispatch(new problemActions.Query())
    this.problems.subscribe(x => {
      if (x.ids.length >= 40) {
        MathJax.Hub.Queue(['Typeset', MathJax.Hub])
      }
    })

    fromEvent(document, 'scroll')
      .pipe(
        debounceTime(200),
        distinct(),
        tap(() => {
          MathJax.Hub.Queue(['Typeset', MathJax.Hub])
        })
      )
      .subscribe()

    this.store.dispatch(new solutionActions.Query())

    interval(1000).subscribe(() => {
      const enddate = new Date('2018-12-14 18:00:00') // TODO
      const now = new Date()

      const distance = enddate.getTime() - now.getTime()
github pubkey / rxdb / dist / es / plugins / replication.js View on Github external
rxRepState._subs.push(fromEvent(evEmitter, 'change').subscribe(function (ev) {
    if (rxRepState._subjects.docs.observers.length === 0 || ev.direction !== 'pull') return;
    ev.change.docs.filter(function (doc) {
      return doc.language !== 'query';
    }) // remove internal docs
    .map(function (doc) {
      return rxRepState.collection._handleFromPouch(doc);
    }) // do primary-swap and keycompression
    .forEach(function (doc) {
      return rxRepState._subjects.docs.next(doc);
    });
  })); // error


  rxRepState._subs.push(fromEvent(evEmitter, 'error').subscribe(function (ev) {
    return rxRepState._subjects.error.next(ev);
  })); // active


  rxRepState._subs.push(fromEvent(evEmitter, 'active').subscribe(function () {
    return rxRepState._subjects.active.next(true);
  }));

  rxRepState._subs.push(fromEvent(evEmitter, 'paused').subscribe(function () {
    return rxRepState._subjects.active.next(false);
  })); // complete


  rxRepState._subs.push(fromEvent(evEmitter, 'complete').subscribe(function (info) {
    /**
     * when complete fires, it might be that not all changeEvents
github angular / components / src / cdk / scrolling / viewport-ruler.ts View on Github external
ngZone.runOutsideAngular(() => {
      this._change = _platform.isBrowser ?
          merge(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange')) :
          observableOf();

      // Note that we need to do the subscription inside `runOutsideAngular`
      // since subscribing is what causes the event listener to be added.
      this._invalidateCache = this.change().subscribe(() => this._updateViewportSize());
    });
  }
github Nodonisko / ionic-cache / src / cache.service.ts View on Github external
private watchNetworkInit() {
    this.networkStatus = navigator.onLine;
    const connect = fromEvent(window, 'online').pipe(map(() => true)),
      disconnect = fromEvent(window, 'offline').pipe(map(() => false));

    this.networkStatusChanges = merge(connect, disconnect).pipe(share());
    this.networkStatusChanges.subscribe(status => {
      this.networkStatus = status;
    });
  }
github sourcegraph / browser-extensions / app / bitbucket / BitbucketMount.tsx View on Github external
console.error('could not find closest section for event listeners.')
            return
        }
        createTooltips()
        const { baseRev, headRev } = revState
        if (baseRev !== undefined) {
            this.setState(() => ({ revState: { headRev, baseRev } }))
        } else {
            this.subscriptions.add(
                resolveParentRev({ repoPath, rev: revState.headRev! }).subscribe(rev => {
                    this.setState(() => ({ revState: { headRev, baseRev: rev } }))
                })
            )
        }
        this.subscriptions.add(
            merge(fromEvent(closestSection, 'mouseover'), fromEvent(closestSection, 'click'))
                .pipe(debounceTime(50))
                .subscribe((e: MouseEvent) => {
                    this.handleTokens(e)
                })
        )
    }
github dynatrace-oss / barista / src / lib / filter-field / filter-field.ts View on Github external
private _getFreeTextOutsideClickStream(): Observable {
    if (!this._document) {
      return observableOf();
    }

    return (merge(
      fromEvent(this._document, 'click'),
      fromEvent(this._document, 'touchend'),
    ).pipe(
      filter((event: Event) => {
        const clickTarget = event.target as HTMLElement;
        const filterField = this._elementRef.nativeElement;
        return (
          isDtFreeTextDef(this._currentDef) &&
          clickTarget !== filterField &&
          (!filterField || !filterField.contains(clickTarget))
        );
      }),
    ) as any) as Observable;
  }
github generative-music / blossom / src / core / input / make-input-source.js View on Github external
const makeClickSource = el =>
  fromEvent(el, 'click').pipe(
    map(clickEvent => mapInputToCoordinate(el, clickEvent))
  );
github nestjs / nest / bundle / websockets / adapters / ws-adapter.js View on Github external
bindMessageHandlers(client, handlers, transform) {
        const close$ = rxjs_1.fromEvent(client, constants_1.CLOSE_EVENT).pipe(operators_1.share(), operators_1.first());
        const source$ = rxjs_1.fromEvent(client, 'message').pipe(operators_1.mergeMap(data => this.bindMessageHandler(data, handlers, transform).pipe(operators_1.filter(result => result))), operators_1.takeUntil(close$));
        source$.subscribe(response => client.send(JSON.stringify(response)));
    }
    bindMessageHandler(buffer, handlers, transform) {
github Alfresco / alfresco-ng2-components / lib / content-services / search / components / search-trigger.directive.ts View on Github external
private get outsideClickStream(): Observable {
        if (!this.document) {
            return of(null);
        }

        return merge(
            fromEvent(this.document, 'click'),
            fromEvent(this.document, 'touchend')
        ).pipe(
            filter((event: MouseEvent | TouchEvent) => {
                const clickTarget = event.target as HTMLElement;
                return this._panelOpen && clickTarget !== this.element.nativeElement;
            }),
            takeUntil(this.onDestroy$)
        );
    }