Skip to content

Documentation unclear of how the memoizer is used #455

Closed

Description

@Mr-Wallet

The README describes how createSelectorCreator can be used to override the defaultMemoizer and how it will be called with the resultFunc and additional memoizeOptions. However, if my reading of the source code is correct, it's also called before calling the input functions to short-circuit their evaluation, and that isn't called with the memoizeOptions. These are important details for implementing a custom memoizer, so it seems like an oversight in the documentation.

Activity

  1. srubin commented on Jun 24, 2020

    @srubin

    This bit me recently. I'd appreciate being able to specify a different memoize function for the two purposes. I guess I could do this using memoizeOptions:

    function memoizeInputArgs(fn) { /* ... */ }
    function memoizeResultArgs(fn) { /* ... */ }
    
    const selector = createSelectorCreator((fn, isResultFunction) =>
      isResultFunction ? memoizeResultArgs(fn) : memoizeInputArgs(fn), true)
    );

    but it might be cleaner to allow passing a second memoize function to createSelectorCreator.

  2. srubin commented on Jun 24, 2020

    @srubin

    I ended up with this slightly more fleshed-out version:

    type MemoizeFn = (func: Function, option1?: any, option2?: any, option3?: any) => any;
    
    export function myCreateSelectorCreator(
        memoizeResultFnArgs: MemoizeFn,
        memoizeResultFnArgsOptions: any[] = [],
        memoizeInputFnArgs: MemoizeFn = defaultMemoize,
        memoizeInputFnArgsOptions: any[] = [],
    ) {
        function memoize(fn: Function, areResultArgs: boolean) {
            if (areResultArgs) {
                return memoizeResultFnArgs(fn, ...memoizeResultFnArgsOptions);
            }
            return memoizeInputFnArgs(fn, ...memoizeInputFnArgsOptions);
        }
        return createSelectorCreator(
            memoize,
            true, // only passed to `memoize` for result args, not input args
        );
    }
  3. added
    Documentation
    on Oct 17, 2021
  4. markerikson commented on Oct 20, 2021

    @markerikson
    Contributor

    This is mostly a duplicate of #376 and related to #359 .

  5. added a commit that references this issue on Nov 11, 2023
  6. aryaemami59 commented on Mar 16, 2024

    @aryaemami59
    Member

    This one has been resolved by #636.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CachingDocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions