summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/reducers/event-listeners.js
blob: d0418b9ece4bae72f7ac8f200d73990e0eeac47a (plain)
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
/* 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 { prefs } from "../utils/prefs";

export function initialEventListenerState() {
  return {
    active: [],
    categories: [],
    expanded: [],
    logEventBreakpoints: prefs.logEventBreakpoints,
  };
}

function update(state = initialEventListenerState(), action) {
  switch (action.type) {
    case "UPDATE_EVENT_LISTENERS":
      return { ...state, active: action.active };

    case "RECEIVE_EVENT_LISTENER_TYPES":
      return { ...state, categories: action.categories };

    case "UPDATE_EVENT_LISTENER_EXPANDED":
      return { ...state, expanded: action.expanded };

    case "TOGGLE_EVENT_LISTENERS": {
      const { logEventBreakpoints } = action;
      prefs.logEventBreakpoints = logEventBreakpoints;
      return { ...state, logEventBreakpoints };
    }

    default:
      return state;
  }
}

export default update;