LiveLoveApp logo

Exercise - Unicast

Instructions

The goal of this exercise is to practice creating a unicast Observable.

  1. Go to codesandbox.io, sign in, and then create a new sandbox using the "Vanilla TypeScript" template.
  2. Add the rxjs dependency.
  3. Open the index.ts file and import the Observable class from the rxjs module.
  4. Create a new Observable instance, providing the subscribe function.
  5. Use the console.log() function to log a message for each new subscription.
  6. Optionally produce a value.
  7. Return a teardown function.
  8. Subscribe to the new Observable multiple times and note the number of subscriptions.

Hints

Here is the signature for the Observable class's constructor() function:

constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic);