Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: memoizing observables #98

Open
Rush opened this issue Sep 7, 2018 · 2 comments
Open

Idea: memoizing observables #98

Rush opened this issue Sep 7, 2018 · 2 comments
Assignees
Labels

Comments

@Rush
Copy link

Rush commented Sep 7, 2018

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.

@medikoo medikoo self-assigned this Sep 10, 2018
@medikoo
Copy link
Owner

medikoo commented Sep 10, 2018

@Rush can you reedit your message, so example is in plain JavaScript? Otherwise it's hard for me to relate to it.

@medikoo medikoo assigned Rush and unassigned medikoo Sep 10, 2018
@Rush
Copy link
Author

Rush commented Sep 19, 2018

Will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants