-
Notifications
You must be signed in to change notification settings - Fork 412
/
Copy pathcode.js
96 lines (91 loc) · 2.69 KB
/
code.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
/* 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 {
Reducer,
SourceCodeStatus,
AssemblyCodeStatus,
CodeState,
} from 'firefox-profiler/types';
import { combineReducers } from 'redux';
const sourceCodeCache: Reducer<Map<string, SourceCodeStatus>> = (
state = new Map(),
action
) => {
switch (action.type) {
case 'SOURCE_CODE_LOADING_BEGIN_URL': {
const { file, url } = action;
const newState = new Map(state);
newState.set(file, { type: 'LOADING', source: { type: 'URL', url } });
return newState;
}
case 'SOURCE_CODE_LOADING_BEGIN_BROWSER_CONNECTION': {
const { file } = action;
const newState = new Map(state);
newState.set(file, {
type: 'LOADING',
source: { type: 'BROWSER_CONNECTION' },
});
return newState;
}
case 'SOURCE_CODE_LOADING_SUCCESS': {
const { file, code } = action;
const newState = new Map(state);
newState.set(file, { type: 'AVAILABLE', code });
return newState;
}
case 'SOURCE_CODE_LOADING_ERROR': {
const { file, errors } = action;
const newState = new Map(state);
newState.set(file, { type: 'ERROR', errors });
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;