Open Rush opened 6 years ago
I have just figured out a way to use memoizee for RxJS:
import { Observable } from 'rxjs'; import { publishReplay, refCount } from 'rxjs/operators'; import * as memoizee from 'memoizee'; type ObservableFunction = <T>(args: any[]) => Observable<T>; export function memoizeObservable(toWrap: ObservableFunction, options: memoizee.Options) { const newOptions = Object.assign({}, options); return memoizee(function(this: any, ...args: any[]) { const result$ = toWrap.apply(this, args); return result$.pipe(publishReplay(1)).pipe(refCount()); }, newOptions); }
Is there a chance you're going to support this out of the box or would you rather see a library "memoizee-rxjs" or something along these lines?
Anyway - sharing this snippet here in case somebody finds it useful.
@Rush can you reedit your message, so example is in plain JavaScript? Otherwise it's hard for me to relate to it.
Will do
I have just figured out a way to use memoizee for RxJS:
Is there a chance you're going to support this out of the box or would you rather see a library "memoizee-rxjs" or something along these lines?
Anyway - sharing this snippet here in case somebody finds it useful.