Implementing create()

At the beginning of this chapter, we were taught how to create an Observable. The code looked like this:

let stream$ = Rx.Observable.create( observer => observer.next(1));stream$.subscribe( data => console.log(data));

Just by looking at the code, we can make educated guesses as to what's going on underneath. It's clear we need an Observable class.

The class needs a create() method that takes a function as a parameter. The create() method should return an Observable. Furthermore, our Observable class needs a subscribe() method that takes a function as a parameter. Let's start off there and see where we land.

First, let's define our Observable class with the aforementioned methods:

class MyObservable { static create(behaviourFn): ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.