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

Commit

Permalink
Replaces Object.assign with ... spread (#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Sobek authored and jasonLaster committed Nov 9, 2017
1 parent 466c686 commit 60c5981
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 167 deletions.
4 changes: 1 addition & 3 deletions src/actions/breakpoints/tests/syncing.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import { findScopeByName } from "../../../utils/breakpoint/astBreakpointLocation
import { syncClientBreakpoint } from "../../breakpoints/syncBreakpoint.js";

function setBreakpoint(location, condition) {
const actualLocation = Object.assign({}, location, {
line: location.line
});
const actualLocation = { ...location, line: location.line };

return Promise.resolve({
id: makeLocationId(location),
Expand Down
37 changes: 18 additions & 19 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ import * as loadSourceText from "./sources/loadSourceText";
import * as debuggee from "./debuggee";
import * as toolbox from "./toolbox";

export default Object.assign(
{},
navigation,
breakpoints,
expressions,
eventListeners,
sources,
pause,
ui,
fileSearch,
ast,
coverage,
projectTextSearch,
quickOpen,
sourceTree,
loadSourceText,
debuggee,
toolbox
);
export default {
...navigation,
...breakpoints,
...expressions,
...eventListeners,
...sources,
...pause,
...ui,
...fileSearch,
...ast,
...coverage,
...projectTextSearch,
...quickOpen,
...sourceTree,
...loadSourceText,
...debuggee,
...toolbox
};
6 changes: 2 additions & 4 deletions src/actions/tests/helpers/threadClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ function generateCorrectingThreadClient(offset = 0) {
return {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, condition) => {
const actualLocation = Object.assign({}, location, {
line: location.line + offset
});
const actualLocation = { ...location, line: location.line + offset };

return Promise.resolve({
id: makeLocationId(location),
Expand All @@ -71,7 +69,7 @@ function generateCorrectingThreadClient(offset = 0) {
export function simulateCorrectThreadClient(offset, location) {
const correctedThreadClient = generateCorrectingThreadClient(offset);
const offsetLine = { line: location.line + offset };
const correctedLocation = Object.assign({}, location, offsetLine);
const correctedLocation = { ...location, ...offsetLine };
return { correctedThreadClient, correctedLocation };
}

Expand Down
9 changes: 4 additions & 5 deletions src/actions/tests/pending-breakpoints.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ describe("initializing with disabled pending breakpoints in prefs", () => {
});

it("syncs breakpoints with pending breakpoints", async () => {
const expectedLocation = Object.assign(
{},
mockedPendingBreakpoint.location,
{ sourceId: "bar.js" }
);
const expectedLocation = {
...mockedPendingBreakpoint.location,
sourceId: "bar.js"
};

const expectedId = makeLocationId(expectedLocation);
const { getState, dispatch } = createStore(simpleMockThreadClient);
Expand Down
22 changes: 8 additions & 14 deletions src/actions/utils/middleware/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,27 @@ function promiseMiddleware({

// Create a new action that doesn't have the promise field and has
// the `seqId` field that represents the sequence id
action = Object.assign(filterAction(action), { seqId });
action = { ...filterAction(action), seqId };

dispatch(Object.assign({}, action, { status: "start" }));
dispatch({ ...action, status: "start" });

// Return the promise so action creators can still compose if they
// want to.
return new Promise((resolve, reject) => {
promiseInst.then(
value => {
executeSoon(() => {
dispatch(
Object.assign({}, action, {
status: "done",
value: value
})
);
dispatch({ ...action, status: "done", value: value });
resolve(value);
});
},
error => {
executeSoon(() => {
dispatch(
Object.assign({}, action, {
status: "error",
error: error.message || error
})
);
dispatch({
...action,
status: "error",
error: error.message || error
});
reject(error);
});
}
Expand Down
8 changes: 1 addition & 7 deletions src/client/chrome/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ async function paused({
}: any) {
const frames = callFrames.map(createFrame);
const frame = frames[0];
const why = Object.assign(
{},
{
type: reason
},
data
);
const why = { type: reason, ...data };

const objectId = frame.scopeChain[0].object.objectId;
const { result } = await runtimeAgent.getProperties({
Expand Down
5 changes: 3 additions & 2 deletions src/client/firefox/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ export function createPause(
// NOTE: useful when the debugger is already paused
const frame = packet.frame || response.frames[0];

return Object.assign({}, packet, {
return {
...packet,
frame: createFrame(frame),
frames: response.frames.map(createFrame)
});
};
}

// Firefox only returns `actualLocation` if it actually changed,
Expand Down
52 changes: 23 additions & 29 deletions src/components/Editor/GutterMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,26 @@ export function gutterMenu({
}
};

const toggleBreakpointItem = Object.assign(
{
accesskey: L10N.getStr("shortcuts.toggleBreakpoint.accesskey"),
disabled: false,
click: () => {
toggleBreakpoint(line);
if (isCbPanelOpen) {
closeConditionalPanel();
}
const toggleBreakpointItem = {
accesskey: L10N.getStr("shortcuts.toggleBreakpoint.accesskey"),
disabled: false,
click: () => {
toggleBreakpoint(line);
if (isCbPanelOpen) {
closeConditionalPanel();
}
},
breakpoint ? gutterItems.removeBreakpoint : gutterItems.addBreakpoint
);
...(breakpoint ? gutterItems.removeBreakpoint : gutterItems.addBreakpoint)
};

const conditionalBreakpoint = Object.assign(
{
accesskey: L10N.getStr("editor.addConditionalBreakpoint.accesskey"),
disabled: false,
click: () => openConditionalPanel(line)
},
breakpoint && breakpoint.condition
const conditionalBreakpoint = {
accesskey: L10N.getStr("editor.addConditionalBreakpoint.accesskey"),
disabled: false,
click: () => openConditionalPanel(line),
...(breakpoint && breakpoint.condition
? gutterItems.editConditional
: gutterItems.addConditional
);
: gutterItems.addConditional)
};

const items = [toggleBreakpointItem, conditionalBreakpoint];

Expand All @@ -106,16 +102,14 @@ export function gutterMenu({
}

if (breakpoint) {
const disableBreakpoint = Object.assign(
{
accesskey: L10N.getStr("editor.disableBreakpoint.accesskey"),
disabled: false,
click: () => toggleDisabledBreakpoint(line)
},
breakpoint.disabled
const disableBreakpoint = {
accesskey: L10N.getStr("editor.disableBreakpoint.accesskey"),
disabled: false,
click: () => toggleDisabledBreakpoint(line),
...(breakpoint.disabled
? gutterItems.enableBreakpoint
: gutterItems.disableBreakpoint
);
: gutterItems.disableBreakpoint)
};
items.push(disableBreakpoint);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectSearch/tests/TextSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function render(overrides = {}) {
searchSources: jest.fn(),
selectSource: jest.fn()
};
const props = Object.assign({}, defaultProps, overrides);
const props = { ...defaultProps, ...overrides };

const component = shallow(<TextSearch {...props} />);
return component;
Expand Down
8 changes: 2 additions & 6 deletions src/components/SecondaryPanes/Breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,8 @@ function updateLocation(sources, pause, bp): LocalBreakpoint {
const isCurrentlyPaused = isCurrentlyPausedAtBreakpoint(pause, bp);
const locationId = makeLocationId(bp.location);

const location = Object.assign({}, bp.location, { source });
const localBP = Object.assign({}, bp, {
location,
locationId,
isCurrentlyPaused
});
const location = { ...bp.location, source };
const localBP = { ...bp, location, locationId, isCurrentlyPaused };

return localBP;
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/SecondaryPanes/EventListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ class EventListeners extends Component<Props> {

export default connect(
state => {
const listeners = getEventListeners(state).map(l =>
Object.assign({}, l, {
const listeners = getEventListeners(state).map(l => {
return {
...l,
breakpoint: getBreakpoint(state, {
sourceId: l.sourceId,
line: l.line
})
})
);
};
});

return { listeners };
},
Expand Down
4 changes: 1 addition & 3 deletions src/components/SecondaryPanes/Frames/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ function getSourceForFrame(sources, frame) {
}

function appendSource(sources, frame) {
return Object.assign({}, frame, {
source: getSourceForFrame(sources, frame).toJS()
});
return { ...frame, source: getSourceForFrame(sources, frame).toJS() };
}

export function getAndProcessFrames(frames: Frame[], sources: SourcesMap) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SecondaryPanes/Frames/tests/Frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function render(frameToSelect = {}, overrides = {}) {
line: 10
}
};
const frame = Object.assign({}, defaultFrame, overrides);
const selectedFrame = Object.assign({}, frame, frameToSelect);
const frame = { ...defaultFrame, ...overrides };
const selectedFrame = { ...frame, ...frameToSelect };
const selectFrame = jest.fn();
const toggleBlackBox = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion src/components/SecondaryPanes/Frames/tests/Frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function render(overrides = {}) {
toggleBlackBox: jest.fn()
};

const props = Object.assign({}, defaultProps, overrides);
const props = { ...defaultProps, ...overrides };
const component = shallow(<Frames.WrappedComponent {...props} />);

return component;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SecondaryPanes/Frames/tests/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function render(overrides = {}) {
toggleBlackBox: jest.fn()
};

const props = Object.assign({}, defaultProps, overrides);
const props = { ...defaultProps, ...overrides };
const component = shallow(<Group {...props} />);
return { component, props };
}
Expand Down
14 changes: 8 additions & 6 deletions src/reducers/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function update(state: PauseState = State(), action: Action): PauseState {
case "MAP_SCOPES":
const { frame, scopes } = action;
const selectedFrameId = frame.id;

const frameScopes = { ...state.frameScopes, [selectedFrameId]: scopes };
return { ...state, frameScopes };

Expand All @@ -94,13 +95,13 @@ function update(state: PauseState = State(), action: Action): PauseState {
pause.frame = frames[0];
}

return Object.assign({}, state, { pause, frames });
return { ...state, pause, frames };
}

break;

case "BREAK_ON_NEXT":
return Object.assign({}, state, { isWaitingOnBreak: true });
return { ...state, isWaitingOnBreak: true };

case "SELECT_FRAME":
return {
Expand All @@ -121,7 +122,7 @@ function update(state: PauseState = State(), action: Action): PauseState {

if (action.status === "done") {
if (!action.value) {
return Object.assign({}, state);
return { ...state };
}

const ownProperties = action.value.ownProperties;
Expand All @@ -139,18 +140,19 @@ function update(state: PauseState = State(), action: Action): PauseState {
break;

case "CONNECT":
return Object.assign({}, State(), { debuggeeUrl: action.url });
return { ...State(), debuggeeUrl: action.url };

case "PAUSE_ON_EXCEPTIONS":
const { shouldPauseOnExceptions, shouldIgnoreCaughtExceptions } = action;

prefs.pauseOnExceptions = shouldPauseOnExceptions;
prefs.ignoreCaughtExceptions = shouldIgnoreCaughtExceptions;

return Object.assign({}, state, {
return {
...state,
shouldPauseOnExceptions,
shouldIgnoreCaughtExceptions
});
};

case "COMMAND":
return action.status === "start"
Expand Down
5 changes: 3 additions & 2 deletions src/test/tests-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { readFileSync } from "fs";
const rootPath = path.join(__dirname, "../../");

const envConfig = getConfig();
const config = Object.assign({}, envConfig, {
const config = {
...envConfig,
workers: {
sourceMapURL: path.join(
rootPath,
Expand All @@ -17,7 +18,7 @@ const config = Object.assign({}, envConfig, {
prettyPrintURL: path.join(rootPath, "src/workers/pretty-print/worker.js"),
searchURL: path.join(rootPath, "src/workers/search/worker.js")
}
});
};

global.DebuggerConfig = config;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function bootstrapStore(client, { services, toolboxActions }) {
log: isTesting() || getValue("logging.actions"),
timing: isDevelopment(),
makeThunkArgs: (args, state) => {
return Object.assign({}, args, { client }, services, toolboxActions);
return { ...args, client, ...services, ...toolboxActions };
}
});

Expand Down
Loading

0 comments on commit 60c5981

Please sign in to comment.