-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathconfig.ts
More file actions
207 lines (191 loc) · 6.12 KB
/
Copy pathconfig.ts
File metadata and controls
207 lines (191 loc) · 6.12 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { ActionCreator, ActionReducer, Action } from '@ngrx/store';
import { InjectionToken } from '@angular/core';
export type ActionSanitizer = (action: Action, id: number) => Action;
export type StateSanitizer = (state: any, index: number) => any;
export type SerializationOptions = {
options?: boolean | any;
replacer?: (key: any, value: any) => {};
reviver?: (key: any, value: any) => {};
immutable?: any;
refs?: Array<any>;
};
export type Predicate = (state: any, action: Action) => boolean;
/**
* Chrome extension documentation
* @see https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md#features
* Firefox extension documentation
* @see https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#features
*/
export interface DevToolsFeatureOptions {
/**
* Start/pause recording of dispatched actions
*/
pause?: boolean;
/**
* Lock/unlock dispatching actions and side effects
*/
lock?: boolean;
/**
* Persist states on page reloading
*/
persist?: boolean;
/**
* Export history of actions in a file
*/
export?: boolean;
/**
* Import history of actions from a file
*/
import?: 'custom' | boolean;
/**
* Jump back and forth (time travelling)
*/
jump?: boolean;
/**
* Skip (cancel) actions
*/
skip?: boolean;
/**
* Drag and drop actions in the history list
*/
reorder?: boolean;
/**
* Dispatch custom actions or action creators
*/
dispatch?: boolean;
/**
* Generate tests for the selected actions
*/
test?: boolean;
}
/**
* Chrome extension documentation
* @see https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md
* Firefox extension documentation
* @see https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md
*/
export class StoreDevtoolsConfig {
/**
* Maximum allowed actions to be stored in the history tree (default: `false`)
*/
maxAge: number | false = false;
monitor?: ActionReducer<any, any>;
/**
* Function which takes `action` object and id number as arguments, and should return `action` object back.
*/
actionSanitizer?: ActionSanitizer;
/**
* Function which takes `state` object and index as arguments, and should return `state` object back.
*/
stateSanitizer?: StateSanitizer;
/**
* The instance name to be shown on the monitor page (default: `document.title`)
*/
name?: string;
serialize?: boolean | SerializationOptions;
logOnly?: boolean;
features?: DevToolsFeatureOptions;
/**
* Action types to be hidden in the monitors. If `actionsSafelist` specified, `actionsBlocklist` is ignored.
*/
actionsBlocklist?: string[];
/**
* Action types to be shown in the monitors
*/
actionsSafelist?: string[];
/**
* Called for every action before sending, takes state and action object, and returns true in case it allows sending the current data to the monitor.
*/
predicate?: Predicate;
/**
* Auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use.
*/
autoPause?: boolean;
/**
* If set to true, will include stack trace for every dispatched action
*/
trace?: boolean | (() => string);
/**
* Maximum stack trace frames to be stored (in case trace option was provided as true).
*/
traceLimit?: number;
/**
* The property determines whether the extension connection is established within the
* Angular zone or not. It is set to `false` by default.
*/
connectInZone?: boolean;
/**
* Action creators to make available in the extension's dispatcher,
* so actions can be dispatched manually from the extension.
*/
actionCreators?: ActionCreator[] | Record<string, ActionCreator>;
}
export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>(
'@ngrx/store-devtools Options'
);
/**
* Used to provide a `StoreDevtoolsConfig` for the store-devtools.
*/
export const INITIAL_OPTIONS = new InjectionToken<StoreDevtoolsConfig>(
'@ngrx/store-devtools Initial Config'
);
export type StoreDevtoolsOptions =
| Partial<StoreDevtoolsConfig>
| (() => Partial<StoreDevtoolsConfig>);
export function noMonitor(): null {
return null;
}
export const DEFAULT_NAME = 'NgRx Store DevTools';
export function createConfig(
optionsInput: StoreDevtoolsOptions
): StoreDevtoolsConfig {
const DEFAULT_OPTIONS: StoreDevtoolsConfig = {
maxAge: false,
monitor: noMonitor,
actionSanitizer: undefined,
stateSanitizer: undefined,
actionCreators: undefined,
name: DEFAULT_NAME,
serialize: false,
logOnly: false,
autoPause: false,
trace: false,
traceLimit: 75,
// Add all features explicitly. This prevent buggy behavior for
// options like "lock" which might otherwise not show up.
features: {
pause: true, // Start/pause recording of dispatched actions
lock: true, // Lock/unlock dispatching actions and side effects
persist: true, // Persist states on page reloading
export: true, // Export history of actions in a file
import: 'custom', // Import history of actions from a file
jump: true, // Jump back and forth (time travelling)
skip: true, // Skip (cancel) actions
reorder: true, // Drag and drop actions in the history list
dispatch: true, // Dispatch custom actions or action creators
test: true, // Generate tests for the selected actions
},
connectInZone: false,
};
const options =
typeof optionsInput === 'function' ? optionsInput() : optionsInput;
const logOnly = options.logOnly
? { pause: true, export: true, test: true }
: false;
const features: NonNullable<Partial<StoreDevtoolsConfig['features']>> =
options.features ||
logOnly ||
(DEFAULT_OPTIONS.features as NonNullable<
Partial<StoreDevtoolsConfig['features']>
>);
if (features.import === true) {
features.import = 'custom';
}
const config = Object.assign({}, DEFAULT_OPTIONS, { features }, options);
if (config.maxAge && config.maxAge < 2) {
throw new Error(
`Devtools 'maxAge' cannot be less than 2, got ${config.maxAge}`
);
}
return config;
}