Skip to content

Instantly share code, notes, and snippets.

@tomastrajan
Last active September 16, 2019 04:58
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 tomastrajan/f23c8ca93318915bbb6b69af4ac0cbaf to your computer and use it in GitHub Desktop.
Save tomastrajan/f23c8ca93318915bbb6b69af4ac0cbaf to your computer and use it in GitHub Desktop.
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