-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.ts
110 lines (94 loc) · 2.66 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type {
IDynAdapterFilters,
IDynAdapterSort,
IDynDerivedAPI,
IDynIndexerAPI,
DynArrayData,
DynMapData,
DynDataHost,
DynDataOptions } from './';
import type { DynMapReducer } from '../map';
import type { DynArrayReducer } from '../array';
/**
* Defines the shape of a dynamic array constructor function.
*/
export interface IDynArrayReducerCtor<T>
{
new (data?: Iterable<T> | DynArrayData<T>): DynArrayReducer<T>;
}
/**
* Defines the shape of a dynamic map constructor function.
*/
export interface IDynMapReducerCtor<K, T>
{
new (data?: Map<K, T> | DynMapData<K, T>): DynMapReducer<K, T>;
}
/**
* Defines the shape of a derived reducer constructor function.
*/
export interface IDynDerivedReducerCtor<T>
{
new (hostData: DynDataHost<any>, parentIndex: IDynIndexerAPI<any, T>, options: DynDataOptions<T>): IDynDerivedReducer<any, any, T>;
}
/**
* Defines the interface for a derived reducer.
*/
export interface IDynDerivedReducer<D, K, T>
{
/**
* Returns the internal data of this instance. Be careful!
*
* Note: if an array is set as initial data then that array is used as the internal data. If any changes are
* performed to the data externally do invoke `update` via {@link IDynDerivedReducer.index} with `true` to
* recalculate the index and notify all subscribers.
*
* @returns The internal data.
*/
get data(): D | null;
/**
* @returns Derived public API.
*/
get derived(): IDynDerivedAPI<D, K, T>
/**
* @returns The filters adapter.
*/
get filters(): IDynAdapterFilters<T>;
/**
* @returns Returns the Indexer public API.
*/
get index(): IDynIndexerAPI<K, T>;
/**
* Returns whether this derived reducer is destroyed.
*/
get destroyed(): boolean;
/**
* @returns Main data / items length or indexed length.
*/
get length(): number;
/**
* @returns Gets current reversed state.
*/
get reversed(): boolean;
/**
* @returns The sort adapter.
*/
get sort(): IDynAdapterSort<T>;
/**
* Sets reversed state and notifies subscribers.
*
* @param reversed - New reversed state.
*/
set reversed(reversed: boolean);
/**
* Removes all derived reducers, subscriptions, and cleans up all resources.
*/
destroy(): void;
/**
* Subscribe to this IDerivedReducer.
*
* @param handler - Callback function that is invoked on update / changes. Receives derived reducer reference.
*
* @returns Unsubscribe function.
*/
subscribe(handler: (value: IDynDerivedReducer<D, K, T>) => void): () => void;
}