Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit ea1dc3f

Browse files
committed
Replace Object.assign with the spread operator in reps.
1 parent 24858d7 commit ea1dc3f

File tree

10 files changed

+51
-33
lines changed

10 files changed

+51
-33
lines changed

packages/devtools-reps/src/reps/array.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ function arrayIterator(props, array, max) {
7878
let item;
7979

8080
try {
81-
item = ItemRep(Object.assign({}, props, config, {
81+
item = ItemRep({
82+
...props,
83+
...config,
8284
object: array[i],
83-
}));
85+
});
8486
} catch (exc) {
85-
item = ItemRep(Object.assign({}, props, config, {
87+
item = ItemRep({
88+
...props,
89+
...config,
8690
object: exc,
87-
}));
91+
});
8892
}
8993
items.push(item);
9094
}
@@ -118,10 +122,11 @@ function ItemRep(props) {
118122
} = props;
119123
return (
120124
span({},
121-
Rep(Object.assign({}, props, {
125+
Rep({
126+
...props,
122127
object: object,
123128
mode: mode
124-
})),
129+
}),
125130
delim
126131
)
127132
);

packages/devtools-reps/src/reps/event.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ Event.propTypes = {
2727
};
2828

2929
function Event(props) {
30-
// Use `Object.assign` to keep `props` without changes because:
31-
// 1. JSON.stringify/JSON.parse is slow.
32-
// 2. Immutable.js is planned for the future.
33-
let gripProps = Object.assign({}, props, {
34-
title: getTitle(props)
35-
});
36-
gripProps.object = Object.assign({}, props.object);
37-
gripProps.object.preview = Object.assign({}, props.object.preview);
30+
let gripProps = {
31+
...props,
32+
title: getTitle(props),
33+
object: {
34+
...props.object,
35+
preview: {
36+
...props.object.preview,
37+
ownProperties: {},
38+
},
39+
}
40+
};
3841

39-
gripProps.object.preview.ownProperties = {};
4042
if (gripProps.object.preview.target) {
4143
Object.assign(gripProps.object.preview.ownProperties, {
4244
target: gripProps.object.preview.target

packages/devtools-reps/src/reps/grip-array.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,13 @@ function arrayIterator(props, grip, max) {
203203
}
204204

205205
if (res.length < max) {
206-
res.push(Rep(Object.assign({}, props, {
206+
res.push(Rep({
207+
...props,
207208
object,
208209
mode: MODE.TINY,
209210
// Do not propagate title to array items reps
210211
title: undefined,
211-
})));
212+
}));
212213
}
213214

214215
return res;

packages/devtools-reps/src/reps/grip-map-entry.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ function GripMapEntry(props) {
3636

3737
return span({
3838
className: "objectBox objectBox-map-entry"
39-
}, PropRep(Object.assign({}, props, {
39+
}, PropRep({
40+
...props,
4041
name: key,
4142
object: value,
4243
equal: " \u2192 ",
4344
title: null,
4445
suppressQuotes: false,
45-
})));
46+
}));
4647
}
4748

4849
function supportsObject(grip, noGrip = false) {

packages/devtools-reps/src/reps/grip.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,16 @@ function propIterator(props, object, max) {
179179
const length = max - indexes.length;
180180

181181
const symbolsProps = ownSymbols.slice(0, length).map(symbolItem => {
182-
return PropRep(Object.assign({}, props, {
182+
return PropRep({
183+
...props,
183184
mode: MODE.TINY,
184185
name: symbolItem,
185186
object: symbolItem.descriptor.value,
186187
equal: ": ",
187188
defaultRep: Grip,
188189
title: null,
189190
suppressQuotes,
190-
}));
191+
});
191192
});
192193

193194
propsArray.push(...symbolsProps);
@@ -232,15 +233,16 @@ function getProps(componentProps, properties, indexes, suppressQuotes) {
232233
let name = propertiesKeys[i];
233234
let value = getPropValue(properties[name]);
234235

235-
return PropRep(Object.assign({}, componentProps, {
236+
return PropRep({
237+
...componentProps,
236238
mode: MODE.TINY,
237239
name,
238240
object: value,
239241
equal: ": ",
240242
defaultRep: Grip,
241243
title: null,
242244
suppressQuotes,
243-
}));
245+
});
244246
});
245247
}
246248

packages/devtools-reps/src/reps/object.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ function propIterator(props, object, max) {
9696
const propertiesNames = Object.keys(object);
9797

9898
const pushPropRep = (name, value) => {
99-
elements.push(PropRep(Object.assign({}, props, {
99+
elements.push(PropRep({
100+
...props,
100101
key: name,
101102
mode: MODE.TINY,
102103
name,
103104
object: value,
104105
equal: ": ",
105-
})));
106+
}));
106107
propertiesNumber++;
107108

108109
if (propertiesNumber < propertiesNames.length) {

packages/devtools-reps/src/reps/promise.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ function getProps(props, promiseState) {
8484

8585
return keys.reduce((res, key, i) => {
8686
let object = promiseState[key];
87-
res = res.concat(PropRep(Object.assign({}, props, {
87+
res = res.concat(PropRep({
88+
...props,
8889
mode: MODE.TINY,
8990
name: `<${key}>`,
9091
object,
9192
equal: ": ",
9293
suppressQuotes: true,
93-
})));
94+
}));
9495

9596
// Interleave commas between elements
9697
if (i !== keys.length - 1) {

packages/devtools-reps/src/reps/prop-rep.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,21 @@ function PropRep(props) {
6363
}
6464
key = span({"className": "nodeName"}, name);
6565
} else {
66-
key = Rep(Object.assign({}, props, {
66+
key = Rep({
67+
...props,
6768
className: "nodeName",
6869
object: name,
6970
mode: mode || MODE.TINY,
7071
defaultRep: Grip,
71-
}));
72+
});
7273
}
7374

7475
return [
7576
key,
7677
span({
7778
"className": "objectEqual"
7879
}, equal),
79-
Rep(Object.assign({}, props)),
80+
Rep({...props}),
8081
];
8182
}
8283

packages/devtools-reps/src/reps/stubs/grip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ stubs.set("testMoreThanMaxProps", {
7171
"preview": {
7272
"kind": "Object",
7373
"ownProperties": Array.from({length: longModeMaxLength})
74-
.reduce((res, item, index) => Object.assign(res, {
74+
.reduce((res, item, index) => ({
75+
...res,
7576
["p" + index]: {
7677
"configurable": true,
7778
"enumerable": true,

packages/devtools-reps/src/shared/images/Svg.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ function Svg(name, props) {
2626
if (name === "subSettings") {
2727
className = "";
2828
}
29-
props = Object.assign({}, props, { className, src: svg[name] });
30-
return React.createElement(InlineSVG, props);
29+
return React.createElement(InlineSVG, {
30+
...props,
31+
className,
32+
src: svg[name]
33+
});
3134
}
3235

3336
module.exports = Svg;

0 commit comments

Comments
 (0)