forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.js
291 lines (260 loc) · 7.8 KB
/
state.js
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import type {
Action,
DataSource,
PreviewSelection,
ImplementationFilter,
CallTreeSummaryStrategy,
RequestedLib,
TrackReference,
TimelineType,
CheckedSharingOptions,
} from './actions';
import type { TabSlug } from '../app-logic/tabs-handling';
import type { StartEndRange, CssPixels, Milliseconds } from './units';
import type { Profile, ThreadIndex, Pid, BrowsingContextID } from './profile';
import type {
CallNodePath,
GlobalTrack,
LocalTrack,
TrackIndex,
MarkerIndex,
ActiveTabTimeline,
OriginsTimeline,
ThreadsKey,
} from './profile-derived';
import type { Attempt } from '../utils/errors';
import type { TransformStacksPerThread } from './transforms';
import type JSZip from 'jszip';
import type { IndexIntoZipFileTable } from '../profile-logic/zip-files';
import type { PathSet } from '../utils/path.js';
export type Reducer<T> = (T | void, Action) => T;
export type SymbolicationStatus = 'DONE' | 'SYMBOLICATING';
export type ThreadViewOptions = {|
+selectedCallNodePath: CallNodePath,
+expandedCallNodePaths: PathSet,
+selectedMarker: MarkerIndex | null,
|};
export type ThreadViewOptionsPerThreads = { [ThreadsKey]: ThreadViewOptions };
export type RightClickedCallNode = {|
+threadsKey: ThreadsKey,
+callNodePath: CallNodePath,
|};
export type RightClickedMarker = {|
+threadsKey: ThreadsKey,
+markerIndex: MarkerIndex,
|};
/**
* Full profile view state
* They should not be used from the active tab view.
* NOTE: This state is empty for now, but will be used later, do not remove.
* globalTracks and localTracksByPid states will be here in the future.
*/
export type FullProfileViewState = {|
globalTracks: GlobalTrack[],
localTracksByPid: Map<Pid, LocalTrack[]>,
|};
export type OriginsViewState = {|
originsTimeline: OriginsTimeline,
|};
/**
* Active tab profile view state
* They should not be used from the full view.
*/
export type ActiveTabProfileViewState = {|
activeTabTimeline: ActiveTabTimeline,
|};
/**
* Profile view state
*/
export type ProfileViewState = {
+viewOptions: {|
perThread: ThreadViewOptionsPerThreads,
symbolicationStatus: SymbolicationStatus,
waitingForLibs: Set<RequestedLib>,
previewSelection: PreviewSelection,
scrollToSelectionGeneration: number,
focusCallTreeGeneration: number,
rootRange: StartEndRange,
rightClickedTrack: TrackReference | null,
rightClickedCallNode: RightClickedCallNode | null,
rightClickedMarker: RightClickedMarker | null,
mouseTimePosition: Milliseconds | null,
|},
+profile: Profile | null,
+full: FullProfileViewState,
+activeTab: ActiveTabProfileViewState,
+origins: OriginsViewState,
};
export type AppViewState =
| {| +phase: 'ROUTE_NOT_FOUND' |}
| {| +phase: 'TRANSITIONING_FROM_STALE_PROFILE' |}
| {| +phase: 'PROFILE_LOADED' |}
| {| +phase: 'DATA_LOADED' |}
| {| +phase: 'DATA_RELOAD' |}
| {| +phase: 'FATAL_ERROR', +error: Error |}
| {|
+phase: 'INITIALIZING',
+additionalData?: {| +attempt: Attempt | null, +message: string |},
|};
export type Phase = $PropertyType<AppViewState, 'phase'>;
/**
* This represents the finite state machine for loading zip files. The phase represents
* where the state is now.
*/
export type ZipFileState =
| {|
+phase: 'NO_ZIP_FILE',
+zip: null,
+pathInZipFile: null,
|}
| {|
+phase: 'LIST_FILES_IN_ZIP_FILE',
+zip: JSZip,
+pathInZipFile: null,
|}
| {|
+phase: 'PROCESS_PROFILE_FROM_ZIP_FILE',
+zip: JSZip,
+pathInZipFile: string,
|}
| {|
+phase: 'FAILED_TO_PROCESS_PROFILE_FROM_ZIP_FILE',
+zip: JSZip,
+pathInZipFile: string,
|}
| {|
+phase: 'FILE_NOT_FOUND_IN_ZIP_FILE',
+zip: JSZip,
+pathInZipFile: string,
|}
| {|
+phase: 'VIEW_PROFILE_IN_ZIP_FILE',
+zip: JSZip,
+pathInZipFile: string,
|};
export type IsSidebarOpenPerPanelState = { [TabSlug]: boolean };
export type UrlSetupPhase = 'initial-load' | 'loading-profile' | 'done';
/*
* Experimental features that are mostly disabled by default. You need to enable
* them from the DevTools console with `experimental.enable<feature-camel-case>()`,
* e.g. `experimental.enableEventDelayTracks()`.
*/
export type ExperimentalFlags = {|
+eventDelayTracks: boolean,
|};
export type AppState = {|
+view: AppViewState,
+urlSetupPhase: UrlSetupPhase,
+hasZoomedViaMousewheel: boolean,
+isSidebarOpenPerPanel: IsSidebarOpenPerPanelState,
+panelLayoutGeneration: number,
+lastVisibleThreadTabSlug: TabSlug,
+trackThreadHeights: {
[key: ThreadsKey]: CssPixels,
},
+isNewlyPublished: boolean,
+isDragAndDropDragging: boolean,
+isDragAndDropOverlayRegistered: boolean,
+experimental: ExperimentalFlags,
|};
export type UploadPhase =
| 'local'
| 'compressing'
| 'uploading'
| 'uploaded'
| 'error';
export type UploadState = {|
phase: UploadPhase,
uploadProgress: number,
error: Error | mixed,
abortFunction: () => void,
generation: number,
|};
export type PublishState = {|
+checkedSharingOptions: CheckedSharingOptions,
+upload: UploadState,
+isHidingStaleProfile: boolean,
+hasSanitizedProfile: boolean,
+prePublishedState: State | null,
|};
export type ZippedProfilesState = {
zipFile: ZipFileState,
error: Error | null,
selectedZipFileIndex: IndexIntoZipFileTable | null,
// In practice this should never contain null, but needs to support the
// TreeView interface.
expandedZipFileIndexes: Array<IndexIntoZipFileTable | null>,
};
/**
* Full profile specific url state
* They should not be used from the active tab view.
*/
export type FullProfileSpecificUrlState = {|
globalTrackOrder: TrackIndex[],
hiddenGlobalTracks: Set<TrackIndex>,
hiddenLocalTracksByPid: Map<Pid, Set<TrackIndex>>,
localTrackOrderByPid: Map<Pid, TrackIndex[]>,
showJsTracerSummary: boolean,
timelineType: TimelineType,
legacyThreadOrder: ThreadIndex[] | null,
legacyHiddenThreads: ThreadIndex[] | null,
|};
/**
* Active tab profile specific url state
* They should not be used from the full view.
*/
export type ActiveTabSpecificProfileUrlState = {|
isResourcesPanelOpen: boolean,
|};
export type ProfileSpecificUrlState = {|
selectedThreads: Set<ThreadIndex> | null,
implementation: ImplementationFilter,
lastSelectedCallTreeSummaryStrategy: CallTreeSummaryStrategy,
invertCallstack: boolean,
showUserTimings: boolean,
committedRanges: StartEndRange[],
callTreeSearchString: string,
markersSearchString: string,
networkSearchString: string,
transforms: TransformStacksPerThread,
full: FullProfileSpecificUrlState,
activeTab: ActiveTabSpecificProfileUrlState,
|};
/**
* Determines how the timeline's tracks are organized.
*/
export type TimelineTrackOrganization =
| {| +type: 'full' |}
| {| +type: 'active-tab', +browsingContextID: BrowsingContextID | null |}
| {| +type: 'origins' |};
export type UrlState = {|
+dataSource: DataSource,
// This is used for the "public" dataSource".
+hash: string,
// This is used for the "from-url" dataSource.
+profileUrl: string,
// This is used for the "compare" dataSource, to compare 2 profiles.
+profilesToCompare: string[] | null,
+selectedTab: TabSlug,
+pathInZipFile: string | null,
+profileName: string | null,
+timelineTrackOrganization: TimelineTrackOrganization,
+profileSpecific: ProfileSpecificUrlState,
|};
export type IconState = Set<string>;
export type State = {|
+app: AppState,
+profileView: ProfileViewState,
+urlState: UrlState,
+icons: IconState,
+zippedProfiles: ZippedProfilesState,
+publish: PublishState,
|};
export type IconWithClassName = {|
+icon: string,
+className: string,
|};