tor-browser

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

details.js (1497B)


      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 "use strict";
      5 
      6 const {
      7  UPDATE_DETAILS,
      8  RESET,
      9 } = require("resource://devtools/client/accessibility/constants.js");
     10 
     11 /**
     12 * Initial state definition
     13 */
     14 function getInitialState() {
     15  return {};
     16 }
     17 
     18 /**
     19 * Maintain details of a current relevant accessible.
     20 */
     21 function details(state = getInitialState(), action) {
     22  switch (action.type) {
     23    case UPDATE_DETAILS:
     24      return onUpdateDetails(state, action);
     25    case RESET:
     26      return getInitialState();
     27    default:
     28      return state;
     29  }
     30 }
     31 
     32 /**
     33 * Handle details update for an accessible object
     34 *
     35 * @param {object} state  Current accessible object details.
     36 * @param {object} action Redux action object
     37 * @return {object}  updated state
     38 */
     39 function onUpdateDetails(state, action) {
     40  const { accessible, response, error } = action;
     41  if (error) {
     42    if (!accessible.isDestroyed()) {
     43      console.warn(
     44        `Error fetching accessible details: `,
     45        accessible.actorID,
     46        error
     47      );
     48    }
     49 
     50    return getInitialState();
     51  }
     52 
     53  const [DOMNode, relationObjects, audit] = response;
     54  const relations = {};
     55  relationObjects.forEach(({ type, targets }) => {
     56    relations[type] = targets.length === 1 ? targets[0] : targets;
     57  });
     58  return { accessible, DOMNode, relations, audit };
     59 }
     60 
     61 exports.details = details;