-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathcode.ts
More file actions
115 lines (110 loc) · 3.34 KB
/
code.ts
File metadata and controls
115 lines (110 loc) · 3.34 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
/* 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/. */
import type {
Reducer,
SourceCodeStatus,
AssemblyCodeStatus,
CodeState,
IndexIntoSourceTable,
} from 'firefox-profiler/types';
import { combineReducers } from 'redux';
const sourceCodeCache: Reducer<Map<IndexIntoSourceTable, SourceCodeStatus>> = (
state = new Map(),
action
) => {
switch (action.type) {
case 'SOURCE_CODE_LOADING_BEGIN_URL': {
const { sourceIndex, url } = action;
const newState = new Map(state);
newState.set(sourceIndex, {
type: 'LOADING',
source: { type: 'URL', url },
});
return newState;
}
case 'SOURCE_CODE_LOADING_BEGIN_BROWSER_CONNECTION': {
const { sourceIndex } = action;
const newState = new Map(state);
newState.set(sourceIndex, {
type: 'LOADING',
source: { type: 'BROWSER_CONNECTION' },
});
return newState;
}
case 'SOURCE_CODE_LOADING_SUCCESS': {
const { sourceIndex, code } = action;
const newState = new Map(state);
newState.set(sourceIndex, { type: 'AVAILABLE', code });
return newState;
}
case 'SOURCE_CODE_LOADING_ERROR': {
const { sourceIndex, errors } = action;
const newState = new Map(state);
newState.set(sourceIndex, { type: 'ERROR', errors });
return newState;
}
case 'SANITIZED_PROFILE_PUBLISHED': {
if (!action.translationMaps) {
return state;
}
const { oldSourceToNewSourcePlusOne } = action.translationMaps;
const newState = new Map();
for (const [sourceIndex, status] of state) {
const newSourceIndexPlusOne = oldSourceToNewSourcePlusOne[sourceIndex];
if (newSourceIndexPlusOne === 0) {
continue;
}
const newSourceIndex = newSourceIndexPlusOne - 1;
newState.set(newSourceIndex, status);
}
return newState;
}
default:
return state;
}
};
const assemblyCodeCache: Reducer<Map<string, AssemblyCodeStatus>> = (
state = new Map(),
action
) => {
switch (action.type) {
case 'ASSEMBLY_CODE_LOADING_BEGIN_URL': {
const { nativeSymbolKey, url } = action;
const newState = new Map(state);
newState.set(nativeSymbolKey, {
type: 'LOADING',
source: { type: 'URL', url },
});
return newState;
}
case 'ASSEMBLY_CODE_LOADING_BEGIN_BROWSER_CONNECTION': {
const { nativeSymbolKey } = action;
const newState = new Map(state);
newState.set(nativeSymbolKey, {
type: 'LOADING',
source: { type: 'BROWSER_CONNECTION' },
});
return newState;
}
case 'ASSEMBLY_CODE_LOADING_SUCCESS': {
const { nativeSymbolKey, instructions } = action;
const newState = new Map(state);
newState.set(nativeSymbolKey, { type: 'AVAILABLE', instructions });
return newState;
}
case 'ASSEMBLY_CODE_LOADING_ERROR': {
const { nativeSymbolKey, errors } = action;
const newState = new Map(state);
newState.set(nativeSymbolKey, { type: 'ERROR', errors });
return newState;
}
default:
return state;
}
};
const code: Reducer<CodeState> = combineReducers({
sourceCodeCache,
assemblyCodeCache,
});
export default code;