Skip to content

Instantly share code, notes, and snippets.

@Ibro
Last active April 26, 2017 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ibro/6d6bf6ca4ac8d46d3099dceb458157e7 to your computer and use it in GitHub Desktop.
Save Ibro/6d6bf6ca4ac8d46d3099dceb458157e7 to your computer and use it in GitHub Desktop.
Using Observable.create() - Coding Blast - www.codingblast.com
import { Observable } from 'rxjs';
interface ISimpleObserver<T> {
next: (value: T) => void;
error: (err: any) => void;
complete: () => void;
}
let words = ['coding blast', 'coding', 'blast'];
let source = Observable.create(function onSubscription(observer: ISimpleObserver<string>) {
for (let word of words) {
observer.next(word);
}
observer.complete();
});
source.subscribe(next, error, complete);
function next(value: any) {
console.log('next: ', value);
}
function error(err: any) {
console.log('error: ', err);
}
function complete() {
console.log('complete');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment