1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RxJS Observableの流れ

Last updated at Posted at 2022-07-17

Observableの作成流れ

①Observableを作る(rxjs)
 ➡︎const {Observable} = rxjs;

②Observableの処理を作成する(Observable.create)
   const aaa = Observable.create((observer) => {
  observer.next(1);
   console.log('sample');
   observer.complete();
   observer.error('error');
}

③Observableの処理を実行する(subscribe)

 aaa.pipe().subscribe((x) => console.log(・・・));
 aaa.pipe().subscribe((c) => console.log(・・・));

④Observable処理の取り消し(unsubscribe)
 →subscribe実行で、はじめて処理が実行され、unsubscribeで処理実行が取り消されます。

     //①を省略、②
         const test = Observable.create((observer) => {
            observer.next(1),
            observer.next(2),
            observer.next(3),
            setTimeout(()=>{
                observer.next(4)
            },1000);
        })
     //③
        const subscription = 
        test.pipe().subscribe(
            (x) => console.log(`${x} :`,x ** 2)
        );
     //④
        subscription.unsubscribe();

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?