Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 683 Bytes

File metadata and controls

23 lines (19 loc) · 683 Bytes

RxJS tricks

The below will fire the inner code when a subscription is made

import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';

const obs = new Observable((subscriber: Subscriber<Response>) => {
  // get Observable from somewhere else
  .subscribe(
    (response: Response) => this.responseToSubscriber(response, subscriber),
    (response: Response) => this.responseToSubscriber(response, subscriber)
  );
}) as Observable<Response>;

private responseToSubscriber(response: Response, subscriber: Subscriber<Response>) {
  // do some manipulation
  subscriber.next(httpJsonResponse);
  subscriber.complete();
}