Created
February 27, 2018 19:03
-
-
Save a88zach/f5395d4feb0cb5bbd57bd7ce68747613 to your computer and use it in GitHub Desktop.
Extending rxjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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