Last active
September 16, 2019 04:58
-
-
Save tomastrajan/f23c8ca93318915bbb6b69af4ac0cbaf to your computer and use it in GitHub Desktop.
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
export function cancelable() : MethodDecorator { | |
return function ( target : any, propertyKey : string, descriptor : PropertyDescriptor ) { | |
const originalFn = descriptor.value; | |
const subject = new BehaviorSubject(undefined); | |
const result$ = subject.asObservable().switchMap(args => originalFn(...args)); | |
descriptor.value = (...args) => { | |
subject.next(args); | |
return result$; | |
}; | |
return descriptor; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment