summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/new-console-output/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/webconsole/new-console-output/reducers')
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/filters.js39
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/index.js18
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/messages.js135
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/moz.build12
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/prefs.js18
-rw-r--r--devtools/client/webconsole/new-console-output/reducers/ui.js39
6 files changed, 261 insertions, 0 deletions
diff --git a/devtools/client/webconsole/new-console-output/reducers/filters.js b/devtools/client/webconsole/new-console-output/reducers/filters.js
new file mode 100644
index 000000000..cd5f4bf7c
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/filters.js
@@ -0,0 +1,39 @@
+/* -*- 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 FilterState = Immutable.Record({
+ debug: true,
+ error: true,
+ info: true,
+ log: true,
+ net: false,
+ netxhr: false,
+ text: "",
+ warn: true,
+});
+
+function filters(state = new FilterState(), action) {
+ switch (action.type) {
+ case constants.FILTER_TOGGLE:
+ const {filter} = action;
+ const active = !state.get(filter);
+ return state.set(filter, active);
+ case constants.FILTERS_CLEAR:
+ return new FilterState();
+ case constants.FILTER_TEXT_SET:
+ let {text} = action;
+ return state.set("text", text);
+ }
+
+ return state;
+}
+
+exports.FilterState = FilterState;
+exports.filters = filters;
diff --git a/devtools/client/webconsole/new-console-output/reducers/index.js b/devtools/client/webconsole/new-console-output/reducers/index.js
new file mode 100644
index 000000000..6ab10d565
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/index.js
@@ -0,0 +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 { filters } = require("./filters");
+const { messages } = require("./messages");
+const { prefs } = require("./prefs");
+const { ui } = require("./ui");
+
+exports.reducers = {
+ filters,
+ messages,
+ prefs,
+ ui,
+};
diff --git a/devtools/client/webconsole/new-console-output/reducers/messages.js b/devtools/client/webconsole/new-console-output/reducers/messages.js
new file mode 100644
index 000000000..0693fed60
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/messages.js
@@ -0,0 +1,135 @@
+/* -*- 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 {isGroupType} = require("devtools/client/webconsole/new-console-output/utils/messages");
+
+const MessageState = Immutable.Record({
+ // List of all the messages added to the console.
+ messagesById: Immutable.List(),
+ // List of the message ids which are opened.
+ messagesUiById: Immutable.List(),
+ // Map of the form {messageId : tableData}, which represent the data passed
+ // as an argument in console.table calls.
+ messagesTableDataById: Immutable.Map(),
+ // Map of the form {groupMessageId : groupArray},
+ // where groupArray is the list of of all the parent groups' ids of the groupMessageId.
+ groupsById: Immutable.Map(),
+ // Message id of the current group (no corresponding console.groupEnd yet).
+ currentGroup: null,
+});
+
+function messages(state = new MessageState(), action) {
+ const {
+ messagesById,
+ messagesUiById,
+ messagesTableDataById,
+ groupsById,
+ currentGroup
+ } = state;
+
+ switch (action.type) {
+ case constants.MESSAGE_ADD:
+ let newMessage = action.message;
+
+ if (newMessage.type === constants.MESSAGE_TYPE.NULL_MESSAGE) {
+ // When the message has a NULL type, we don't add it.
+ return state;
+ }
+
+ if (newMessage.type === constants.MESSAGE_TYPE.END_GROUP) {
+ // Compute the new current group.
+ return state.set("currentGroup", getNewCurrentGroup(currentGroup, groupsById));
+ }
+
+ if (newMessage.allowRepeating && messagesById.size > 0) {
+ let lastMessage = messagesById.last();
+ if (lastMessage.repeatId === newMessage.repeatId) {
+ return state.withMutations(function (record) {
+ record.set("messagesById", messagesById.pop().push(
+ newMessage.set("repeat", lastMessage.repeat + 1)
+ ));
+ });
+ }
+ }
+
+ return state.withMutations(function (record) {
+ // Add the new message with a reference to the parent group.
+ record.set(
+ "messagesById",
+ messagesById.push(newMessage.set("groupId", currentGroup))
+ );
+
+ if (newMessage.type === "trace") {
+ // We want the stacktrace to be open by default.
+ record.set("messagesUiById", messagesUiById.push(newMessage.id));
+ } else if (isGroupType(newMessage.type)) {
+ record.set("currentGroup", newMessage.id);
+ record.set("groupsById",
+ groupsById.set(
+ newMessage.id,
+ getParentGroups(currentGroup, groupsById)
+ )
+ );
+
+ if (newMessage.type === constants.MESSAGE_TYPE.START_GROUP) {
+ // We want the group to be open by default.
+ record.set("messagesUiById", messagesUiById.push(newMessage.id));
+ }
+ }
+ });
+ case constants.MESSAGES_CLEAR:
+ return state.withMutations(function (record) {
+ record.set("messagesById", Immutable.List());
+ record.set("messagesUiById", Immutable.List());
+ record.set("groupsById", Immutable.Map());
+ record.set("currentGroup", null);
+ });
+ case constants.MESSAGE_OPEN:
+ return state.set("messagesUiById", messagesUiById.push(action.id));
+ case constants.MESSAGE_CLOSE:
+ let index = state.messagesUiById.indexOf(action.id);
+ return state.deleteIn(["messagesUiById", index]);
+ case constants.MESSAGE_TABLE_RECEIVE:
+ const {id, data} = action;
+ return state.set("messagesTableDataById", messagesTableDataById.set(id, data));
+ }
+
+ return state;
+}
+
+function getNewCurrentGroup(currentGoup, groupsById) {
+ let newCurrentGroup = null;
+ if (currentGoup) {
+ // Retrieve the parent groups of the current group.
+ let parents = groupsById.get(currentGoup);
+ if (Array.isArray(parents) && parents.length > 0) {
+ // If there's at least one parent, make the first one the new currentGroup.
+ newCurrentGroup = parents[0];
+ }
+ }
+ return newCurrentGroup;
+}
+
+function getParentGroups(currentGroup, groupsById) {
+ let groups = [];
+ if (currentGroup) {
+ // If there is a current group, we add it as a parent
+ groups = [currentGroup];
+
+ // As well as all its parents, if it has some.
+ let parentGroups = groupsById.get(currentGroup);
+ if (Array.isArray(parentGroups) && parentGroups.length > 0) {
+ groups = groups.concat(parentGroups);
+ }
+ }
+
+ return groups;
+}
+
+exports.messages = messages;
diff --git a/devtools/client/webconsole/new-console-output/reducers/moz.build b/devtools/client/webconsole/new-console-output/reducers/moz.build
new file mode 100644
index 000000000..651512f85
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/moz.build
@@ -0,0 +1,12 @@
+# vim: set filetype=python:
+# 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/.
+
+DevToolsModules(
+ 'filters.js',
+ 'index.js',
+ 'messages.js',
+ 'prefs.js',
+ 'ui.js',
+)
diff --git a/devtools/client/webconsole/new-console-output/reducers/prefs.js b/devtools/client/webconsole/new-console-output/reducers/prefs.js
new file mode 100644
index 000000000..0707105e1
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/prefs.js
@@ -0,0 +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 Immutable = require("devtools/client/shared/vendor/immutable");
+const PrefState = Immutable.Record({
+ logLimit: 1000
+});
+
+function prefs(state = new PrefState(), action) {
+ return state;
+}
+
+exports.PrefState = PrefState;
+exports.prefs = prefs;
diff --git a/devtools/client/webconsole/new-console-output/reducers/ui.js b/devtools/client/webconsole/new-console-output/reducers/ui.js
new file mode 100644
index 000000000..aa91dceeb
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/reducers/ui.js
@@ -0,0 +1,39 @@
+/* -*- 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 {
+ FILTER_BAR_TOGGLE,
+ MESSAGE_ADD,
+} = require("devtools/client/webconsole/new-console-output/constants");
+const Immutable = require("devtools/client/shared/vendor/immutable");
+
+const UiState = Immutable.Record({
+ filterBarVisible: false,
+ filteredMessageVisible: false,
+ autoscroll: true,
+});
+
+function ui(state = new UiState(), action) {
+ // Autoscroll should be set for all action types. If the last action was not message
+ // add, then turn it off. This prevents us from scrolling after someone toggles a
+ // filter, or to the bottom of the attachement when an expandable message at the bottom
+ // of the list is expanded. It does depend on the MESSAGE_ADD action being the last in
+ // its batch, though.
+ state = state.set("autoscroll", action.type == MESSAGE_ADD);
+
+ switch (action.type) {
+ case FILTER_BAR_TOGGLE:
+ return state.set("filterBarVisible", !state.filterBarVisible);
+ }
+
+ return state;
+}
+
+module.exports = {
+ UiState,
+ ui,
+};