mika-el
12/20/2018 - 1:24 PM

Observable create examples

Http request

Création

const http$ = Observable.create(observer => {
  fetch('api/courses')
    .then( response => {
      return response.json();
    })
    .then(body => {
      observer.next(body);
      observer.complete();
    })
    .catch(err => {
      observer.error(err);
    });
});

Subscription

http$.subscribe(
  courses => console.log(courses),
  noop,
  () => console.log('completed')
);