Function default

  • Description

    memoize a function based its arguments passed, potentially improving runtime performance

    Example

    import moize from 'moize';

    // standard implementation
    const fn = (foo, bar) => `${foo} ${bar}`;
    const memoizedFn = moize(fn);

    // implementation with options
    const fn = async (id) => get(`http://foo.com/${id}`);
    const memoizedFn = moize(fn, {isPromise: true, maxSize: 5});

    // implementation with convenience methods
    const Foo = ({foo}) => <div>{foo}</div>;
    const MemoizedFoo = moize.react(Foo);

    Type Parameters

    • MoizeableFn extends Moizeable

    Parameters

    • fn: MoizeableFn

      the function to memoized, or a list of options when currying

    Returns Moized<MoizeableFn, Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<MoizeableFn>;
        onCacheChange: OnCacheOperation<MoizeableFn>;
        onCacheHit: OnCacheOperation<MoizeableFn>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<Moizeable>;
        onCacheChange: OnCacheOperation<Moizeable>;
        onCacheHit: OnCacheOperation<Moizeable>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }>>

    the memoized function

  • Description

    memoize a function based its arguments passed, potentially improving runtime performance

    Example

    import moize from 'moize';

    // standard implementation
    const fn = (foo, bar) => `${foo} ${bar}`;
    const memoizedFn = moize(fn);

    // implementation with options
    const fn = async (id) => get(`http://foo.com/${id}`);
    const memoizedFn = moize(fn, {isPromise: true, maxSize: 5});

    // implementation with convenience methods
    const Foo = ({foo}) => <div>{foo}</div>;
    const MemoizedFoo = moize.react(Foo);

    Type Parameters

    • MoizeableFn extends Moizeable

    • PassedOptions extends Partial<{
          isDeepEqual: boolean;
          isPromise: boolean;
          isReact: boolean;
          isSerialized: boolean;
          isShallowEqual: boolean;
          matchesArg: IsEqual;
          matchesKey: IsMatchingKey;
          maxAge: number;
          maxArgs: number;
          maxSize: number;
          onCacheAdd: OnCacheOperation<MoizeableFn>;
          onCacheChange: OnCacheOperation<MoizeableFn>;
          onCacheHit: OnCacheOperation<MoizeableFn>;
          onExpire: OnExpire;
          profileName: string;
          serializer: Serialize;
          transformArgs: TransformKey;
          updateCacheForKey: UpdateCacheForKey;
          updateExpire: boolean;
      }>

    Parameters

    • fn: MoizeableFn

      the function to memoized, or a list of options when currying

    • options: PassedOptions

      the options to apply

    Returns Moized<MoizeableFn, Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<MoizeableFn>;
        onCacheChange: OnCacheOperation<MoizeableFn>;
        onCacheHit: OnCacheOperation<MoizeableFn>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<Moizeable>;
        onCacheChange: OnCacheOperation<Moizeable>;
        onCacheHit: OnCacheOperation<Moizeable>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & PassedOptions>

    the memoized function

  • Description

    memoize a function based its arguments passed, potentially improving runtime performance

    Example

    import moize from 'moize';

    // standard implementation
    const fn = (foo, bar) => `${foo} ${bar}`;
    const memoizedFn = moize(fn);

    // implementation with options
    const fn = async (id) => get(`http://foo.com/${id}`);
    const memoizedFn = moize(fn, {isPromise: true, maxSize: 5});

    // implementation with convenience methods
    const Foo = ({foo}) => <div>{foo}</div>;
    const MemoizedFoo = moize.react(Foo);

    Type Parameters

    • MoizedFn extends AnyFn & Record<string, any> & Dictionary<any, MoizedFn> & {
          cache: Cache<Moizeable>;
          fn: Moizeable;
          isMemoized: true;
          options: NormalizedOptions<Moizeable>;
      } & {
          _microMemoizeOptions: Pick<Partial<{
              isDeepEqual: boolean;
              isPromise: boolean;
              isReact: boolean;
              isSerialized: boolean;
              isShallowEqual: boolean;
              matchesArg: IsEqual;
              matchesKey: IsMatchingKey;
              maxAge: number;
              maxArgs: number;
              maxSize: number;
              onCacheAdd: OnCacheOperation<Moizeable>;
              onCacheChange: OnCacheOperation<Moizeable>;
              onCacheHit: OnCacheOperation<Moizeable>;
              onExpire: OnExpire;
              profileName: string;
              serializer: Serialize;
              transformArgs: TransformKey;
              updateCacheForKey: UpdateCacheForKey;
              updateExpire: boolean;
          }>, "isPromise" | "maxSize" | "onCacheAdd" | "onCacheChange" | "onCacheHit"> & {
              isEqual: IsEqual;
              isMatchingKey: IsMatchingKey;
              transformKey: TransformKey;
          };
          cache: Cache<Moizeable>;
          cacheSnapshot: Cache<Moizeable>;
          clear: (() => void);
          clearStats: (() => void);
          contextTypes?: Record<string, Function>;
          defaultProps?: Record<string, unknown>;
          displayName?: string;
          expirations: Expiration[];
          expirationsSnapshot: Expiration[];
          get: ((key) => any);
          getStats: (() => StatsProfile);
          has: ((key) => boolean);
          isCollectingStats: (() => boolean);
          isMoized: (() => true);
          keys: (() => Key[]);
          options: Partial<{
              isDeepEqual: boolean;
              isPromise: boolean;
              isReact: boolean;
              isSerialized: boolean;
              isShallowEqual: boolean;
              matchesArg: IsEqual;
              matchesKey: IsMatchingKey;
              maxAge: number;
              maxArgs: number;
              maxSize: number;
              onCacheAdd: OnCacheOperation<Moizeable>;
              onCacheChange: OnCacheOperation<Moizeable>;
              onCacheHit: OnCacheOperation<Moizeable>;
              onExpire: OnExpire;
              profileName: string;
              serializer: Serialize;
              transformArgs: TransformKey;
              updateCacheForKey: UpdateCacheForKey;
              updateExpire: boolean;
          }>;
          originalFunction: Moizeable;
          propTypes: Record<string, Function>;
          remove: ((key) => void);
          set: ((key, value) => void);
          values: (() => any[]);
      }

    Parameters

    • fn: MoizedFn

      the function to memoized, or a list of options when currying

    Returns Moized<MoizedFn["fn"], Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<MoizedFn>;
        onCacheChange: OnCacheOperation<MoizedFn>;
        onCacheHit: OnCacheOperation<MoizedFn>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<Moizeable>;
        onCacheChange: OnCacheOperation<Moizeable>;
        onCacheHit: OnCacheOperation<Moizeable>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }>>

    the memoized function

  • Description

    memoize a function based its arguments passed, potentially improving runtime performance

    Example

    import moize from 'moize';

    // standard implementation
    const fn = (foo, bar) => `${foo} ${bar}`;
    const memoizedFn = moize(fn);

    // implementation with options
    const fn = async (id) => get(`http://foo.com/${id}`);
    const memoizedFn = moize(fn, {isPromise: true, maxSize: 5});

    // implementation with convenience methods
    const Foo = ({foo}) => <div>{foo}</div>;
    const MemoizedFoo = moize.react(Foo);

    Type Parameters

    • MoizedFn extends AnyFn & Record<string, any> & Dictionary<any, MoizedFn> & {
          cache: Cache<Moizeable>;
          fn: Moizeable;
          isMemoized: true;
          options: NormalizedOptions<Moizeable>;
      } & {
          _microMemoizeOptions: Pick<Partial<{
              isDeepEqual: boolean;
              isPromise: boolean;
              isReact: boolean;
              isSerialized: boolean;
              isShallowEqual: boolean;
              matchesArg: IsEqual;
              matchesKey: IsMatchingKey;
              maxAge: number;
              maxArgs: number;
              maxSize: number;
              onCacheAdd: OnCacheOperation<Moizeable>;
              onCacheChange: OnCacheOperation<Moizeable>;
              onCacheHit: OnCacheOperation<Moizeable>;
              onExpire: OnExpire;
              profileName: string;
              serializer: Serialize;
              transformArgs: TransformKey;
              updateCacheForKey: UpdateCacheForKey;
              updateExpire: boolean;
          }>, "isPromise" | "maxSize" | "onCacheAdd" | "onCacheChange" | "onCacheHit"> & {
              isEqual: IsEqual;
              isMatchingKey: IsMatchingKey;
              transformKey: TransformKey;
          };
          cache: Cache<Moizeable>;
          cacheSnapshot: Cache<Moizeable>;
          clear: (() => void);
          clearStats: (() => void);
          contextTypes?: Record<string, Function>;
          defaultProps?: Record<string, unknown>;
          displayName?: string;
          expirations: Expiration[];
          expirationsSnapshot: Expiration[];
          get: ((key) => any);
          getStats: (() => StatsProfile);
          has: ((key) => boolean);
          isCollectingStats: (() => boolean);
          isMoized: (() => true);
          keys: (() => Key[]);
          options: Partial<{
              isDeepEqual: boolean;
              isPromise: boolean;
              isReact: boolean;
              isSerialized: boolean;
              isShallowEqual: boolean;
              matchesArg: IsEqual;
              matchesKey: IsMatchingKey;
              maxAge: number;
              maxArgs: number;
              maxSize: number;
              onCacheAdd: OnCacheOperation<Moizeable>;
              onCacheChange: OnCacheOperation<Moizeable>;
              onCacheHit: OnCacheOperation<Moizeable>;
              onExpire: OnExpire;
              profileName: string;
              serializer: Serialize;
              transformArgs: TransformKey;
              updateCacheForKey: UpdateCacheForKey;
              updateExpire: boolean;
          }>;
          originalFunction: Moizeable;
          propTypes: Record<string, Function>;
          remove: ((key) => void);
          set: ((key, value) => void);
          values: (() => any[]);
      }

    • PassedOptions extends Partial<{
          isDeepEqual: boolean;
          isPromise: boolean;
          isReact: boolean;
          isSerialized: boolean;
          isShallowEqual: boolean;
          matchesArg: IsEqual;
          matchesKey: IsMatchingKey;
          maxAge: number;
          maxArgs: number;
          maxSize: number;
          onCacheAdd: OnCacheOperation<MoizedFn>;
          onCacheChange: OnCacheOperation<MoizedFn>;
          onCacheHit: OnCacheOperation<MoizedFn>;
          onExpire: OnExpire;
          profileName: string;
          serializer: Serialize;
          transformArgs: TransformKey;
          updateCacheForKey: UpdateCacheForKey;
          updateExpire: boolean;
      }>

    Parameters

    • fn: MoizedFn

      the function to memoized, or a list of options when currying

    • options: PassedOptions

      the options to apply

    Returns Moized<MoizedFn["fn"], Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<MoizedFn>;
        onCacheChange: OnCacheOperation<MoizedFn>;
        onCacheHit: OnCacheOperation<MoizedFn>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & Partial<{
        isDeepEqual: boolean;
        isPromise: boolean;
        isReact: boolean;
        isSerialized: boolean;
        isShallowEqual: boolean;
        matchesArg: IsEqual;
        matchesKey: IsMatchingKey;
        maxAge: number;
        maxArgs: number;
        maxSize: number;
        onCacheAdd: OnCacheOperation<Moizeable>;
        onCacheChange: OnCacheOperation<Moizeable>;
        onCacheHit: OnCacheOperation<Moizeable>;
        onExpire: OnExpire;
        profileName: string;
        serializer: Serialize;
        transformArgs: TransformKey;
        updateCacheForKey: UpdateCacheForKey;
        updateExpire: boolean;
    }> & PassedOptions>

    the memoized function

  • Description

    memoize a function based its arguments passed, potentially improving runtime performance

    Example

    import moize from 'moize';

    // standard implementation
    const fn = (foo, bar) => `${foo} ${bar}`;
    const memoizedFn = moize(fn);

    // implementation with options
    const fn = async (id) => get(`http://foo.com/${id}`);
    const memoizedFn = moize(fn, {isPromise: true, maxSize: 5});

    // implementation with convenience methods
    const Foo = ({foo}) => <div>{foo}</div>;
    const MemoizedFoo = moize.react(Foo);

    Type Parameters

    • PassedOptions extends Partial<{
          isDeepEqual: boolean;
          isPromise: boolean;
          isReact: boolean;
          isSerialized: boolean;
          isShallowEqual: boolean;
          matchesArg: IsEqual;
          matchesKey: IsMatchingKey;
          maxAge: number;
          maxArgs: number;
          maxSize: number;
          onCacheAdd: OnCacheOperation<Moizeable>;
          onCacheChange: OnCacheOperation<Moizeable>;
          onCacheHit: OnCacheOperation<Moizeable>;
          onExpire: OnExpire;
          profileName: string;
          serializer: Serialize;
          transformArgs: TransformKey;
          updateCacheForKey: UpdateCacheForKey;
          updateExpire: boolean;
      }>

    Parameters

    • options: PassedOptions

      the options to apply

    Returns Moizer<PassedOptions>

    the memoized function

Generated using TypeDoc