Skip to content

Commit a62542d

Browse files
committed
Leverage Object.assign
1 parent e2988ca commit a62542d

File tree

4 files changed

+6
-38
lines changed

4 files changed

+6
-38
lines changed

compat/src/util.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
/**
2-
* Assign properties from `props` to `obj`
3-
* @template O, P The obj and props types
4-
* @param {O} obj The object to copy properties to
5-
* @param {P} props The object to copy properties from
6-
* @returns {O & P}
7-
*/
8-
export function assign(obj, props) {
9-
for (let i in props) obj[i] = props[i];
10-
return /** @type {O & P} */ (obj);
11-
}
1+
export const assign = Object.assign;
122

133
/**
144
* Check if two objects have a different shape
@@ -29,5 +19,6 @@ export function shallowDiffers(a, b) {
2919
* @returns {boolean}
3020
*/
3121
export function is(x, y) {
22+
// TODO: can we replace this with Object.is?
3223
return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
3324
}

debug/src/util.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
/**
2-
* Assign properties from `props` to `obj`
3-
* @template O, P The obj and props types
4-
* @param {O} obj The object to copy properties to
5-
* @param {P} props The object to copy properties from
6-
* @returns {O & P}
7-
*/
8-
export function assign(obj, props) {
9-
for (let i in props) obj[i] = props[i];
10-
return /** @type {O & P} */ (obj);
11-
}
1+
export const assign = Object.assign;
122

133
export function isNaN(value) {
144
return value !== value;

src/diff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function diff(
233233
c.state = c._nextState;
234234

235235
if (c.getChildContext != null) {
236-
globalContext = assign(assign({}, globalContext), c.getChildContext());
236+
globalContext = assign({}, globalContext, c.getChildContext());
237237
}
238238

239239
if (isClassComponent && !isNew && c.getSnapshotBeforeUpdate != null) {

src/util.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import { EMPTY_ARR } from './constants';
22

33
export const isArray = Array.isArray;
4-
5-
/**
6-
* Assign properties from `props` to `obj`
7-
* @template O, P The obj and props types
8-
* @param {O} obj The object to copy properties to
9-
* @param {P} props The object to copy properties from
10-
* @returns {O & P}
11-
*/
12-
export function assign(obj, props) {
13-
// @ts-expect-error We change the type of `obj` to be `O & P`
14-
for (let i in props) obj[i] = props[i];
15-
return /** @type {O & P} */ (obj);
16-
}
4+
export const assign = Object.assign;
5+
export const slice = EMPTY_ARR.slice;
176

187
/**
198
* Remove a child node from its parent if attached. This is a workaround for
@@ -24,5 +13,3 @@ export function assign(obj, props) {
2413
export function removeNode(node) {
2514
if (node && node.parentNode) node.parentNode.removeChild(node);
2615
}
27-
28-
export const slice = EMPTY_ARR.slice;

0 commit comments

Comments
 (0)