From 6fbc4e4652309293462b3dc576ce4babcf4017f4 Mon Sep 17 00:00:00 2001 From: Kenji Okamoto Date: Tue, 13 Nov 2018 08:33:31 -0800 Subject: [PATCH] Simplify the getBreakpointsForSource selector function (#7264) * Simplify the getBreakpointsForSource selector function * tweak tests --- src/reducers/breakpoints.js | 16 ++++------------ src/reducers/tests/breakpoints.spec.js | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/reducers/breakpoints.js b/src/reducers/breakpoints.js index 37714eb1f2..02a20592af 100644 --- a/src/reducers/breakpoints.js +++ b/src/reducers/breakpoints.js @@ -296,21 +296,13 @@ export function getBreakpointsForSource( } const isGeneratedSource = isGeneratedId(sourceId); - const breakpoints = getBreakpointsMap(state); - - const breakpointsForSource = []; - - for (const key in breakpoints) { - const bp = breakpoints[key]; + const breakpoints = getBreakpointsList(state); + return breakpoints.filter(bp => { const location = isGeneratedSource ? bp.generatedLocation || bp.location : bp.location; - if (location.sourceId === sourceId) { - breakpointsForSource.push({ ...bp }); - } - } - - return breakpointsForSource; + return location.sourceId === sourceId; + }); } export function getBreakpointForLine( diff --git a/src/reducers/tests/breakpoints.spec.js b/src/reducers/tests/breakpoints.spec.js index badb769e2f..5638c4c0bf 100644 --- a/src/reducers/tests/breakpoints.spec.js +++ b/src/reducers/tests/breakpoints.spec.js @@ -37,9 +37,14 @@ describe("Breakpoints Selectors", () => { }; const breakpoints = initializeStateWith(data); - expect(getBreakpointsForSource({ breakpoints }, sourceId)).toEqual( - Object.values(matchingBreakpoints) + const allBreakpoints = Object.values(matchingBreakpoints); + const sourceBreakpoints = getBreakpointsForSource( + { breakpoints }, + sourceId ); + + expect(sourceBreakpoints).toEqual(allBreakpoints); + expect(sourceBreakpoints[0] === allBreakpoints[0]).toBe(true); }); it("it gets a breakpoint for a generated source", () => { @@ -71,8 +76,12 @@ describe("Breakpoints Selectors", () => { const breakpoints = initializeStateWith(data); - expect(getBreakpointsForSource({ breakpoints }, generatedSourceId)).toEqual( - Object.values(matchingBreakpoints) + const allBreakpoints = Object.values(matchingBreakpoints); + const sourceBreakpoints = getBreakpointsForSource( + { breakpoints }, + generatedSourceId ); + + expect(sourceBreakpoints).toEqual(allBreakpoints); }); });