summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/enhancers/css-error-reporting.js
blob: 513552db4df800e21735878dd25312f818821024 (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
39
40
41
42
43
/* 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/. */

"use strict";

const {
  INITIALIZE,
  FILTER_TOGGLE,
  FILTERS,
} = require("resource://devtools/client/webconsole/constants.js");

/**
 * This is responsible for ensuring that error reporting is enabled if the CSS
 * filter is toggled on.
 */
function ensureCSSErrorReportingEnabled(webConsoleUI) {
  let watchingCSSMessages = false;
  return next => (reducer, initialState, enhancer) => {
    function ensureErrorReportingEnhancer(state, action) {
      state = reducer(state, action);

      // If we're already watching CSS messages, or if the CSS filter is disabled,
      // we don't do anything.
      if (!webConsoleUI || watchingCSSMessages || !state.filters.css) {
        return state;
      }

      const cssFilterToggled =
        action.type == FILTER_TOGGLE && action.filter == FILTERS.CSS;

      if (cssFilterToggled || action.type == INITIALIZE) {
        watchingCSSMessages = true;
        webConsoleUI.watchCssMessages();
      }

      return state;
    }
    return next(ensureErrorReportingEnhancer, initialState, enhancer);
  };
}

module.exports = ensureCSSErrorReportingEnabled;