Interface ObjectByPath<T>
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;
}
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
- Omit<DynReducer.Data.Sort<T>, "subscribe">
- Readable<ObjectByPathData>
- ObjectByPath (View Summary)
Accessors
path
-
Get the current object property being sorted.
Returns PropertyPath
state
-
get state(): string
Get the current sort state:
- `none` no sorting.
- `asc` ascending sort.
- `desc` descending sort.Returns string
Methods
getCustomCompareFnMap
-
Returns any current custom compare function lookup map.
Returns PropertyPathMap<DynReducer.Data.Sort<T> | CompareFn<T>>
reset
-
Resets
propandstate.Returns void
set
-
Sets the current sorted object property and sort state. You may provide partial data, but state must be one of:
none,asc, ordesc.Parameters
- data: ObjectByPathData
New prop / state data to set.
Returns void
- data: ObjectByPathData
setCustomCompareFnMap
-
setCustomCompareFnMap(
customCompareFnMap: PropertyPathMap<
DynReducer.Data.Sort<T>
| CompareFn<T>,
>,
): voidSets the current custom compare function lookup map for object properties that require unique sorting.
Parameters
- customCompareFnMap: PropertyPathMap<DynReducer.Data.Sort<T> | CompareFn<T>>
New custom compare function map to set.
Returns void
- customCompareFnMap: PropertyPathMap<DynReducer.Data.Sort<T> | CompareFn<T>>
subscribe
-
subscribe(
this: void,
run: Subscriber<ObjectByPathData>,
invalidate?: Invalidator<ObjectByPathData>,
): UnsubscriberSubscribe on value changes.
Parameters
- this: void
- run: Subscriber<ObjectByPathData>
subscription callback
Optionalinvalidate: Invalidator<ObjectByPathData>cleanup callback
Returns Unsubscriber
togglePath
-
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
- path: PropertyPath
Object property path to activate.
Returns void
- path: PropertyPath
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
typeofthe values being compared. This allows flexible, type-aware sorting without requiring a custom compare function for common data types.Built-in
typeofhandlingtypeofvalue)stringString.prototype.localeCompare().numbera - b).booleanfalsesorts beforetruevia numeric coercion (Number(a) - Number(b)).biginta < b ? -1 : a > b ? 1 : 0).objectDateobjects sorted bygetTime(); other objects compare as equal.undefinedsymbol,function)Custom comparison
Users may provide their own comparator configuration via the
customCompareFnMapoption, which can be:(a, b) => number..compare(a, b)method..compare(a, b)method.These custom comparators override the default
typeofhandling for the property keys specified in thecustomCompareFnMap.