-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathmodels.ts
180 lines (150 loc) · 4.94 KB
/
models.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { type ValueEqualityFn } from '@angular/core';
export interface Action {
type: string;
}
// declare to make it property-renaming safe
export declare interface TypedAction<T extends string> extends Action {
readonly type: T;
}
export type ActionType<A> = A extends ActionCreator<infer T, infer C>
? ReturnType<C> & { type: T }
: never;
export type TypeId<T> = () => T;
export type InitialState<T> = Partial<T> | TypeId<Partial<T>> | void;
/**
* A function that takes an `Action` and a `State`, and returns a `State`.
* See `createReducer`.
*/
export interface ActionReducer<T, V extends Action = Action> {
(state: T | undefined, action: V): T;
}
export type ActionReducerMap<T, V extends Action = Action> = {
[p in keyof T]: ActionReducer<T[p], V>;
};
export interface ActionReducerFactory<T, V extends Action = Action> {
(
reducerMap: ActionReducerMap<T, V>,
initialState?: InitialState<T>
): ActionReducer<T, V>;
}
export type MetaReducer<T = any, V extends Action = Action> = (
reducer: ActionReducer<T, V>
) => ActionReducer<T, V>;
export interface StoreFeature<T, V extends Action = Action> {
key: string;
reducers: ActionReducerMap<T, V> | ActionReducer<T, V>;
reducerFactory: ActionReducerFactory<T, V>;
initialState?: InitialState<T>;
metaReducers?: MetaReducer<T, V>[];
}
export type Selector<T, V> = (state: T) => V;
/**
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
*/
export type SelectorWithProps<State, Props, Result> = (
state: State,
props: Props
) => Result;
export const arraysAreNotAllowedMsg = 'action creator cannot return an array';
type ArraysAreNotAllowed = typeof arraysAreNotAllowedMsg;
export const typePropertyIsNotAllowedMsg =
'action creator cannot return an object with a property named `type`';
type TypePropertyIsNotAllowed = typeof typePropertyIsNotAllowedMsg;
export const emptyObjectsAreNotAllowedMsg =
'action creator cannot return an empty object';
type EmptyObjectsAreNotAllowed = typeof emptyObjectsAreNotAllowedMsg;
export const arraysAreNotAllowedInProps =
'action creator props cannot be an array';
type ArraysAreNotAllowedInProps = typeof arraysAreNotAllowedInProps;
export const typePropertyIsNotAllowedInProps =
'action creator props cannot have a property named `type`';
type TypePropertyIsNotAllowedInProps = typeof typePropertyIsNotAllowedInProps;
export const emptyObjectsAreNotAllowedInProps =
'action creator props cannot be an empty object';
type EmptyObjectsAreNotAllowedInProps = typeof emptyObjectsAreNotAllowedInProps;
export const primitivesAreNotAllowedInProps =
'action creator props cannot be a primitive value';
type PrimitivesAreNotAllowedInProps = typeof primitivesAreNotAllowedInProps;
export type FunctionIsNotAllowed<
T,
ErrorMessage extends string
> = T extends Function ? ErrorMessage : T;
/**
* A function that returns an object in the shape of the `Action` interface. Configured using `createAction`.
*/
export type Creator<
P extends any[] = any[],
R extends object = object
> = FunctionWithParametersType<P, R>;
export type Primitive =
| string
| number
| bigint
| boolean
| symbol
| null
| undefined;
export type NotAllowedCheck<T extends object> = T extends any[]
? ArraysAreNotAllowed
: T extends { type: any }
? TypePropertyIsNotAllowed
: keyof T extends never
? EmptyObjectsAreNotAllowed
: unknown;
export type NotAllowedInPropsCheck<T> = T extends object
? T extends any[]
? ArraysAreNotAllowedInProps
: T extends { type: any }
? TypePropertyIsNotAllowedInProps
: keyof T extends never
? EmptyObjectsAreNotAllowedInProps
: unknown
: T extends Primitive
? PrimitivesAreNotAllowedInProps
: never;
/**
* See `Creator`.
*/
export type ActionCreator<
T extends string = string,
C extends Creator = Creator
> = C & TypedAction<T>;
export interface ActionCreatorProps<T> {
_as: 'props';
_p: T;
}
export type FunctionWithParametersType<P extends unknown[], R = void> = (
...args: P
) => R;
export interface RuntimeChecks {
/**
* Verifies if the state is serializable
*/
strictStateSerializability: boolean;
/**
* Verifies if the actions are serializable. Please note, you may not need to set it to `true` unless you are storing/replaying actions using external resources, for example `localStorage`.
*/
strictActionSerializability: boolean;
/**
* Verifies that the state isn't mutated
*/
strictStateImmutability: boolean;
/**
* Verifies that actions aren't mutated
*/
strictActionImmutability: boolean;
/**
* Verifies that actions are dispatched within NgZone
*/
strictActionWithinNgZone: boolean;
/**
* Verifies that action types are not registered more than once
*/
strictActionTypeUniqueness?: boolean;
}
export interface SelectSignalOptions<T> {
/**
* A comparison function which defines equality for select results.
*/
equal?: ValueEqualityFn<T>;
}