Skip to content

Commit

Permalink
Bug 1775203 - [devtools] Remove "loading" state of symbols state obje…
Browse files Browse the repository at this point in the history
…ct. r=bomsy

This helps reduce the number of state changes and the number of renders.
We now switch from null symbols which means they are loading,
to an object with the loaded symbols.

Differential Revision: https://phabricator.services.mozilla.com/D149855
  • Loading branch information
ochameau committed Jun 27, 2022
1 parent 523887d commit b3ba605
Show file tree
Hide file tree
Showing 19 changed files with 17 additions and 101 deletions.
4 changes: 2 additions & 2 deletions devtools/client/debugger/bin/module-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@
"byName": {},
"byBlocks": {},
"usedIds": {
"0": 0
"1": 1
}
}
}
Expand All @@ -2466,7 +2466,7 @@
"byName": {},
"byBlocks": {},
"usedIds": {
"0": 0
"1": 1
}
}
}
Expand Down
1 change: 0 additions & 1 deletion devtools/client/debugger/dist/parser-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14695,7 +14695,6 @@ function extractSymbols(sourceId) {
literals: [],
hasJsx: false,
hasTypes: false,
loading: false,
framework: undefined
};
const state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function highlightCalls(cx) {

const symbols = getSymbols(getState(), source);

if (!symbols || symbols.loading) {
if (!symbols) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion devtools/client/debugger/src/actions/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function findExpressionMatch(state, codeMirror, tokenPos) {
const symbols = getSymbols(state, source);

let match;
if (!symbols || symbols.loading) {
if (!symbols) {
match = getExpressionFromCoords(codeMirror, tokenPos);
} else {
match = findBestMatchExpression(symbols, tokenPos);
Expand Down
2 changes: 1 addition & 1 deletion devtools/client/debugger/src/actions/sources/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const setSymbols = memoizeableAction("setSymbols", {
}

const symbols = getSymbols(getState(), source);
if (!symbols || symbols.loading) {
if (!symbols) {
return null;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Object {
],
"imports": Array [],
"literals": Array [],
"loading": false,
"memberExpressions": Array [],
"objectProperties": Array [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Outline extends Component {
let classes = [];
let functions = [];

if (symbols && !symbols.loading) {
if (symbols) {
({ classes, functions } = symbols);
}

Expand Down Expand Up @@ -221,7 +221,7 @@ export class Outline extends Component {
renderClassFunctions(klass, functions) {
const { symbols } = this.props;

if (!symbols || symbols.loading || klass == null || functions.length == 0) {
if (!symbols || klass == null || functions.length == 0) {
return null;
}

Expand Down Expand Up @@ -310,7 +310,7 @@ export class Outline extends Component {
return this.renderPlaceholder();
}

if (!symbols || symbols.loading) {
if (!symbols) {
return this.renderLoading();
}

Expand Down
9 changes: 0 additions & 9 deletions devtools/client/debugger/src/components/test/Outline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ describe("Outline", () => {
});
expect(component).toMatchSnapshot();
});

it("if symbols are loading", () => {
const { component } = render({
symbols: {
loading: true,
},
});
expect(component).toMatchSnapshot();
});
});

it("renders ignore anonymous functions", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,6 @@ exports[`Outline renders outline renders ignore anonymous functions 1`] = `
</div>
`;

exports[`Outline renders outline renders loading if symbols are loading 1`] = `
<div
className="outline-pane-info"
>
Loading…
</div>
`;

exports[`Outline renders outline renders loading if symbols is not defined 1`] = `
<div
className="outline-pane-info"
Expand Down
5 changes: 1 addition & 4 deletions devtools/client/debugger/src/reducers/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ function update(state = initialASTState(), action) {
case "SET_SYMBOLS": {
const { sourceId } = action;
if (action.status === "start") {
return {
...state,
symbols: { ...state.symbols, [sourceId]: { loading: true } },
};
return state;
}

const value = action.value;
Expand Down
15 changes: 2 additions & 13 deletions devtools/client/debugger/src/selectors/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,11 @@ export function getSymbols(state, source) {
}

export function hasSymbols(state, source) {
const symbols = getSymbols(state, source);

if (!symbols) {
return false;
}

return !symbols.loading;
return !!getSymbols(state, source);
}

export function isSymbolsLoading(state, source) {
const symbols = getSymbols(state, source);
if (!symbols) {
return false;
}

return symbols.loading;
return !getSymbols(state, source);
}

export function getInScopeLines(state, location) {
Expand Down
6 changes: 3 additions & 3 deletions devtools/client/debugger/src/utils/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

export function findBestMatchExpression(symbols, tokenPos) {
if (symbols.loading) {
if (!symbols) {
return null;
}

Expand Down Expand Up @@ -81,15 +81,15 @@ function findClosestofSymbol(declarations, location) {
}

export function findClosestFunction(symbols, location) {
if (!symbols || symbols.loading) {
if (!symbols) {
return null;
}

return findClosestofSymbol(symbols.functions, location);
}

export function findClosestClass(symbols, location) {
if (!symbols || symbols.loading) {
if (!symbols) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion devtools/client/debugger/src/utils/quick-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function formatSymbol(symbol) {
}

export function formatSymbols(symbols) {
if (!symbols || symbols.loading) {
if (!symbols) {
return { functions: [] };
}

Expand Down
2 changes: 1 addition & 1 deletion devtools/client/debugger/src/utils/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export function getSourceClassnames(source, symbols) {
return "blackBox";
}

if (symbols && !symbols.loading && symbols.framework) {
if (symbols && symbols.framework) {
return symbols.framework.toLowerCase();
}

Expand Down
1 change: 0 additions & 1 deletion devtools/client/debugger/src/utils/tests/source.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const defaultSymbolDeclarations = {
literals: [],
hasJsx: false,
hasTypes: false,
loading: false,
framework: undefined,
};

Expand Down
1 change: 0 additions & 1 deletion devtools/client/debugger/src/workers/parser/getSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function extractSymbols(sourceId) {
literals: [],
hasJsx: false,
hasTypes: false,
loading: false,
framework: undefined,
};

Expand Down
Loading

0 comments on commit b3ba605

Please sign in to comment.