-
Notifications
You must be signed in to change notification settings - Fork 420
/
Copy pathurl-state.js
778 lines (733 loc) · 22.4 KB
/
url-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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/* 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 { combineReducers } from 'redux';
import { oneLine } from 'common-tags';
import { objectEntries } from '../utils/flow';
import { tabSlugs } from '../app-logic/tabs-handling';
import type {
ThreadIndex,
Pid,
TrackIndex,
StartEndRange,
TransformStacksPerThread,
DataSource,
ImplementationFilter,
CallTreeSummaryStrategy,
TimelineType,
UrlState,
Reducer,
TimelineTrackOrganization,
SourceViewState,
AssemblyViewState,
IsOpenPerPanelState,
TabID,
} from 'firefox-profiler/types';
import type { TabSlug } from '../app-logic/tabs-handling';
/*
* This state file governs the state that comes from, and alters, the window
* location. The location itself is changed in `src/components/app/UrlManager`,
* and the computations are handled in `src/app-logic/url-handling`.
*
* All reducers in this state can be circumvented and the state reset
* completely using the action `UPDATE_URL_STATE`. This action is dispatched
* from the URL, either at the first load or when it changes when the user
* navigates.
* That's why the individual reducers might look incomplete at times.
* See below the function `wrapReducerInResetter`.
*/
const dataSource: Reducer<DataSource> = (state = 'none', action) => {
switch (action.type) {
case 'WAITING_FOR_PROFILE_FROM_FILE':
return 'from-file';
case 'PROFILE_PUBLISHED':
case 'SANITIZED_PROFILE_PUBLISHED':
return 'public';
case 'TRIGGER_LOADING_FROM_URL':
return 'from-url';
case 'PROFILE_REMOTELY_DELETED':
return 'unpublished';
case 'SET_DATA_SOURCE':
return action.dataSource;
default:
return state;
}
};
const hash: Reducer<string> = (state = '', action) => {
switch (action.type) {
case 'PROFILE_PUBLISHED':
case 'SANITIZED_PROFILE_PUBLISHED':
return action.hash;
case 'PROFILE_REMOTELY_DELETED':
return '';
default:
return state;
}
};
const profileUrl: Reducer<string> = (state = '', action) => {
switch (action.type) {
case 'WAITING_FOR_PROFILE_FROM_URL':
return action.profileUrl ? action.profileUrl : state;
case 'TRIGGER_LOADING_FROM_URL':
return action.profileUrl;
default:
return state;
}
};
const profilesToCompare: Reducer<string[] | null> = (state = null, action) => {
switch (action.type) {
case 'CHANGE_PROFILES_TO_COMPARE':
return action.profiles;
default:
return state;
}
};
const selectedTab: Reducer<TabSlug> = (state = 'calltree', action) => {
switch (action.type) {
case 'CHANGE_SELECTED_TAB':
case 'SELECT_TRACK':
case 'VIEW_FULL_PROFILE':
case 'CHANGE_TAB_FILTER':
return action.selectedTab;
case 'FOCUS_CALL_TREE':
return 'calltree';
default:
return state;
}
};
const committedRanges: Reducer<StartEndRange[]> = (state = [], action) => {
switch (action.type) {
case 'COMMIT_RANGE': {
const { start, end } = action;
return [...state, { start, end }];
}
case 'POP_COMMITTED_RANGES':
return state.slice(0, action.firstPoppedFilterIndex);
case 'SANITIZED_PROFILE_PUBLISHED':
// This value may be updated due to profile sanitization.
return action.committedRanges ? action.committedRanges : state;
default:
return state;
}
};
const selectedThreads: Reducer<Set<ThreadIndex> | null> = (
state = null,
action
) => {
switch (action.type) {
case 'CHANGE_SELECTED_THREAD':
case 'SELECT_TRACK':
case 'VIEW_FULL_PROFILE':
case 'VIEW_ORIGINS_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
case 'ISOLATE_PROCESS':
case 'ISOLATE_PROCESS_MAIN_THREAD':
case 'HIDE_GLOBAL_TRACK':
case 'HIDE_LOCAL_TRACK':
case 'HIDE_PROVIDED_TRACKS':
case 'ISOLATE_LOCAL_TRACK':
case 'TOGGLE_RESOURCES_PANEL':
case 'CHANGE_TAB_FILTER':
// Only switch to non-null selected threads.
return (action.selectedThreadIndexes: Set<ThreadIndex>);
case 'SANITIZED_PROFILE_PUBLISHED': {
const { oldThreadIndexToNew } = action;
if (state === null || !oldThreadIndexToNew) {
// Either there was no selected thread, or the thread indexes were not modified.
return state;
}
const newSelectedThreads = new Set();
for (const oldThreadIndex of state) {
const newThreadIndex = oldThreadIndexToNew.get(oldThreadIndex);
if (newThreadIndex === undefined) {
console.error(oneLine`
Unable to map an old thread index to a new thread index for the selected
thread when sanitizing a profile
`);
return null;
}
newSelectedThreads.add(newThreadIndex);
}
return newSelectedThreads;
}
default:
return state;
}
};
const callTreeSearchString: Reducer<string> = (state = '', action) => {
switch (action.type) {
case 'CHANGE_CALL_TREE_SEARCH_STRING':
return action.searchString;
default:
return state;
}
};
const markersSearchString: Reducer<string> = (state = '', action) => {
switch (action.type) {
case 'CHANGE_MARKER_SEARCH_STRING':
return action.searchString;
default:
return state;
}
};
const networkSearchString: Reducer<string> = (state = '', action) => {
switch (action.type) {
case 'CHANGE_NETWORK_SEARCH_STRING':
return action.searchString;
default:
return state;
}
};
const transforms: Reducer<TransformStacksPerThread> = (state = {}, action) => {
switch (action.type) {
case 'PROFILE_LOADED':
return action.transformStacks || state;
case 'ADD_TRANSFORM_TO_STACK': {
const { threadsKey, transform } = action;
const transforms = state[threadsKey] || [];
return Object.assign({}, state, {
[threadsKey]: [...transforms, transform],
});
}
case 'POP_TRANSFORMS_FROM_STACK': {
const { threadsKey, firstPoppedFilterIndex } = action;
const transforms = state[threadsKey] || [];
return Object.assign({}, state, {
[threadsKey]: transforms.slice(0, firstPoppedFilterIndex),
});
}
case 'SANITIZED_PROFILE_PUBLISHED': {
const { oldThreadIndexToNew } = action;
if (!oldThreadIndexToNew) {
// The thread indexes weren't modified, just return the old value here.
return state;
}
// This may no longer be valid because of PII sanitization.
const newTransforms = {};
for (const [threadsKey, transformStack] of objectEntries(state)) {
const newThreadIndex = oldThreadIndexToNew.get(Number(threadsKey));
if (newThreadIndex !== undefined) {
newTransforms[newThreadIndex] = transformStack;
}
}
return newTransforms;
}
default:
return state;
}
};
const timelineType: Reducer<TimelineType> = (
state = 'cpu-category',
action
) => {
switch (action.type) {
case 'CHANGE_TIMELINE_TYPE':
return action.timelineType;
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
// The timelineType can be set at load time from a URL value.
// If it's not set from a URL value we provide a default value from this action.
// When it's null we don't want to override the value that was set already.
if (action.timelineType !== null) {
return action.timelineType;
}
return state;
default:
return state;
}
};
/**
* Represents the current filter applied to the stack frames, where it will show
* frames only by implementation.
*/
const implementation: Reducer<ImplementationFilter> = (
state = 'combined',
action
) => {
switch (action.type) {
case 'PROFILE_LOADED':
return action.implementationFilter || state;
case 'CHANGE_IMPLEMENTATION_FILTER':
return action.implementation;
default:
return state;
}
};
/**
* Represents the last selected call tree summary strategy, which will be used to
* summarize the the call tree. A strategy can be selected that is not supported
* by the current thread, in this case it will default back to timing.
*/
const lastSelectedCallTreeSummaryStrategy: Reducer<CallTreeSummaryStrategy> = (
state = 'timing',
action
) => {
switch (action.type) {
case 'CHANGE_CALL_TREE_SUMMARY_STRATEGY':
return action.callTreeSummaryStrategy;
default:
return state;
}
};
const invertCallstack: Reducer<boolean> = (state = false, action) => {
switch (action.type) {
case 'CHANGE_INVERT_CALLSTACK':
return action.invertCallstack;
default:
return state;
}
};
/**
* Signals whether user timing markers will be shown in the stack chart.
*/
const showUserTimings: Reducer<boolean> = (state = false, action) => {
switch (action.type) {
case 'CHANGE_SHOW_USER_TIMINGS':
return action.showUserTimings;
default:
return state;
}
};
/**
* This state controls whether or not to show a summary view of self time, or the full
* stack-based view of the JS tracer data.
*/
const showJsTracerSummary: Reducer<boolean> = (state = false, action) => {
switch (action.type) {
case 'CHANGE_SHOW_JS_TRACER_SUMMARY':
return action.showSummary;
default:
return state;
}
};
const globalTrackOrder: Reducer<TrackIndex[]> = (state = [], action) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'CHANGE_GLOBAL_TRACK_ORDER':
case 'CHANGE_TAB_FILTER':
return action.globalTrackOrder;
case 'SANITIZED_PROFILE_PUBLISHED':
// If some threads were removed, do not even attempt to figure this out. It's
// complicated, and not many people use this feature.
return action.oldThreadIndexToNew ? [] : state;
default:
return state;
}
};
const hiddenGlobalTracks: Reducer<Set<TrackIndex>> = (
state = new Set(),
action
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'ISOLATE_LOCAL_TRACK':
case 'ISOLATE_PROCESS':
case 'ISOLATE_PROCESS_MAIN_THREAD':
case 'ISOLATE_SCREENSHOT_TRACK':
case 'CHANGE_TAB_FILTER':
return action.hiddenGlobalTracks;
case 'HIDE_GLOBAL_TRACK': {
const hiddenGlobalTracks = new Set(state);
hiddenGlobalTracks.add(action.trackIndex);
return hiddenGlobalTracks;
}
case 'SHOW_ALL_TRACKS':
return new Set();
case 'SHOW_PROVIDED_TRACKS': {
const hiddenGlobalTracks = new Set(state);
// Remove all the provided global tracks from the hidden global tracks.
action.globalTracksToShow.forEach(
Set.prototype.delete,
hiddenGlobalTracks
);
return hiddenGlobalTracks;
}
case 'SHOW_GLOBAL_TRACK':
case 'SHOW_GLOBAL_TRACK_INCLUDING_LOCAL_TRACKS': {
const hiddenGlobalTracks = new Set(state);
hiddenGlobalTracks.delete(action.trackIndex);
return hiddenGlobalTracks;
}
case 'HIDE_PROVIDED_TRACKS': {
const hiddenGlobalTracks = new Set(state);
// Add all the provided global tracks to the hidden global tracks.
action.globalTracksToHide.forEach(Set.prototype.add, hiddenGlobalTracks);
return hiddenGlobalTracks;
}
case 'SANITIZED_PROFILE_PUBLISHED':
// If any threads were removed, this was because they were hidden.
// Reset this state.
return action.oldThreadIndexToNew ? new Set() : state;
default:
return state;
}
};
const hiddenLocalTracksByPid: Reducer<Map<Pid, Set<TrackIndex>>> = (
state = new Map(),
action
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'CHANGE_TAB_FILTER':
return action.hiddenLocalTracksByPid;
case 'HIDE_LOCAL_TRACK': {
const hiddenLocalTracksByPid = new Map(state);
const hiddenLocalTracks = new Set(hiddenLocalTracksByPid.get(action.pid));
hiddenLocalTracks.add(action.trackIndex);
hiddenLocalTracksByPid.set(action.pid, hiddenLocalTracks);
return hiddenLocalTracksByPid;
}
case 'SHOW_ALL_TRACKS': {
const hiddenLocalTracksByPid = new Map(state);
for (const key of hiddenLocalTracksByPid) {
hiddenLocalTracksByPid.set(key[0], new Set());
}
return hiddenLocalTracksByPid;
}
case 'SHOW_PROVIDED_TRACKS': {
const hiddenLocalTracksByPid = new Map(state);
// Go through the filtered local tracks to make them visible.
for (const [
pid,
localTracksToMakeVisible,
] of action.localTracksByPidToShow.entries()) {
const hiddenLocalTracks = state.get(pid) ?? new Set();
const newHiddenLocalTracks = new Set(hiddenLocalTracks);
localTracksToMakeVisible.forEach(
Set.prototype.delete,
newHiddenLocalTracks
);
hiddenLocalTracksByPid.set(pid, newHiddenLocalTracks);
}
return hiddenLocalTracksByPid;
}
case 'SHOW_LOCAL_TRACK': {
const hiddenLocalTracksByPid = new Map(state);
const hiddenLocalTracks = new Set(hiddenLocalTracksByPid.get(action.pid));
hiddenLocalTracks.delete(action.trackIndex);
hiddenLocalTracksByPid.set(action.pid, hiddenLocalTracks);
return hiddenLocalTracksByPid;
}
case 'SHOW_GLOBAL_TRACK_INCLUDING_LOCAL_TRACKS': {
// Show all local tracks for this global track
const hiddenLocalTracksByPid = new Map(state);
hiddenLocalTracksByPid.set(action.pid, new Set());
return hiddenLocalTracksByPid;
}
case 'HIDE_PROVIDED_TRACKS': {
const hiddenLocalTracksByPid = new Map(state);
// Go through the provided local tracks to make them hidden.
for (const [
pid,
localTracksToMakeHidden,
] of action.localTracksByPidToHide.entries()) {
const hiddenLocalTracks = state.get(pid) ?? new Set();
const newHiddenLocalTracks = new Set(hiddenLocalTracks);
localTracksToMakeHidden.forEach(
Set.prototype.add,
newHiddenLocalTracks
);
hiddenLocalTracksByPid.set(pid, newHiddenLocalTracks);
}
return hiddenLocalTracksByPid;
}
case 'ISOLATE_PROCESS_MAIN_THREAD':
case 'ISOLATE_LOCAL_TRACK': {
const hiddenLocalTracksByPid = new Map(state);
hiddenLocalTracksByPid.set(action.pid, action.hiddenLocalTracks);
return hiddenLocalTracksByPid;
}
case 'SANITIZED_PROFILE_PUBLISHED':
// If any threads were removed then this information is no longer valid.
return action.oldThreadIndexToNew ? new Map() : state;
default:
return state;
}
};
const localTrackOrderByPid: Reducer<Map<Pid, TrackIndex[]>> = (
state = new Map(),
action
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'ENABLE_EVENT_DELAY_TRACKS':
case 'ENABLE_EXPERIMENTAL_PROCESS_CPU_TRACKS':
case 'CHANGE_TAB_FILTER':
return action.localTrackOrderByPid;
case 'CHANGE_LOCAL_TRACK_ORDER': {
const localTrackOrderByPid = new Map(state);
localTrackOrderByPid.set(action.pid, action.localTrackOrder);
return localTrackOrderByPid;
}
case 'SANITIZED_PROFILE_PUBLISHED':
// If any threads were removed then remove this information. It's complicated
// to compute, and not many people use it.
return action.oldThreadIndexToNew ? new Map() : state;
default:
return state;
}
};
const localTrackOrderChangedPids: Reducer<Set<Pid>> = (
state = new Set(),
action
) => {
switch (action.type) {
case 'CHANGE_LOCAL_TRACK_ORDER': {
const localTrackOrderChangedPids = new Set(state);
localTrackOrderChangedPids.add(action.pid);
return localTrackOrderChangedPids;
}
case 'SANITIZED_PROFILE_PUBLISHED':
// In localTrackOrderByPid above the state is reset in this case,
// let's reset it here as well.
return action.oldThreadIndexToNew ? new Set() : state;
default:
return state;
}
};
/**
* This state controls whether or not we are filtering the full view for a
* specific Firefox tab.
*/
const tabFilter: Reducer<TabID | null> = (state = null, action) => {
switch (action.type) {
case 'CHANGE_TAB_FILTER':
return action.tabID;
default:
return state;
}
};
// If you update this reducer, please don't forget to update the profileName
// reducer below as well.
const pathInZipFile: Reducer<string | null> = (state = null, action) => {
switch (action.type) {
// Update the URL the moment the zip file is starting to be
// processed, not when it is viewed. The processing is async.
case 'PROCESS_PROFILE_FROM_ZIP_FILE':
return action.pathInZipFile ? action.pathInZipFile : null;
case 'PROFILE_PUBLISHED': // Removes the file information when publishing.
case 'SANITIZED_PROFILE_PUBLISHED':
case 'RETURN_TO_ZIP_FILE_LIST':
return null;
default:
return state;
}
};
const profileName: Reducer<string | null> = (state = null, action) => {
switch (action.type) {
case 'PROFILE_PUBLISHED':
case 'SANITIZED_PROFILE_PUBLISHED':
case 'CHANGE_PROFILE_NAME':
return action.profileName;
default:
return state;
}
};
const timelineTrackOrganization: Reducer<TimelineTrackOrganization> = (
state = { type: 'full' },
action
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
return { type: 'full' };
case 'VIEW_ACTIVE_TAB_PROFILE':
return {
type: 'active-tab',
tabID: action.tabID,
};
case 'VIEW_ORIGINS_PROFILE':
return { type: 'origins' };
default:
return state;
}
};
const sourceView: Reducer<SourceViewState> = (
state = { scrollGeneration: 0, libIndex: null, sourceFile: null },
action
) => {
switch (action.type) {
case 'UPDATE_BOTTOM_BOX': {
return {
scrollGeneration: state.scrollGeneration + 1,
libIndex: action.libIndex,
sourceFile: action.sourceFile,
};
}
default:
return state;
}
};
const assemblyView: Reducer<AssemblyViewState> = (
state = {
scrollGeneration: 0,
nativeSymbol: null,
allNativeSymbolsForInitiatingCallNode: [],
isOpen: false,
},
action
) => {
switch (action.type) {
case 'UPDATE_BOTTOM_BOX': {
return {
scrollGeneration: state.scrollGeneration + 1,
nativeSymbol: action.nativeSymbol,
allNativeSymbolsForInitiatingCallNode:
action.allNativeSymbolsForInitiatingCallNode,
isOpen: state.isOpen || action.shouldOpenAssemblyView,
};
}
case 'OPEN_ASSEMBLY_VIEW': {
return {
...state,
isOpen: true,
};
}
case 'CLOSE_ASSEMBLY_VIEW': {
return {
...state,
isOpen: false,
};
}
default:
return state;
}
};
function _getBottomBoxInitialState() {
const state = {};
tabSlugs.forEach((tabSlug) => (state[tabSlug] = false));
return state;
}
const isBottomBoxOpenPerPanel: Reducer<IsOpenPerPanelState> = (
state = _getBottomBoxInitialState(),
action
) => {
switch (action.type) {
case 'UPDATE_BOTTOM_BOX': {
const { currentTab, shouldOpenBottomBox } = action;
if (shouldOpenBottomBox && !state[currentTab]) {
return { ...state, [currentTab]: true };
}
return state;
}
case 'CLOSE_BOTTOM_BOX_FOR_TAB': {
const { tab } = action;
if (state[tab]) {
return { ...state, [tab]: false };
}
return state;
}
default:
return state;
}
};
/**
* Active tab specific profile url states
*/
/**
* Active tab resources panel open/close state.
*/
const isResourcesPanelOpen: Reducer<boolean> = (state = false, action) => {
switch (action.type) {
case 'TOGGLE_RESOURCES_PANEL':
return !state;
default:
return state;
}
};
/**
* This value is only set from the URL and never changed.
*/
const symbolServerUrl: Reducer<string | null> = (state = null) => {
return state;
};
/**
* These values are specific to an individual full profile.
*/
const fullProfileSpecific = combineReducers({
globalTrackOrder,
hiddenGlobalTracks,
hiddenLocalTracksByPid,
localTrackOrderByPid,
localTrackOrderChangedPids,
showJsTracerSummary,
tabFilter,
// The timeline tracks used to be hidden and sorted by thread indexes, rather than
// track indexes. The only way to migrate this information to tracks-based data is to
// first retrieve the profile, so they can't be upgraded by the normal url upgrading
// process. These value are only set by the locationToState function.
legacyThreadOrder: (state: ThreadIndex[] | null = null) => state,
legacyHiddenThreads: (state: ThreadIndex[] | null = null) => state,
});
/**
* These values are specific to an individual active tab profile.
*/
const activeTabProfileSpecific = combineReducers({
isResourcesPanelOpen,
});
/**
* These values are specific to an individual profile.
*/
const profileSpecific = combineReducers({
selectedThreads,
implementation,
lastSelectedCallTreeSummaryStrategy,
invertCallstack,
showUserTimings,
committedRanges,
callTreeSearchString,
markersSearchString,
networkSearchString,
transforms,
sourceView,
assemblyView,
isBottomBoxOpenPerPanel,
timelineType,
full: fullProfileSpecific,
activeTab: activeTabProfileSpecific,
});
/**
* Provide a mechanism to wrap the UrlState reducer in a special function that can swap
* out the entire UrlState with a new one coming from the History API. Also provide a
* way to invalidate sections of the state based off of looking at multiple profiles.
*/
const wrapReducerInResetter = (
regularUrlStateReducer: Reducer<UrlState>
): Reducer<UrlState> => {
return (state, action) => {
switch (action.type) {
case 'UPDATE_URL_STATE':
// A new URL came in because of a browser action, discard the current UrlState
// and use the new one, which was probably serialized from the URL, or stored
// in the history API.
return action.newUrlState
? action.newUrlState
: regularUrlStateReducer(undefined, action);
case 'RETURN_TO_ZIP_FILE_LIST':
case 'WAITING_FOR_PROFILE_FROM_FILE':
// Invalidate all information that would be specific to an individual profile.
return {
...regularUrlStateReducer(state, action),
profileSpecific: profileSpecific(undefined, state),
selectedTab: selectedTab(undefined, action),
};
default:
return regularUrlStateReducer(state, action);
}
};
};
const urlStateReducer: Reducer<UrlState> = wrapReducerInResetter(
combineReducers({
dataSource,
hash,
profileUrl,
profilesToCompare,
selectedTab,
pathInZipFile,
profileSpecific,
profileName,
timelineTrackOrganization,
symbolServerUrl,
})
);
export default urlStateReducer;