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
|
/* 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/>. */
/**
* Threads reducer
* @module reducers/threads
*/
export function initialThreadsState() {
return {
threads: [],
// List of thread actor IDs which are current tracing.
// i.e. where JavaScript tracing is enabled.
mutableTracingThreads: new Set(),
};
}
export default function update(state = initialThreadsState(), action) {
switch (action.type) {
case "INSERT_THREAD":
return {
...state,
threads: [...state.threads, action.newThread],
};
case "REMOVE_THREAD":
return {
...state,
threads: state.threads.filter(
thread => action.threadActorID != thread.actor
),
};
case "UPDATE_SERVICE_WORKER_STATUS":
return {
...state,
threads: state.threads.map(t => {
if (t.actor == action.thread) {
return { ...t, serviceWorkerStatus: action.status };
}
return t;
}),
};
case "TRACING_TOGGLED":
const { mutableTracingThreads } = state;
const sizeBefore = mutableTracingThreads.size;
if (action.enabled) {
mutableTracingThreads.add(action.thread);
} else {
mutableTracingThreads.delete(action.thread);
}
// We may receive toggle events when we change the logging method
// while we are already tracing, but the list of tracing thread stays the same.
const changed = mutableTracingThreads.size != sizeBefore;
if (changed) {
return {
...state,
mutableTracingThreads,
};
}
return state;
default:
return state;
}
}
|