exceptions.js (1923B)
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 import { createSelector } from "devtools/client/shared/vendor/reselect"; 6 import { shallowEqual, arrayShallowEqual } from "../utils/shallow-equal"; 7 8 import { getSelectedSource, getSourceActorsForSource } from "./index"; 9 10 export const getSelectedSourceExceptions = createSelector( 11 getSelectedSourceActors, 12 // Do not retrieve mutableExceptionsMap as it will never change and createSelector would 13 // prevent re-running the selector in case of modification. state.exception is the `state` 14 // in the reducer, which we take care of cloning in case of new exception. 15 state => state.exceptions, 16 (sourceActors, exceptionsState) => { 17 const { mutableExceptionsMap } = exceptionsState; 18 const sourceExceptions = []; 19 20 for (const sourceActor of sourceActors) { 21 const exceptions = mutableExceptionsMap.get(sourceActor.id); 22 if (exceptions) { 23 sourceExceptions.push(...exceptions); 24 } 25 } 26 27 return sourceExceptions; 28 }, 29 // Shallow compare both input and output because of arrays being possibly always 30 // different instance but with same content. 31 { 32 memoizeOptions: { 33 equalityCheck: shallowEqual, 34 resultEqualityCheck: arrayShallowEqual, 35 }, 36 } 37 ); 38 39 function getSelectedSourceActors(state) { 40 const selectedSource = getSelectedSource(state); 41 if (!selectedSource) { 42 return []; 43 } 44 return getSourceActorsForSource(state, selectedSource.id); 45 } 46 47 export function getSelectedException(state, line, column) { 48 const sourceExceptions = getSelectedSourceExceptions(state); 49 50 if (!sourceExceptions) { 51 return undefined; 52 } 53 54 return sourceExceptions.find( 55 sourceExc => 56 sourceExc.lineNumber === line && sourceExc.columnNumber === column 57 ); 58 }