美文网首页
Tips of using RxJS

Tips of using RxJS

作者: forks1990 | 来源:发表于2018-11-15 16:31 被阅读0次

Async EventEmitter

Oh EventEmitter is Angular extension, not RxJS, whatever!

asyncEvent = new EventEmitter(true);

EventEmitter accept boolean argument, subscription get called in next JavaScript cycle, if sync event causes dead-lock, performance issues, or other problems, async is a quick solution.

Debounced or Shuffle Event

class OurComponent {
  private changed = new Subject<string>();

  private _value: string;

  get value() { return this._value; }

  set value(v: string) {
    if (v != this._value) {
       this._value = v;
       this.changed.next(v);
    }
  }

  @Output
  get delayedChange(): Observable<string> {
      return this.changed.pipe(debounceTime(500));
  }
}

Change delayedChange be a property, return a new observable filtered with debounceTime RxJS operation.

Disable an Event on Dispose

Suppose an event got from Dom world or other external source, you want disable derived event on component dispose, see code of cdk CdkScrollable directive for a clue.

相关文章

  • Tips of using RxJS

    Async EventEmitter Oh EventEmitter is Angular extension, ...

  • vs code

    TIps Tab navigation WindowsWhen using Visual Studio Code ...

  • Tips of using `cdkScrollable`

    Element should Scrollable Scrollable means content render...

  • Tips of using `ngbDropdown`

    ngbDropdown is very useful component of ngb-bootstrap, bu...

  • Scratch Using Tips

    图为我用Xmind整理的Scratch Using Tips,主要是Scratch中五大模块的运用,每个模块都会介...

  • 01RxJS-响应式编程类库

    rxjs-响应式编程类库)RxJS官网[https://rxjs.dev/] RxJS(Reactive Exte...

  • RxJS

    RxJS官网[https://rxjs.dev/] 1 概述 1.1 什么是 RxJS ? RxJS 是一个用...

  • 浅析Angular之RxJS

    本文结构: 什么是RxJS RxJS有什么特点 RxJS核心概念 什么是RxJS 在javaScript中,我们可...

  • Rxjs系列教程目录

    RxJS-中文文档RxJS-中文指南 rxjs学习入门心得(一)Observable可观察对象rxjs学习入门心得...

  • RxJS官方教程(六) 算子

    RxJS官方教程(一) 概览 RxJS官方教程(二) Observable RxJS官方教程(三) Observa...

网友评论

      本文标题:Tips of using RxJS

      本文链接:https://www.haomeiwen.com/subject/snvyfqtx.html