tor-browser

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

simulation.js (1291B)


      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  accessibility: { SIMULATION_TYPE },
      9 } = require("resource://devtools/shared/constants.js");
     10 const {
     11  SIMULATE,
     12 } = require("resource://devtools/client/accessibility/constants.js");
     13 
     14 /**
     15 * Initial state definition
     16 */
     17 function getInitialState() {
     18  return {
     19    [SIMULATION_TYPE.ACHROMATOPSIA]: false,
     20    [SIMULATION_TYPE.PROTANOPIA]: false,
     21    [SIMULATION_TYPE.DEUTERANOPIA]: false,
     22    [SIMULATION_TYPE.TRITANOPIA]: false,
     23    [SIMULATION_TYPE.CONTRAST_LOSS]: false,
     24  };
     25 }
     26 
     27 function simulation(state = getInitialState(), action) {
     28  switch (action.type) {
     29    case SIMULATE: {
     30      if (action.error) {
     31        console.warn("Error running simulation", action.error);
     32        return state;
     33      }
     34 
     35      const simTypes = action.simTypes;
     36 
     37      if (simTypes.length === 0) {
     38        return getInitialState();
     39      }
     40 
     41      const updatedState = getInitialState();
     42      simTypes.forEach(simType => {
     43        updatedState[simType] = true;
     44      });
     45 
     46      return updatedState;
     47    }
     48    default:
     49      return state;
     50  }
     51 }
     52 
     53 exports.simulation = simulation;