Bug 1287508 - Part 3: Define state defaults in reducers. r=me
--- a/devtools/client/webconsole/new-console-output/reducers/filters.js
+++ b/devtools/client/webconsole/new-console-output/reducers/filters.js
@@ -1,26 +1,35 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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 Immutable = require("devtools/client/shared/vendor/immutable");
const constants = require("devtools/client/webconsole/new-console-output/constants");
-const {Filters} = require("devtools/client/webconsole/new-console-output/store");
-function filters(state = new Filters(), action) {
+const FilterState = Immutable.Record({
+ error: true,
+ warn: true,
+ info: true,
+ log: true,
+ searchText: ""
+});
+
+function filters(state = new FilterState(), action) {
switch (action.type) {
case constants.SEVERITY_FILTER:
let {filter, toggled} = action;
return state.set(filter, toggled);
case constants.FILTERS_CLEAR:
- return new Filters();
+ return new FilterState();
case constants.MESSAGES_SEARCH:
let {searchText} = action;
return state.set("searchText", searchText);
}
return state;
}
+exports.FilterState = FilterState;
exports.filters = filters;
--- a/devtools/client/webconsole/new-console-output/reducers/prefs.js
+++ b/devtools/client/webconsole/new-console-output/reducers/prefs.js
@@ -1,14 +1,18 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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 {Prefs} = require("devtools/client/webconsole/new-console-output/store");
+const Immutable = require("devtools/client/shared/vendor/immutable");
+const PrefState = Immutable.Record({
+ logLimit: 1000
+});
-function prefs(state = new Prefs(), action) {
+function prefs(state = new PrefState(), action) {
return state;
}
+exports.PrefState = PrefState;
exports.prefs = prefs;
--- a/devtools/client/webconsole/new-console-output/reducers/ui.js
+++ b/devtools/client/webconsole/new-console-output/reducers/ui.js
@@ -1,17 +1,22 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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 constants = require("devtools/client/webconsole/new-console-output/constants");
-const {Ui} = require("devtools/client/webconsole/new-console-output/store");
+const Immutable = require("devtools/client/shared/vendor/immutable");
+
+const Ui = Immutable.Record({
+ configFilterBarVisible: false,
+ filteredMessageVisible: false
+});
function ui(state = new Ui(), action) {
switch (action.type) {
case constants.FILTERBAR_TOGGLE:
return state.set("configFilterBarVisible", !state.configFilterBarVisible);
}
return state;
--- a/devtools/client/webconsole/new-console-output/store.js
+++ b/devtools/client/webconsole/new-console-output/store.js
@@ -1,56 +1,30 @@
/* 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 Immutable = require("devtools/client/shared/vendor/immutable");
const Services = require("Services");
-
-const Filters = Immutable.Record({
- error: true,
- warn: true,
- info: true,
- log: true,
- searchText: ""
-});
-
-const Prefs = Immutable.Record({
- logLimit: 1000
-});
-
-const Ui = Immutable.Record({
- configFilterBarVisible: false,
- filteredMessageVisible: false
-});
-
-module.exports.Prefs = Prefs;
-module.exports.Filters = Filters;
-module.exports.Ui = Ui;
-
+const {FilterState} = require("devtools/client/webconsole/new-console-output/reducers/filters");
+const {PrefState} = require("devtools/client/webconsole/new-console-output/reducers/prefs");
const { combineReducers, createStore } = require("devtools/client/shared/vendor/redux");
const { reducers } = require("./reducers/index");
function storeFactory() {
const initialState = {
- messages: Immutable.List(),
- prefs: new Prefs({
+ prefs: new PrefState({
logLimit: Math.max(Services.prefs.getIntPref("devtools.hud.loglimit"), 1),
}),
- filters: new Filters({
+ filters: new FilterState({
error: Services.prefs.getBoolPref("devtools.webconsole.filter.error"),
warn: Services.prefs.getBoolPref("devtools.webconsole.filter.warn"),
info: Services.prefs.getBoolPref("devtools.webconsole.filter.info"),
log: Services.prefs.getBoolPref("devtools.webconsole.filter.log"),
searchText: ""
- }),
- ui: new Ui({
- configFilterBarVisible: false,
- filteredMessageVisible: false
})
};
return createStore(combineReducers(reducers), initialState);
}
// Provide the single store instance for app code.
module.exports.store = storeFactory();