首页 > Web开发 > 详细

[RxJS] Building an RxJS Operator

时间:2020-04-10 23:36:11      阅读:82      评论:0      收藏:0      [点我收藏+]

While we’ve made sure to expose our spinner service using simple, external APIs, most of the time, it will be called in the same way, from observables and promises. In this lesson, we will be creating an RxJS operator that be easily plugged in to different observables to track them via the spinner.

 

function showLoadingStatus() {
  return source => new Observable((subscriber) => {
    newTaskStarted(); // start your logic
    const sub = source.subscribe(subscriber);

    return () => {
      sub.unsubscribe();
      existingTaskCompleted();  // end your logic
    }
  });
}

interval(500)
  .pipe(
    take(2),
    showLoadingStatus()
  )
  .subscribe(
    (x) => console.log(‘next is ‘, x)
  )

 

[RxJS] Building an RxJS Operator

原文:https://www.cnblogs.com/Answer1215/p/12676897.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!