tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sidebar.js (1861B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  EXTENSION_SIDEBAR_OBJECT_TREEVIEW_UPDATE,
      9  EXTENSION_SIDEBAR_EXPRESSION_RESULT_VIEW_UPDATE,
     10  EXTENSION_SIDEBAR_PAGE_UPDATE,
     11  EXTENSION_SIDEBAR_REMOVE,
     12 } = require("resource://devtools/client/inspector/extensions/actions/index.js");
     13 
     14 const INITIAL_SIDEBAR = {};
     15 
     16 const reducers = {
     17  [EXTENSION_SIDEBAR_OBJECT_TREEVIEW_UPDATE](sidebar, { sidebarId, object }) {
     18    // Update the sidebar to a "object-treeview" which shows
     19    // the passed object.
     20    return Object.assign({}, sidebar, {
     21      [sidebarId]: {
     22        viewMode: "object-treeview",
     23        object,
     24      },
     25    });
     26  },
     27 
     28  [EXTENSION_SIDEBAR_EXPRESSION_RESULT_VIEW_UPDATE](
     29    sidebar,
     30    { sidebarId, expressionResult, rootTitle }
     31  ) {
     32    // Update the sidebar to a "object-treeview" which shows
     33    // the passed object.
     34    return Object.assign({}, sidebar, {
     35      [sidebarId]: {
     36        viewMode: "object-value-grip-view",
     37        expressionResult,
     38        rootTitle,
     39      },
     40    });
     41  },
     42 
     43  [EXTENSION_SIDEBAR_PAGE_UPDATE](sidebar, { sidebarId, iframeURL }) {
     44    // Update the sidebar to a "object-treeview" which shows
     45    // the passed object.
     46    return Object.assign({}, sidebar, {
     47      [sidebarId]: {
     48        viewMode: "extension-page",
     49        iframeURL,
     50      },
     51    });
     52  },
     53 
     54  [EXTENSION_SIDEBAR_REMOVE](sidebar, { sidebarId }) {
     55    // Remove the sidebar from the Redux store.
     56    delete sidebar[sidebarId];
     57    return Object.assign({}, sidebar);
     58  },
     59 };
     60 
     61 module.exports = function (sidebar = INITIAL_SIDEBAR, action) {
     62  const reducer = reducers[action.type];
     63  if (!reducer) {
     64    return sidebar;
     65  }
     66  return reducer(sidebar, action);
     67 };