Skip to content

Commit

Permalink
Use ... instead of Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Apr 29, 2020
1 parent 3a9cc2b commit 943f377
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 62 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,6 @@
"@ampproject/filesize": "^2.1.1",
"@ampproject/rollup-plugin-closure-compiler": "0.21.0",
"@babel/core": "^7.1.2",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.1.0",
"@babel/preset-modules": "^0.1.1",
Expand Down
66 changes: 28 additions & 38 deletions packages/history/index.ts
Expand Up @@ -407,23 +407,20 @@ export function createBrowserHistory({

if (index == null) {
index = 0;
globalHistory.replaceState(
Object.assign({}, globalHistory.state, { idx: index }),
''
);
globalHistory.replaceState({ ...globalHistory.state, idx: index }, '');
}

function createHref(to: To) {
return typeof to === 'string' ? to : createPath(to);
}

function getNextLocation(to: To, state: State | null = null): Location {
return readOnly(
Object.assign({}, location, typeof to === 'string' ? parsePath(to) : to, {
state,
key: createKey()
})
);
return readOnly({
...location,
...(typeof to === 'string' ? parsePath(to) : to),
state,
key: createKey()
});
}

function getHistoryStateAndUrl(
Expand Down Expand Up @@ -637,10 +634,7 @@ export function createHashHistory({

if (index == null) {
index = 0;
globalHistory.replaceState(
Object.assign({}, globalHistory.state, { idx: index }),
''
);
globalHistory.replaceState({ ...globalHistory.state, idx: index }, '');
}

function getBaseHref() {
Expand All @@ -661,12 +655,12 @@ export function createHashHistory({
}

function getNextLocation(to: To, state: State | null = null): Location {
return readOnly(
Object.assign({}, location, typeof to === 'string' ? parsePath(to) : to, {
state,
key: createKey()
})
);
return readOnly({
...location,
...(typeof to === 'string' ? parsePath(to) : to),
state,
key: createKey()
});
}

function getHistoryStateAndUrl(
Expand Down Expand Up @@ -816,18 +810,14 @@ export function createMemoryHistory({
initialIndex?: number;
} = {}): MemoryHistory {
let entries: Location[] = initialEntries.map(entry => {
let location = readOnly(
Object.assign(
{
pathname: '/',
search: '',
hash: '',
state: null,
key: createKey()
},
typeof entry === 'string' ? parsePath(entry) : entry
)
);
let location = readOnly({
pathname: '/',
search: '',
hash: '',
state: null,
key: createKey(),
...(typeof entry === 'string' ? parsePath(entry) : entry)
});

warning(
location.pathname.charAt(0) === '/',
Expand All @@ -850,12 +840,12 @@ export function createMemoryHistory({
}

function getNextLocation(to: To, state: State | null = null): Location {
return readOnly(
Object.assign({}, location, typeof to === 'string' ? parsePath(to) : to, {
state,
key: createKey()
})
);
return readOnly({
...location,
...(typeof to === 'string' ? parsePath(to) : to),
state,
key: createKey()
});
}

function allowTx(action: Action, location: Location, retry: () => void) {
Expand Down
2 changes: 1 addition & 1 deletion packages/history/package.json
@@ -1,8 +1,8 @@
{
"name": "history",
"version": "5.0.0-beta.8",
"author": "React Training <hello@reacttraining.com>",
"description": "Manage session history with JavaScript",
"author": "React Training <hello@reacttraining.com>",
"repository": "ReactTraining/history",
"license": "MIT",
"main": "main.js",
Expand Down
11 changes: 2 additions & 9 deletions scripts/builds/history.js
Expand Up @@ -33,7 +33,6 @@ const modules = [
presets: [['@babel/preset-env', { loose: true }]],
plugins: [
'babel-plugin-dev-expression',
'@babel/plugin-transform-object-assign',
['@babel/plugin-transform-runtime', { useESModules: true }]
],
runtimeHelpers: true
Expand Down Expand Up @@ -146,10 +145,7 @@ const globals = [
exclude: /node_modules/,
extensions: ['.ts'],
presets: [['@babel/preset-env', { loose: true }]],
plugins: [
'babel-plugin-dev-expression',
'@babel/plugin-transform-object-assign'
]
plugins: ['babel-plugin-dev-expression']
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
compiler()
Expand All @@ -169,10 +165,7 @@ const globals = [
exclude: /node_modules/,
extensions: ['.ts'],
presets: [['@babel/preset-env', { loose: true }]],
plugins: [
'babel-plugin-dev-expression',
'@babel/plugin-transform-object-assign'
]
plugins: ['babel-plugin-dev-expression']
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
compiler(),
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"lib": ["dom", "esnext"],
"module": "esnext",
"target": "es5",
"target": "es2018",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Expand Up @@ -213,11 +213,6 @@
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250"
integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==

"@babel/helper-plugin-utils@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670"
integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==

"@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351"
Expand Down Expand Up @@ -572,13 +567,6 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-object-assign@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-assign/-/plugin-transform-object-assign-7.8.3.tgz#dc3b8dd50ef03837868a37b7df791f64f288538e"
integrity sha512-i3LuN8tPDqUCRFu3dkzF2r1Nx0jp4scxtm7JxtIqI9he9Vk20YD+/zshdzR9JLsoBMlJlNR82a62vQExNEVx/Q==
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"

"@babel/plugin-transform-object-super@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.7.4.tgz#48488937a2d586c0148451bf51af9d7dda567262"
Expand Down

0 comments on commit 943f377

Please sign in to comment.