Skip to content

Commit c1bc28a

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
Use spread operator instead of Object.assign call (codesandbox#1898)
* Use spread operator instead of Object.assign call * Revert overmind folder * Revert generated file
1 parent b9dbd0e commit c1bc28a

File tree

10 files changed

+55
-61
lines changed

10 files changed

+55
-61
lines changed

packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class KeyMapping extends React.Component {
1919
const keybindings = this.props.store.preferences.settings.keybindings;
2020

2121
return keybindings.reduce(
22-
(bindings, binding) =>
23-
Object.assign(bindings, {
24-
[binding.key]: binding.bindings,
25-
}),
22+
(bindings, binding) => ({
23+
...bindings,
24+
[binding.key]: binding.bindings,
25+
}),
2626
{}
2727
);
2828
};

packages/app/src/app/store/actions.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ export function moveModuleContent({ props, state }) {
212212

213213
if (currentSandbox) {
214214
return {
215-
sandbox: Object.assign({}, props.forkedSandbox, {
216-
modules: props.forkedSandbox.modules.map(module =>
217-
Object.assign(module, {
218-
code: currentSandbox.modules.find(
219-
currentSandboxModule =>
220-
currentSandboxModule.shortid === module.shortid
221-
).code,
222-
})
223-
),
224-
}),
215+
sandbox: {
216+
...props.forkedSandbox,
217+
modules: props.forkedSandbox.modules.map(module => ({
218+
...module,
219+
code: currentSandbox.modules.find(
220+
currentSandboxModule =>
221+
currentSandboxModule.shortid === module.shortid
222+
).code,
223+
})),
224+
},
225225
};
226226
}
227227

packages/app/src/app/store/modules/git/actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ export function saveGithubData({ api, state, props }) {
6767
return api
6868
.post(`/sandboxes/${id}/git/repo/${name}`, props.githubData)
6969
.then(git => ({
70-
git: Object.assign({}, git, {
70+
git: {
71+
...git,
7172
commitSha: null,
72-
}),
73+
},
7374
}));
7475
}
7576

packages/app/src/app/store/modules/preferences/actions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export function changeKeybinding({ props, state }) {
3838
export function storeKeybindings({ state, settingsStore }) {
3939
const keybindings = state.get('preferences.settings.keybindings');
4040
const value = keybindings.reduce(
41-
(currentValue, binding) =>
42-
Object.assign(currentValue, {
43-
[binding.key]: binding.bindings,
44-
}),
41+
(currentValue, binding) => ({
42+
...currentValue,
43+
[binding.key]: binding.bindings,
44+
}),
4545
{}
4646
);
4747

packages/app/src/app/store/modules/preferences/getters.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import { KEYBINDINGS } from '@codesandbox/common/lib/utils/keybindings';
33
export function keybindings() {
44
const userBindings = this.settings.keybindings;
55
const userBindingsMap = userBindings.reduce(
6-
(bindings, binding) =>
7-
Object.assign(bindings, {
8-
[binding.key]: binding.bindings,
9-
}),
6+
(bindings, binding) => ({
7+
...bindings,
8+
[binding.key]: binding.bindings,
9+
}),
1010
{}
1111
);
1212

1313
return Object.keys(KEYBINDINGS).reduce(
14-
(currentBindings, key) =>
15-
Object.assign(currentBindings, {
16-
[key]: Object.assign(
17-
{},
18-
KEYBINDINGS[key],
19-
key in userBindingsMap ? { bindings: userBindingsMap[key] } : {}
20-
),
21-
}),
14+
(currentBindings, key) => ({
15+
...currentBindings,
16+
[key]: {
17+
...KEYBINDINGS[key],
18+
...(key in userBindingsMap ? { bindings: userBindingsMap[key] } : {}),
19+
},
20+
}),
2221
{}
2322
);
2423
}

packages/app/src/app/store/providers/Api.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,12 @@ export default Provider({
169169
},
170170
request(options) {
171171
return this.context.http
172-
.request(
173-
Object.assign(options, {
174-
url: API_ROOT + options.url,
175-
body: options.body ? camelizeKeys(options.body) : null,
176-
headers: createHeaders(this.context),
177-
})
178-
)
172+
.request({
173+
...options,
174+
url: API_ROOT + options.url,
175+
body: options.body ? camelizeKeys(options.body) : null,
176+
headers: createHeaders(this.context),
177+
})
179178
.then(response => handleResponse(response, options))
180179
.catch(e => handleError(e, this.context.controller));
181180
},

packages/app/src/app/store/providers/SettingsStore.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export default Provider({
3030
const value = this.get(allowedKeys[prop]);
3131

3232
if (value !== undefined) {
33-
return Object.assign(result, {
33+
return {
34+
...result,
3435
[prop]: value,
35-
});
36+
};
3637
}
3738

3839
return result;

packages/app/src/sandbox/eval/transpilers/vue/loader.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ export default function(content: string, loaderContext: LoaderContext) {
4747

4848
const { path, _module } = loaderContext;
4949
const query = loaderContext.options;
50-
const options = Object.assign(
51-
{
52-
esModule: false,
53-
},
54-
this.vue,
55-
query
56-
);
50+
const options = {
51+
esModule: false,
52+
...this.vue,
53+
...query,
54+
};
5755

5856
// disable esModule in inject mode
5957
// because import/export must be top-level
@@ -79,11 +77,8 @@ export default function(content: string, loaderContext: LoaderContext) {
7977
parts.template && parts.template.attrs && parts.template.attrs;
8078
const hasComment = templateAttrs && templateAttrs.comments;
8179
const functionalTemplate = templateAttrs && templateAttrs.functional;
82-
const bubleTemplateOptions = Object.assign({}, options.buble);
83-
bubleTemplateOptions.transforms = Object.assign(
84-
{},
85-
bubleTemplateOptions.transforms
86-
);
80+
const bubleTemplateOptions = { ...options.buble };
81+
bubleTemplateOptions.transforms = { ...bubleTemplateOptions.transforms };
8782
bubleTemplateOptions.transforms.stripWithFunctional = functionalTemplate;
8883

8984
const templateCompilerOptions =
@@ -125,7 +120,7 @@ export default function(content: string, loaderContext: LoaderContext) {
125120
coffee: ['babel-loader', 'coffee-loader'],
126121
};
127122

128-
const loaders = Object.assign({}, defaultLoaders, codeSandboxLoaders);
123+
const loaders = { ...defaultLoaders, ...codeSandboxLoaders };
129124
const preLoaders = {};
130125
const postLoaders = {};
131126

@@ -474,7 +469,7 @@ export default function(content: string, loaderContext: LoaderContext) {
474469
}
475470

476471
function buildCustomBlockLoaderString(attrs) {
477-
const noSrcAttrs = Object.assign({}, attrs);
472+
const noSrcAttrs = { ...attrs };
478473
delete noSrcAttrs.src;
479474
const qs = querystring.stringify(noSrcAttrs);
480475
return qs ? '?' + qs : qs;

packages/app/src/sandbox/eval/transpilers/vue/template-compiler/modules/transform-require.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var defaultOptions = {
88

99
export default (userOptions, loaderContext: LoaderContext) => {
1010
var options = userOptions
11-
? Object.assign({}, defaultOptions, userOptions)
11+
? { ...defaultOptions, userOptions }
1212
: defaultOptions;
1313

1414
return {

standalone-packages/monaco-typescript/src/lib/emmet/expand/extract-abbreviation.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,10 @@ function extractAbbreviation(line, pos, options) {
296296
// make sure `pos` is within line range
297297
pos = Math.min(line.length, Math.max(0, pos == null ? line.length : pos));
298298

299-
if (typeof options === 'boolean') {
300-
options = Object.assign(defaultOptions, { lookAhead: options });
301-
} else {
302-
options = Object.assign(defaultOptions, options);
303-
}
299+
options = {
300+
...defaultOptions,
301+
...(typeof options === 'boolean' ? { lookAhead: options } : options),
302+
};
304303

305304
if (options.lookAhead == null || options.lookAhead === true) {
306305
pos = offsetPastAutoClosed(line, pos, options);

0 commit comments

Comments
 (0)