Get a better understanding of the RxJS Observable by implementing one that's similar from the ground up.
classSafeobserver {Constructor (destination) { This. Destination =destination; } next (value) {ConstDestination = This. Destination; if(Destination.next &&!) This. isunsubscribed) {Destination.next&&Destination.next (value); }} error (err) {ConstDestination = This. Destination; if(! This. isunsubscribed) { if(destination.error) {destination.error (error); } This. Unsubscribe (); }} complete () {ConstDestination = This. Destination; if(! This. isunsubscribed) { if(destination.complete) {destination.complete (); } This. Unsubscribe (); }} unsubscribe () { This. isunsubscribed =true; if( This. _unsubscribe) { This. _unsubscribe (); } }}classObservable {Constructor (_subscribe) { This. _subscribe =_subscribe; } subscribe (Observer) {ConstSafeobserver =NewSafeobserver (Observer); Safeobserver._unsubscribe= This. _subscribe (Safeobserver); return() =Safeobserver.unsubscribe (); }}ConstMyobservable =NewObservable ((Observer) ={Let I= 0; Constid = setinterval (() = { if(I < 10) {Observer.next (i++); } Else{observer.complete (); } }, 100); return() ={Console.log (' Unsubbed '); Clearinterval (ID); };});ConstObserver ={Next (value) {Console.log (' Next ' +value); }, error (ERR) {}, complete () {Console.log (' Complete '); }};ConstFoo =MYOBSERVABLE.SUBSCRIBE (Observer); Foo.unsubscribe ();
[RxJS] Creating Observable from Scratch