Skip to content

Commit

Permalink
Use spread operator instead of Object.assign call
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed May 20, 2019
1 parent fac7134 commit 4f28a4a
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 71 deletions.
13 changes: 6 additions & 7 deletions packages/app/src/app/overmind/effects/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ export default {
},
request(options) {
return this.context.http
.request(
Object.assign(options, {
url: API_ROOT + options.url,
body: options.body ? camelizeKeys(options.body) : null,
headers: createHeaders(this.context),
})
)
.request({
...options,
url: API_ROOT + options.url,
body: options.body ? camelizeKeys(options.body) : null,
headers: createHeaders(this.context),
})
.then(response => handleResponse(response, options))
.catch(e => handleError(e, this.context.controller));
},
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/app/overmind/effects/settingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export default {
const value = this.get(allowedKeys[prop]);

if (value !== undefined) {
return Object.assign(result, {
return {
...result,
[prop]: value,
});
};
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class KeyMapping extends React.Component {
const keybindings = this.props.store.preferences.settings.keybindings;

return keybindings.reduce(
(bindings, binding) =>
Object.assign(bindings, {
[binding.key]: binding.bindings,
}),
(bindings, binding) => ({
...bindings,
[binding.key]: binding.bindings,
}),
{}
);
};
Expand Down
20 changes: 10 additions & 10 deletions packages/app/src/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ export function moveModuleContent({ props, state }) {

if (currentSandbox) {
return {
sandbox: Object.assign({}, props.forkedSandbox, {
modules: props.forkedSandbox.modules.map(module =>
Object.assign(module, {
code: currentSandbox.modules.find(
currentSandboxModule =>
currentSandboxModule.shortid === module.shortid
).code,
})
),
}),
sandbox: {
...props.forkedSandbox,
modules: props.forkedSandbox.modules.map(module => ({
...module,
code: currentSandbox.modules.find(
currentSandboxModule =>
currentSandboxModule.shortid === module.shortid
).code,
})),
},
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/app/store/modules/git/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export function saveGithubData({ api, state, props }) {
return api
.post(`/sandboxes/${id}/git/repo/${name}`, props.githubData)
.then(git => ({
git: Object.assign({}, git, {
git: {
...git,
commitSha: null,
}),
},
}));
}

Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/app/store/modules/preferences/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export function changeKeybinding({ props, state }) {
export function storeKeybindings({ state, settingsStore }) {
const keybindings = state.get('preferences.settings.keybindings');
const value = keybindings.reduce(
(currentValue, binding) =>
Object.assign(currentValue, {
[binding.key]: binding.bindings,
}),
(currentValue, binding) => ({
...currentValue,
[binding.key]: binding.bindings,
}),
{}
);

Expand Down
23 changes: 11 additions & 12 deletions packages/app/src/app/store/modules/preferences/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ import { KEYBINDINGS } from '@codesandbox/common/lib/utils/keybindings';
export function keybindings() {
const userBindings = this.settings.keybindings;
const userBindingsMap = userBindings.reduce(
(bindings, binding) =>
Object.assign(bindings, {
[binding.key]: binding.bindings,
}),
(bindings, binding) => ({
...bindings,
[binding.key]: binding.bindings,
}),
{}
);

return Object.keys(KEYBINDINGS).reduce(
(currentBindings, key) =>
Object.assign(currentBindings, {
[key]: Object.assign(
{},
KEYBINDINGS[key],
key in userBindingsMap ? { bindings: userBindingsMap[key] } : {}
),
}),
(currentBindings, key) => ({
...currentBindings,
[key]: {
...KEYBINDINGS[key],
...(key in userBindingsMap ? { bindings: userBindingsMap[key] } : {}),
},
}),
{}
);
}
13 changes: 6 additions & 7 deletions packages/app/src/app/store/providers/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ export default Provider({
},
request(options) {
return this.context.http
.request(
Object.assign(options, {
url: API_ROOT + options.url,
body: options.body ? camelizeKeys(options.body) : null,
headers: createHeaders(this.context),
})
)
.request({
...options,
url: API_ROOT + options.url,
body: options.body ? camelizeKeys(options.body) : null,
headers: createHeaders(this.context),
})
.then(response => handleResponse(response, options))
.catch(e => handleError(e, this.context.controller));
},
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/app/store/providers/SettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export default Provider({
const value = this.get(allowedKeys[prop]);

if (value !== undefined) {
return Object.assign(result, {
return {
...result,
[prop]: value,
});
};
}

return result;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 9 additions & 14 deletions packages/app/src/sandbox/eval/transpilers/vue/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ export default function(content: string, loaderContext: LoaderContext) {

const { path, _module } = loaderContext;
const query = loaderContext.options;
const options = Object.assign(
{
esModule: false,
},
this.vue,
query
);
const options = {
esModule: false,
...this.vue,
...query,
};

// disable esModule in inject mode
// because import/export must be top-level
Expand All @@ -79,11 +77,8 @@ export default function(content: string, loaderContext: LoaderContext) {
parts.template && parts.template.attrs && parts.template.attrs;
const hasComment = templateAttrs && templateAttrs.comments;
const functionalTemplate = templateAttrs && templateAttrs.functional;
const bubleTemplateOptions = Object.assign({}, options.buble);
bubleTemplateOptions.transforms = Object.assign(
{},
bubleTemplateOptions.transforms
);
const bubleTemplateOptions = { ...options.buble };
bubleTemplateOptions.transforms = { ...bubleTemplateOptions.transforms };
bubleTemplateOptions.transforms.stripWithFunctional = functionalTemplate;

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

const loaders = Object.assign({}, defaultLoaders, codeSandboxLoaders);
const loaders = { ...defaultLoaders, ...codeSandboxLoaders };
const preLoaders = {};
const postLoaders = {};

Expand Down Expand Up @@ -474,7 +469,7 @@ export default function(content: string, loaderContext: LoaderContext) {
}

function buildCustomBlockLoaderString(attrs) {
const noSrcAttrs = Object.assign({}, attrs);
const noSrcAttrs = { ...attrs };
delete noSrcAttrs.src;
const qs = querystring.stringify(noSrcAttrs);
return qs ? '?' + qs : qs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var defaultOptions = {

export default (userOptions, loaderContext: LoaderContext) => {
var options = userOptions
? Object.assign({}, defaultOptions, userOptions)
? { ...defaultOptions, userOptions }
: defaultOptions;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,10 @@ function extractAbbreviation(line, pos, options) {
// make sure `pos` is within line range
pos = Math.min(line.length, Math.max(0, pos == null ? line.length : pos));

if (typeof options === 'boolean') {
options = Object.assign(defaultOptions, { lookAhead: options });
} else {
options = Object.assign(defaultOptions, options);
}
options = {
...defaultOptions,
...(typeof options === 'boolean' ? { lookAhead: options } : options),
};

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

0 comments on commit 4f28a4a

Please sign in to comment.