Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Simplify the getBreakpointsForSource selector function (#7264)
Browse files Browse the repository at this point in the history
* Simplify the getBreakpointsForSource selector function
* tweak tests
  • Loading branch information
kenjiO authored and jasonLaster committed Nov 13, 2018
1 parent adcd53a commit 6fbc4e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 4 additions & 12 deletions src/reducers/breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 13 additions & 4 deletions src/reducers/tests/breakpoints.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 6fbc4e4

Please sign in to comment.