observable and observer?heba mahmoudLast updated on February 17Your thoughts? Share your thoughts StackChief LLC | February 22, 2024Heba,Check this code...class Observable { constructor(functionThatTakesObserver){ this._functionThatTakesObserver = functionThatTakesObserver; } subscribe(observer) { return this._functionThatTakesObserver(observer) } } let myObservable = new Observable(observer => { setTimeout(() => { observer.next("got data!") observer.complete() }, 1000) }) let myObserver = { next(data) { console.log(data) }, error(e) { console.log(e) }, complete() { console.log("request complete") } } myObservable.subscribe(myObserver) // (1 second) got data! // (1 second) request complete The Observable is the class "Observable".The Observer is the variable "myObservable".Check out our articles on Observables for more insights...JavaScript Observables in 5 MinutesObservable Tutorial0
Heba,
Check this code...
The Observable is the class "Observable".
The Observer is the variable "myObservable".
Check out our articles on Observables for more insights...
JavaScript Observables in 5 Minutes
Observable Tutorial