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

Commit

Permalink
Removes .get - Part 1 (#5788)
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Sobek authored and jasonLaster committed Mar 26, 2018
1 parent 5689d80 commit 2b34694
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docs/dbg.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The actions are bound so you can call them directly!

```js
const source = dbg.store.getState().sources.sources.first();
dbg.actions.selectSource(source.get("id")))
dbg.actions.selectSource(source.id))
```

### selectors
Expand All @@ -39,7 +39,7 @@ The commands are the interface for talking to the debugger server.
```js
const source = dbg.selectors.getSelectedSource();
dbg.client
.setBreakpoint({line: 24, sourceId: source.get("id")})
.setBreakpoint({line: 24, sourceId: source.id})
.then(console.log)
```

Expand Down
10 changes: 3 additions & 7 deletions src/actions/file-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Match = Object;
export function doSearch(query: string, editor: Editor) {
return ({ getState, dispatch }: ThunkArgs) => {
const selectedSource = getSelectedSource(getState());
if (!selectedSource || !selectedSource.get("text")) {
if (!selectedSource || !selectedSource.text) {
return;
}

Expand Down Expand Up @@ -75,19 +75,15 @@ export function searchContents(query: string, editor: Object) {
!query ||
!editor ||
!selectedSource ||
!selectedSource.get("text") ||
!selectedSource.text ||
!modifiers
) {
return;
}

const ctx = { ed: editor, cm: editor.codeMirror };
const _modifiers = modifiers.toJS();
const matches = await getMatches(
query,
selectedSource.get("text"),
_modifiers
);
const matches = await getMatches(query, selectedSource.text, _modifiers);

const res = find(ctx, query, true, _modifiers);
if (!res) {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/pause/mapScopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export function mapScopes(scopes: Promise<Scope>, frame: Frame) {

const shouldMapScopes =
features.mapScopes &&
!generatedSourceRecord.get("isWasm") &&
!sourceRecord.get("isPrettyPrinted") &&
!generatedSourceRecord.isWasm &&
!sourceRecord.isPrettyPrinted &&
!isGeneratedId(frame.location.sourceId);

await dispatch({
Expand Down
5 changes: 2 additions & 3 deletions src/actions/project-text-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ export function searchSources(query: string) {
.valueSeq()
.filter(
source =>
!hasPrettySource(getState(), source.get("id")) &&
!isThirdParty(source)
!hasPrettySource(getState(), source.id) && !isThirdParty(source)
);
for (const source of validSources) {
await dispatch(loadSourceText(source));
await dispatch(searchSource(source.get("id"), query));
await dispatch(searchSource(source.id, query));
}
dispatch(updateSearchStatus(statusType.done));
};
Expand Down
6 changes: 3 additions & 3 deletions src/actions/sources/prettyPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { ThunkArgs } from "../types";
export function createPrettySource(sourceId: string) {
return async ({ dispatch, getState, sourceMaps }: ThunkArgs) => {
const source = getSource(getState(), sourceId);
const url = getPrettySourceURL(source.get("url"));
const url = getPrettySourceURL(source.url);
const id = await sourceMaps.generatedToOriginalId(sourceId, url);

const prettySource = {
Expand All @@ -39,7 +39,7 @@ export function createPrettySource(sourceId: string) {
dispatch({ type: "ADD_SOURCE", source: prettySource });

const { code, mappings } = await prettyPrint({ source, url });
await sourceMaps.applySourceMap(source.get("id"), url, code, mappings);
await sourceMaps.applySourceMap(source.id, url, code, mappings);

const loadedPrettySource = {
...prettySource,
Expand Down Expand Up @@ -84,7 +84,7 @@ export function togglePrettyPrint(sourceId: string) {
);

const selectedLocation = getSelectedLocation(getState());
const url = getPrettySourceURL(source.get("url"));
const url = getPrettySourceURL(source.url);
const prettySource = getSourceByURL(getState(), url);

const options = {};
Expand Down
4 changes: 2 additions & 2 deletions src/actions/sources/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function selectSourceURL(
return async ({ dispatch, getState }: ThunkArgs) => {
const source = getSourceByURL(getState(), url);
if (source) {
const sourceId = source.get("id");
const sourceId = source.id;
const location = createLocation({ ...options.location, sourceId });
// flow is unable to comprehend that if an options.location object
// exists, that we have a valid Location object, and if it doesnt,
Expand Down Expand Up @@ -131,7 +131,7 @@ export function selectLocation(location: Location) {
isMinified(selectedSource)
) {
await dispatch(togglePrettyPrint(sourceId));
dispatch(closeTab(source.get("url")));
dispatch(closeTab(source.url));
}

dispatch(setSymbols(sourceId));
Expand Down
8 changes: 4 additions & 4 deletions src/actions/sources/tests/loadSource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ describe("loadSourceText", async () => {
await dispatch(actions.loadSourceText(I.Map({ id: "foo1" })));
const fooSource = selectors.getSource(getState(), "foo1");

expect(fooSource.get("text").indexOf("return foo1")).not.toBe(-1);
expect(fooSource.text.indexOf("return foo1")).not.toBe(-1);

await dispatch(actions.loadSourceText(I.Map({ id: "foo2" })));
const foo2Source = selectors.getSource(getState(), "foo2");

expect(foo2Source.get("text").indexOf("return foo2")).not.toBe(-1);
expect(foo2Source.text.indexOf("return foo2")).not.toBe(-1);
});

it("loads two sources w/ one request", async () => {
Expand All @@ -47,7 +47,7 @@ describe("loadSourceText", async () => {
resolve({ source: "yay", contentType: "text/javascript" });
await loading;
expect(count).toEqual(1);
expect(selectors.getSource(getState(), id).get("text")).toEqual("yay");
expect(selectors.getSource(getState(), id).text).toEqual("yay");
});

it("doesn't re-load loaded sources", async () => {
Expand All @@ -72,7 +72,7 @@ describe("loadSourceText", async () => {
source = selectors.getSource(getState(), id);
await dispatch(actions.loadSourceText(source));
expect(count).toEqual(1);
expect(selectors.getSource(getState(), id).get("text")).toEqual("yay");
expect(selectors.getSource(getState(), id).text).toEqual("yay");
});

it("should cache subsequent source text loads", async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/sources/tests/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("sources", () => {
expect(selectedSource.get("id")).toEqual("foo1");

const source = getSource(getState(), selectedSource.get("id"));
expect(source.get("id")).toEqual("foo1");
expect(source.id).toEqual("foo1");

await waitForState(
store,
Expand All @@ -58,7 +58,7 @@ describe("sources", () => {

expect(getSelectedSource(getState())).toBe(undefined);
await dispatch(actions.newSource(baseSource));
expect(getSelectedSource(getState()).get("url")).toBe(baseSource.url);
expect(getSelectedSource(getState()).url).toBe(baseSource.url);
});

it("should open a tab for the source", async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Editor/EditorMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function getMenuItems(
const blackboxKey = L10N.getStr("sourceFooter.blackbox.accesskey");
const blackboxLabel = L10N.getStr("sourceFooter.blackbox");
const unblackboxLabel = L10N.getStr("sourceFooter.unblackbox");
const toggleBlackBoxLabel = selectedSource.get("isBlackBoxed")
const toggleBlackBoxLabel = selectedSource.isBlackBoxed
? unblackboxLabel
: blackboxLabel;
const copyFunctionKey = L10N.getStr("copyFunction.accesskey");
Expand Down Expand Up @@ -101,7 +101,7 @@ function getMenuItems(
label: copyToClipboardLabel,
accesskey: copyToClipboardKey,
disabled: false,
click: () => copyToTheClipboard(selectedSource.get("text"))
click: () => copyToTheClipboard(selectedSource.text)
};

const copySourceItem = {
Expand All @@ -117,7 +117,7 @@ function getMenuItems(
label: copySourceUri2Label,
accesskey: copySourceUri2Key,
disabled: false,
click: () => copyToTheClipboard(getRawSourceURL(selectedSource.get("url")))
click: () => copyToTheClipboard(getRawSourceURL(selectedSource.url))
};

const sourceId = selectedSource.get("id");
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SourceFooter extends PureComponent<Props> {
return;
}

const blackboxed = selectedSource.get("isBlackBoxed");
const blackboxed = selectedSource.isBlackBoxed;

const tooltip = L10N.getStr("sourceFooter.blackbox");
const type = "black-box";
Expand All @@ -98,7 +98,7 @@ class SourceFooter extends PureComponent<Props> {
blackBoxSummary() {
const { selectedSource } = this.props;

if (!selectedSource || !selectedSource.get("isBlackBoxed")) {
if (!selectedSource || !selectedSource.isBlackBoxed) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/Editor/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Tab extends PureComponent<Props> {
item: {
...tabMenuItems.copyToClipboard,
disabled: selectedSource.get("id") !== tab,
click: () => copyToTheClipboard(sourceTab.get("text"))
click: () => copyToTheClipboard(sourceTab.text)
}
},
{
Expand Down Expand Up @@ -157,7 +157,7 @@ class Tab extends PureComponent<Props> {
} = this.props;
const src = source.toJS();
const filename = getFilename(src);
const sourceId = source.get("id");
const sourceId = source.id;
const active =
selectedSource &&
sourceId == selectedSource.get("id") &&
Expand All @@ -167,7 +167,7 @@ class Tab extends PureComponent<Props> {

function onClickClose(e) {
e.stopPropagation();
closeTab(source.get("url"));
closeTab(source.url);
}

function handleTabClick(e) {
Expand All @@ -176,7 +176,7 @@ class Tab extends PureComponent<Props> {

// Accommodate middle click to close tab
if (e.button === 1) {
return closeTab(source.get("url"));
return closeTab(source.url);
}

return selectSource(sourceId);
Expand Down Expand Up @@ -212,7 +212,7 @@ export default connect(
return {
tabSources: getSourcesForTabs(state),
selectedSource: selectedSource,
sourceMetaData: getSourceMetaData(state, source.get("id")),
sourceMetaData: getSourceMetaData(state, source.id),
activeSearch: getActiveSearch(state)
};
},
Expand Down
8 changes: 4 additions & 4 deletions src/components/Editor/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Tabs extends PureComponent<Props, State> {
const hiddenTabs = getHiddenTabs(tabSources, sourceTabEls);

if (isVisible() && hiddenTabs.indexOf(selectedSource) !== -1) {
return moveTab(selectedSource.get("url"), 0);
return moveTab(selectedSource.url, 0);
}

this.setState({ hiddenTabs });
Expand All @@ -114,7 +114,7 @@ class Tabs extends PureComponent<Props, State> {
if (isPretty(source)) {
return "prettyPrint";
}
if (source.get("isBlackBoxed")) {
if (source.isBlackBoxed) {
return "blackBox";
}
return "file";
Expand All @@ -124,9 +124,9 @@ class Tabs extends PureComponent<Props, State> {
const { selectSource } = this.props;
const filename = getFilename(source.toJS());

const onClick = () => selectSource(source.get("id"));
const onClick = () => selectSpecificSource(source.id);
return (
<li key={source.get("id")} onClick={onClick}>
<li key={source.id} onClick={onClick}>
<img className={`dropdown-icon ${this.getIconClass(source)}`} />
{filename}
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class Editor extends PureComponent<Props, State> {
if (
(ev.ctrlKey && ev.button === 0) ||
ev.which === 3 ||
(selectedSource && selectedSource.get("isBlackBoxed")) ||
(selectedSource && selectedSource.isBlackBoxed) ||
!selectedSource
) {
return;
Expand Down
6 changes: 2 additions & 4 deletions src/components/SecondaryPanes/Breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function getBreakpointFilename(source) {

function renderSourceLocation(source, line, column) {
const filename = getBreakpointFilename(source);
const isWasm = source && source.get("isWasm");
const isWasm = source && source.isWasm;
const columnVal = features.columnBreakpoints && column ? `:${column}` : "";
const bpLocation = isWasm
? `0x${line.toString(16).toUpperCase()}`
Expand Down Expand Up @@ -199,9 +199,7 @@ const _getBreakpoints = createSelector(
(breakpoints, sources, frame, why) =>
breakpoints
.map(bp => updateLocation(sources, frame, why, bp))
.filter(
bp => bp.location.source && !bp.location.source.get("isBlackBoxed")
)
.filter(bp => bp.location.source && !bp.location.source.isBlackBoxed)
);

export default connect(
Expand Down
2 changes: 1 addition & 1 deletion src/test/mochitest/browser_dbg-editor-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ add_task(async function() {
is(getSource(getState(), simple1.id).get("loadedState"), "loading");

await waitForSelectedSource(dbg, "simple1.js");
ok(getSource(getState(), simple1.id).get("text"));
ok(getSource(getState(), simple1.id).text);
assertHighlightLocation(dbg, "simple1.js", 6);
});
6 changes: 3 additions & 3 deletions src/test/mochitest/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function waitForSelectedSource(dbg, url) {
}

const newSource = findSource(dbg, url, { silent: true });
if (newSource.id != source.get("id")) {
if (newSource.id != source.id) {
return false;
}

Expand Down Expand Up @@ -314,7 +314,7 @@ function assertDebugLine(dbg, line) {
const lineInfo = getCM(dbg).lineInfo(line - 1);
const source = dbg.selectors.getSelectedSource(dbg.getState());
if (source && source.get("loadedState") == "loading") {
const url = source.get("url");
const url = source.url;
ok(
false,
`Looks like the source ${url} is still loading. Try adding waitForLoadedSource in the test.`
Expand Down Expand Up @@ -466,7 +466,7 @@ function isSelectedFrameSelected(dbg, state) {
return false;
}

return source.get("id") == sourceId;
return source.id == sourceId;
}

function createDebuggerContext(toolbox) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/isMinified.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const CHARACTER_LIMIT = 250;
const _minifiedCache = new Map();

export function isMinified(source: SourceRecord) {
if (_minifiedCache.has(source.get("id"))) {
return _minifiedCache.get(source.get("id"));
if (_minifiedCache.has(source.id)) {
return _minifiedCache.get(source.id);
}

let text = source.get("text");
Expand Down
6 changes: 3 additions & 3 deletions src/utils/quick-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function formatSources(sources: SourcesMap): Array<QuickOpenResult> {
.valueSeq()
.filter(source => !isPretty(source))
.map(source => {
const sourcePath = getSourcePath(source.get("url"));
const sourcePath = getSourcePath(source.url);
return {
value: sourcePath,
title: sourcePath
Expand All @@ -121,8 +121,8 @@ export function formatSources(sources: SourcesMap): Array<QuickOpenResult> {
subtitle: endTruncateStr(sourcePath, 100)
.replace(sourcePath.split("/").pop(), "")
.slice(1, -1),
id: source.get("id"),
url: source.get("url")
id: source.id,
url: source.url
};
})
.filter(({ value }) => value != "")
Expand Down
Loading

0 comments on commit 2b34694

Please sign in to comment.