1 | import { IHookStateInitAction, IHookStateSetAction } from './misc/hookState';
|
---|
2 | export interface ListActions<T> {
|
---|
3 | /**
|
---|
4 | * @description Set new list instead old one
|
---|
5 | */
|
---|
6 | set: (newList: IHookStateSetAction<T[]>) => void;
|
---|
7 | /**
|
---|
8 | * @description Add item(s) at the end of list
|
---|
9 | */
|
---|
10 | push: (...items: T[]) => void;
|
---|
11 | /**
|
---|
12 | * @description Replace item at given position. If item at given position not exists it will be set.
|
---|
13 | */
|
---|
14 | updateAt: (index: number, item: T) => void;
|
---|
15 | /**
|
---|
16 | * @description Insert item at given position, all items to the right will be shifted.
|
---|
17 | */
|
---|
18 | insertAt: (index: number, item: T) => void;
|
---|
19 | /**
|
---|
20 | * @description Replace all items that matches predicate with given one.
|
---|
21 | */
|
---|
22 | update: (predicate: (a: T, b: T) => boolean, newItem: T) => void;
|
---|
23 | /**
|
---|
24 | * @description Replace first item matching predicate with given one.
|
---|
25 | */
|
---|
26 | updateFirst: (predicate: (a: T, b: T) => boolean, newItem: T) => void;
|
---|
27 | /**
|
---|
28 | * @description Like `updateFirst` bit in case of predicate miss - pushes item to the list
|
---|
29 | */
|
---|
30 | upsert: (predicate: (a: T, b: T) => boolean, newItem: T) => void;
|
---|
31 | /**
|
---|
32 | * @description Sort list with given sorting function
|
---|
33 | */
|
---|
34 | sort: (compareFn?: (a: T, b: T) => number) => void;
|
---|
35 | /**
|
---|
36 | * @description Same as native Array's method
|
---|
37 | */
|
---|
38 | filter: (callbackFn: (value: T, index?: number, array?: T[]) => boolean, thisArg?: any) => void;
|
---|
39 | /**
|
---|
40 | * @description Removes item at given position. All items to the right from removed will be shifted.
|
---|
41 | */
|
---|
42 | removeAt: (index: number) => void;
|
---|
43 | /**
|
---|
44 | * @deprecated Use removeAt method instead
|
---|
45 | */
|
---|
46 | remove: (index: number) => void;
|
---|
47 | /**
|
---|
48 | * @description Make the list empty
|
---|
49 | */
|
---|
50 | clear: () => void;
|
---|
51 | /**
|
---|
52 | * @description Reset list to initial value
|
---|
53 | */
|
---|
54 | reset: () => void;
|
---|
55 | }
|
---|
56 | declare function useList<T>(initialList?: IHookStateInitAction<T[]>): [T[], ListActions<T>];
|
---|
57 | export default useList;
|
---|