summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/reducers/source-tree.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--devtools/client/debugger/src/reducers/source-tree.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/reducers/source-tree.js b/devtools/client/debugger/src/reducers/source-tree.js
new file mode 100644
index 0000000000..0d8ca49e81
--- /dev/null
+++ b/devtools/client/debugger/src/reducers/source-tree.js
@@ -0,0 +1,58 @@
+/* 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/>. */
+
+// @flow
+
+/**
+ * Source tree reducer
+ * @module reducers/source-tree
+ */
+
+import type { SourceTreeAction, FocusItem } from "../actions/types";
+
+export type SourceTreeState = {
+ expanded: Set<string>,
+ focusedItem: ?FocusItem,
+};
+
+export function initialSourcesTreeState(): SourceTreeState {
+ return {
+ expanded: new Set(),
+ focusedItem: null,
+ };
+}
+
+export default function update(
+ state: SourceTreeState = initialSourcesTreeState(),
+ action: SourceTreeAction
+): SourceTreeState {
+ switch (action.type) {
+ case "SET_EXPANDED_STATE":
+ return updateExpanded(state, action);
+
+ case "SET_FOCUSED_SOURCE_ITEM":
+ return { ...state, focusedItem: action.item };
+ }
+
+ return state;
+}
+
+function updateExpanded(state, action) {
+ return {
+ ...state,
+ expanded: new Set(action.expanded),
+ };
+}
+
+type OuterState = {
+ sourceTree: SourceTreeState,
+};
+
+export function getExpandedState(state: OuterState) {
+ return state.sourceTree.expanded;
+}
+
+export function getFocusedSourceItem(state: OuterState): ?FocusItem {
+ return state.sourceTree.focusedItem;
+}