observable documentation code example

Example 1: understanding Observable.create(

import { Observable } from "rxjs/Observable";

var observable = Observable.create(function subscribe(observer) {
    observer.next('Hey guys!')
})

// OR 

var observable = Observable.create((observer:any) => {
    observer.next('Hey guys!')
})

Example 2: observable js

content_copy
      
      
        open_in_new
      
      import { Observable } from 'rxjs'; const foo = new Observable(subscriber => {  console.log('Hello');  subscriber.next(42);  subscriber.next(100);  subscriber.next(200);  setTimeout(() => {    subscriber.next(300); // happens asynchronously  }, 1000);}); console.log('before');foo.subscribe(x => {  console.log(x);});console.log('after');