Defines the data object and sort / comparison function returned by DynReducerHelper.sort.objectByPath providing managed sorting and comparison utility for dynamic reducers.

Several built-in sorting strategies are applied automatically based on the typeof the values being compared. This allows flexible, type-aware sorting without requiring a custom compare function for common data types.

Type (typeof value) Behavior
string Lexicographic order using String.prototype.localeCompare().
number Numeric ascending order using subtraction (a - b).
boolean false sorts before true via numeric coercion (Number(a) - Number(b)).
bigint Numeric ascending order using relational comparison (a < b ? -1 : a > b ? 1 : 0).
object Special handling for Date objects sorted by getTime(); other objects compare as equal.
undefined Treated as the lowest possible value (always sorts first).
Other types (symbol, function) Not ordered — treated as equal and left in original sequence.

Users may provide their own comparator configuration via the customCompareFnMap option, which can be:

  • A plain function (a, b) => number.
  • An object with a .compare(a, b) method.
  • A static class exposing a .compare(a, b) method.

These custom comparators override the default typeof handling for the property keys specified in the customCompareFnMap.

interface ObjectByPath<T> {
    compare: CompareFn<T>;
    get path(): PropertyPath;
    get state(): string;
    getCustomCompareFnMap(): PropertyPathMap<
        DynReducer.Data.Sort<T>
        | CompareFn<T>,
    >;
    reset(): void;
    set(data: ObjectByPathData): void;
    setCustomCompareFnMap(
        customCompareFnMap: PropertyPathMap<
            DynReducer.Data.Sort<T>
            | CompareFn<T>,
        >,
    ): void;
    subscribe(
        this: void,
        run: Subscriber<ObjectByPathData>,
        invalidate?: Invalidator<ObjectByPathData>,
    ): Unsubscriber;
    togglePath(path: PropertyPath): void;
}

Type Parameters

  • T
Hierarchy
Index
  • get state(): string

    Get the current sort state:

    - `none` no sorting.
    - `asc` ascending sort.
    - `desc` descending sort.

    Returns string

  • Resets prop and state.

    Returns void

  • Sets the current sorted object property and sort state. You may provide partial data, but state must be one of: none, asc, or desc.

    Parameters

    Returns void

  • Toggles current prop state and or initializes a new prop sort state. A property that is selected multiple times will cycle through ascending -> descending -> no sorting.

    Parameters

    Returns void

compare: CompareFn<T>

A callback function that compares two values.