pure
    Preparing search index...

    Type Alias LatestConstructor<TFn>

    type LatestConstructor<TFn extends AnyFn> = {
        areArgsEqual?: (a: Parameters<TFn>, b: Parameters<TFn>) => boolean;
        fn: TFn;
        updateArgs?: UpdateArgsFn<TFn>;
    }

    Type Parameters

    Index

    Properties

    areArgsEqual?: (a: Parameters<TFn>, b: Parameters<TFn>) => boolean

    Optional function to compare if arguments of 2 calls are equal.

    By default, separate calls are considered different, and the result of the latest call will be returned. However, if the function is pure, and the argument of a new call is the same as the call being executed, then the result of the call being executed will be returned. In other words, the new call will not result in another execution of the function.

    fn: TFn

    Function to be wrapped

    updateArgs?: UpdateArgsFn<TFn>

    Optional function to update the arguments.

    By default, when new calls are made while the previous call is being executed, The function will be executed again with the latest arguments. This function is used to change this behavior and is called when new calls are made. In other words, the default value for this function is (_current, _middle, latest) => latest.

    The arguments are:

    • current: The arguments of the call currently being executed
    • latest: The argument of this new call
    • middle: If more than one call is made while the previous call is being executed, this array contains arguments of the calls between current and latest
    • next: This is the returned value of the previous call to updateArgs, i.e. the args to be executed next.