zoukankan      html  css  js  c++  java
  • [RxJS] Learn How To Use RxJS 5.5 Beta 2

    The main changes is about how you import rxjs opreators from now on. And introduce lettable opreator.

    import { range } from 'rxjs/observable/range';
    import { map, filter, scan } from 'rxjs/operators';
    
    const source$ = range(0, 10);
    
    source$.pipe(
      filter(x => x % 2 === 0),
      map(x => x + x),
      scan((acc, x) => acc + x, 0)
    )
    .subscribe(x => console.log(x))

    Build own opreator:

    import { interval } from 'rxjs/observable/interval';
    import { map, take, toArray } from 'rxjs/operators';
    
    /**
     * an operator that takes every Nth value
     */
    const takeEveryNth = (n: number) => <T>(source: Observable<T>) =>
      new Observable(observer => {
        let count = 0;
        return source.subscribe({
          next(x) {
            if (count++ % n === 0) observer.next(x);
          },
          error(err) { observer.error(err); },
          complete() { observer.complete(); }
        })
      });
    
    
    interval(1000).pipe(
      takeEveryNth(2),
      map(x => x + x),
      takeEveryNth(3),
      take(3),
      toArray()
    )
    .subscribe(x => console.log(x));
    // [0, 12, 24]
  • 相关阅读:
    es6.8集群部署(ssl认证)+nfs备份(生产)
    spool
    dataguard unname
    zabbix监控mysql主从同步可用性
    企业微信发送消息
    安装ruby
    binlog2sql
    xtrabackup备份异地恢复+binlog日志应用
    5.7.29重新部署主从
    centos7 图形界面启动
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7615991.html
Copyright © 2011-2022 走看看