Skip to content

Instantly share code, notes, and snippets.

@a88zach
Created February 27, 2018 19:03
Show Gist options
  • Save a88zach/f5395d4feb0cb5bbd57bd7ce68747613 to your computer and use it in GitHub Desktop.
Save a88zach/f5395d4feb0cb5bbd57bd7ce68747613 to your computer and use it in GitHub Desktop.
Extending rxjs
import { Observable } from 'rxjs/Observable';
function extractMap<T>(this: Observable<T>): Observable<T> {
return this.map(json => {
const data = <any>json;
return data.success ? data.result : Observable.throw('Response contained an unsuccessful status');
});
}
Observable.prototype.extractMap = extractMap;
declare module 'rxjs/Observable' {
interface Observable<T> {
extractMap: typeof extractMap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment