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

Refactor Breakpoints to be location symmetric #3294

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

jasonLaster
Copy link
Contributor

Summary of Changes

This is a follow up refactor. The goal is to provide some abstractions so that BPs are better represented in the components:

  1. Components don't know/nor care if they're original or generated
  2. Components only care about showing BPs
  3. Toggle BP takes a line and column and does the rest
  4. The reducer formats a generic BP with the "right" location

const { sourceId } = selectedLocation;

if (bp) {
// NOTE: it's possible the breakpoint has slid to a column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the equalize location util!

};
}

export function toggleBreakpointDisabledStatus(line) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this, might need a simpler name like "toggleDisabledBreakpoint"

Copy link
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice direction!


const { sourceId } = selectedLocation;

if (!bp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we can avoid this somehow... 🤔

@@ -476,75 +475,6 @@ class Editor extends PureComponent {
return !!this.cbPanel;
}

toggleBreakpoint(line, column = undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 niiice

@@ -661,44 +591,6 @@ class Editor extends PureComponent {
});
}

renderBreakpoints() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woooo!

@jasonLaster jasonLaster added this to the July 25th milestone Jul 11, 2017
@jasonLaster jasonLaster changed the title Refactor Breakpoints Refactor Breakpoints to be location symmetric Jul 11, 2017
@codecov
Copy link

codecov bot commented Jul 11, 2017

Codecov Report

Merging #3294 into master will increase coverage by 0.46%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3294      +/-   ##
==========================================
+ Coverage   48.46%   48.92%   +0.46%     
==========================================
  Files         102      105       +3     
  Lines        4288     4319      +31     
  Branches      891      893       +2     
==========================================
+ Hits         2078     2113      +35     
+ Misses       2210     2206       -4
Impacted Files Coverage Δ
src/selectors.js 100% <ø> (ø) ⬆️
src/components/Editor/CallSites.js 2.12% <ø> (ø) ⬆️
src/selectors/linesInScope.js 93.75% <ø> (ø) ⬆️
src/utils/editor/index.js 14.63% <0%> (-0.76%) ⬇️
src/components/Editor/GutterMenu.js 0% <0%> (ø) ⬆️
src/utils/editor/expression.js 0% <0%> (ø) ⬆️
src/selectors/visibleBreakpoints.js 0% <0%> (ø)
src/components/Editor/Breakpoint.js 6.38% <0%> (+0.92%) ⬆️
src/actions/utils/breakpoints.js 78.26% <100%> (-13.05%) ⬇️
src/components/Editor/Breakpoints.js 13.33% <13.33%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5dc9f00...2df507c. Read the comment docs.

@jasonLaster jasonLaster force-pushed the refactor-bps2 branch 2 times, most recently from 6eb8bee to b2f407c Compare July 12, 2017 02:59
@@ -127,7 +133,6 @@ export function disableBreakpoint(location: Location) {
const action = {
type: "DISABLE_BREAKPOINT",
breakpoint: bp,
disabled: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, not being used...

source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps there's a better way to keep this dummy data...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it make sense to start using a factory library?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - that might be a nice cleanup in a separate PR.

selectedSource: getSelectedSource(state)
}),
dispatch => bindActionCreators(actions, dispatch)
)(Breakpoints);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the pattern of splitting out the editor children components. The separation makes it easier to follow

@asolove @codehag


editor.setGutterMarker(
showSourceText(editor, selectedSource.toJS());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important for making sure that we're updating the correct codemirror document.

}

/*
*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should include a quick description

: breakpoint.location;
}

export default function getVisibleBreakpoints(state: OuterState) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a quick comment to explain how this is used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this so that we can check if a breakpoint is also represented in a generated file? can we use it in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get the breakpoints for a file at the "correct" location regardless of original / generated

@@ -24,7 +24,7 @@ add_task(function*() {
yield addBreakpoint(dbg, mainSrc, 4);
is(getBreakpoints(getState()).size, 1, "One breakpoint exists");
ok(
getBreakpoint(getState(), { sourceId: mainSrc.id, line: 4 }),
getBreakpoint(getState(), { sourceId: mainSrc.id, line: 4, column: 2 }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this changed :/

It is probably alright though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a regression - before we were making sure that we didn't turn line breakpoints into column breakpoints...

@@ -14,8 +13,7 @@ export function firstString(...args) {

export function locationMoved(location, newLocation) {
return (
location.line !== newLocation.line ||
(location.column != null && location.column !== newLocation.column)
location.line !== newLocation.line || location.column !== newLocation.column
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nice clean up

: breakpoint.location;

const sameLine = location.line === line + 1;
const sameLine = breakpoint.location.line === line + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i love these cleanups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 nice!

Copy link
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work so far!

}

if (bp) {
// NOTE: it's possible the breakpoint has slid to a column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to slide a breakpoint to a column if the user is expecting a line breakpoint?

source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it make sense to start using a factory library?

return null;
}

return dom.div(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Breakpoint component returns null; so, do we need to wrap it in a div, or just return null, with the mapping done in the body of the function?

@@ -1,47 +1,45 @@
import { showMenu } from "devtools-launchpad";

export default function GutterMenu({
bp,
breakpoint,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return isGeneratedId(sourceId);
}

function getColumn(column, selectedSource) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this pattern better than keeping the selectors in the reducer. maybe we could have a folder structure here:

selectors/
|- breakpoints/
  |- index.js
  |- atLocation.js

: breakpoint.location;
}

export default function getVisibleBreakpoints(state: OuterState) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this so that we can check if a breakpoint is also represented in a generated file? can we use it in all cases?

@@ -24,7 +24,7 @@ add_task(function*() {
yield addBreakpoint(dbg, mainSrc, 4);
is(getBreakpoints(getState()).size, 1, "One breakpoint exists");
ok(
getBreakpoint(getState(), { sourceId: mainSrc.id, line: 4 }),
getBreakpoint(getState(), { sourceId: mainSrc.id, line: 4, column: 2 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a regression - before we were making sure that we didn't turn line breakpoints into column breakpoints...

: breakpoint.location;

const sameLine = location.line === line + 1;
const sameLine = breakpoint.location.line === line + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 nice!

@jasonLaster jasonLaster merged commit d66e4c0 into firefox-devtools:master Jul 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants