moroshko / rxviz

Rx Visualizer - Animated playground for Rx Observables

Home Page:https://rxviz.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update custom operator example

Airblader opened this issue · comments

I think the custom operator example should be rewritten to use pipeable operators instead of mutating the prototype:

const sqrt = source$ => Rx.Observable.create(observer =>
    source$.subscribe(
      value => {
        const result = Math.sqrt(value);

        if (typeof value !== 'number' || isNaN(result)) {
          observer.error(`Square root of ${value} doesn't exist`);
        } else {
          observer.next(result);
        }
      },
      err => observer.error(err),
      () => observer.complete()
    )
  );

Rx.Observable
  .interval(1000)
  .pipe(sqrt)

Sounds good!
Could you submit a PR, please?

Merged #10 and deployed.