breakpointSources.js (1914B)
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 { getSelectedSource } from "./sources"; 7 import { getBreakpointsList } from "./breakpoints"; 8 import { getSelectedLocation } from "../utils/selected-location"; 9 10 // Returns a list of sources with their related breakpoints: 11 // [{ source, breakpoints: [breakpoint1, ...] }, ...] 12 // 13 // This only returns sources for which we have a visible breakpoint. 14 // This will return either generated or original source based on the currently 15 // selected source. 16 export const getBreakpointSources = createSelector( 17 getBreakpointsList, 18 getSelectedSource, 19 (breakpoints, selectedSource) => { 20 const visibleBreakpoints = breakpoints.filter( 21 bp => 22 !bp.options.hidden && 23 (bp.text || bp.originalText || bp.options.condition || bp.disabled) 24 ); 25 26 const sources = new Map(); 27 for (const breakpoint of visibleBreakpoints) { 28 // Depending on the selected source, this will match the original or generated 29 // location of the given selected source. 30 const location = getSelectedLocation(breakpoint, selectedSource); 31 const { source } = location; 32 33 // We may have more than one breakpoint per source, 34 // so use the map to have a unique entry per source. 35 if (!sources.has(source)) { 36 sources.set(source, { 37 source, 38 breakpoints: [breakpoint], 39 }); 40 } else { 41 sources.get(source).breakpoints.push(breakpoint); 42 } 43 } 44 45 // Returns an array of breakpoints info per source, sorted by source's displayed name 46 return [...sources.values()].sort((a, b) => 47 a.source.shortName.localeCompare(b.source.shortName) 48 ); 49 } 50 );