Use Object.assign instead of merge, mergeInto, mixInto and copyProperties
This makes it easier to contribute without having to learn a bunch of slightly different helpers and remember their slightly different signatures and semantics. We'll probably start using ES7 spread properties instead of merge in the future when at least one more transpiler supports it.
Sebastian Markbage committed
Oct 8, 2014 at 11:32 UTC
096360db0303f7582eae80331ee4a54762f3b022
34 files changed
+103
-158
src/addons/transitions/ReactCSSTransitionGroup.js
+1
-3
@@ -28,8 +28,6 @@ var ReactCSSTransitionGroupChild = React.createFactory(
28
require('ReactCSSTransitionGroupChild')
29
);
30
31
-var merge = require('merge');
32
-
31
var ReactCSSTransitionGroup = React.createClass({
32
displayName: 'ReactCSSTransitionGroup',
33
@@ -63,7 +61,7 @@ var ReactCSSTransitionGroup = React.createClass({
61
render: function() {
62
return (
63
ReactTransitionGroup(
66
- merge(this.props, {childFactory: this._wrapChild})
64
+ Object.assign({}, this.props, {childFactory: this._wrapChild})
65
)
66
);
67
}
src/addons/transitions/ReactTransitionGroup.js
+1
-2
@@ -23,7 +23,6 @@ var ReactTransitionChildMapping = require('ReactTransitionChildMapping');
23
24
var cloneWithProps = require('cloneWithProps');
25
var emptyFunction = require('emptyFunction');
26
-var merge = require('merge');
26
27
var ReactTransitionGroup = React.createClass({
28
displayName: 'ReactTransitionGroup',
@@ -159,7 +158,7 @@ var ReactTransitionGroup = React.createClass({
158
// This entered again before it fully left. Add it again.
159
this.performEnter(key);
160
} else {
162
- var newChildren = merge(this.state.children);
161
+ var newChildren = Object.assign({}, this.state.children);
162
delete newChildren[key];
163
this.setState({children: newChildren});
164
}
src/addons/update.js
+2
-3
@@ -18,7 +18,6 @@
18
19
"use strict";
20
21
-var copyProperties = require('copyProperties');
21
var keyOf = require('keyOf');
22
var invariant = require('invariant');
23
@@ -26,7 +25,7 @@ function shallowCopy(x) {
25
if (Array.isArray(x)) {
26
return x.concat();
27
} else if (x && typeof x === 'object') {
29
- return copyProperties(new x.constructor(), x);
28
+ return Object.assign(new x.constructor(), x);
29
} else {
30
return x;
31
}
@@ -106,7 +105,7 @@ function update(value, spec) {
105
COMMAND_MERGE,
106
nextValue
107
);
109
- copyProperties(nextValue, spec[COMMAND_MERGE]);
108
+ Object.assign(nextValue, spec[COMMAND_MERGE]);
109
}
110
111
if (spec.hasOwnProperty(COMMAND_PUSH)) {
src/browser/ReactBrowserEventEmitter.js
+1
-2
@@ -26,7 +26,6 @@ var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
26
var ViewportMetrics = require('ViewportMetrics');
27
28
var isEventSupported = require('isEventSupported');
29
-var merge = require('merge');
29
30
/**
31
* Summary of `ReactBrowserEventEmitter` event handling:
@@ -155,7 +154,7 @@ function getListeningForDocument(mountAt) {
154
*
155
* @internal
156
*/
158
-var ReactBrowserEventEmitter = merge(ReactEventEmitterMixin, {
157
+var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
158
159
/**
160
* Injectable event backend
src/browser/ReactPutListenerQueue.js
+1
-3
@@ -21,13 +21,11 @@
21
var PooledClass = require('PooledClass');
22
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
23
24
-var mixInto = require('mixInto');
25
-
24
function ReactPutListenerQueue() {
25
this.listenersToPut = [];
26
}
27
30
-mixInto(ReactPutListenerQueue, {
28
+Object.assign(ReactPutListenerQueue.prototype, {
29
enqueuePutListener: function(rootNodeID, propKey, propValue) {
30
this.listenersToPut.push({
31
rootNodeID: rootNodeID,
src/browser/ReactReconcileTransaction.js
+1
-4
@@ -26,8 +26,6 @@ var ReactInputSelection = require('ReactInputSelection');
26
var ReactPutListenerQueue = require('ReactPutListenerQueue');
27
var Transaction = require('Transaction');
28
29
-var mixInto = require('mixInto');
30
-
29
/**
30
* Ensures that, when possible, the selection range (currently selected text
31
* input) is not disturbed by performing the transaction.
@@ -174,8 +172,7 @@ var Mixin = {
172
};
173
174
177
-mixInto(ReactReconcileTransaction, Transaction.Mixin);
178
-mixInto(ReactReconcileTransaction, Mixin);
175
+Object.assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
176
177
PooledClass.addPoolingTo(ReactReconcileTransaction);
178
src/browser/ReactTextComponent.js
+1
-3
@@ -25,7 +25,6 @@ var ReactComponent = require('ReactComponent');
25
var ReactElement = require('ReactElement');
26
27
var escapeTextForBrowser = require('escapeTextForBrowser');
28
-var mixInto = require('mixInto');
28
29
/**
30
* Text nodes violate a couple assumptions that React makes about components:
@@ -46,8 +45,7 @@ var ReactTextComponent = function(props) {
45
// This constructor and it's argument is currently used by mocks.
46
};
47
49
-mixInto(ReactTextComponent, ReactComponent.Mixin);
50
-mixInto(ReactTextComponent, {
48
+Object.assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
49
50
/**
51
* Creates the markup for this text node. This node is not intended to have
src/browser/server/ReactServerRenderingTransaction.js
+5
-3
@@ -25,7 +25,6 @@ var ReactPutListenerQueue = require('ReactPutListenerQueue');
25
var Transaction = require('Transaction');
26
27
var emptyFunction = require('emptyFunction');
28
-var mixInto = require('mixInto');
28
29
/**
30
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks
@@ -107,8 +106,11 @@ var Mixin = {
106
};
107
108
110
-mixInto(ReactServerRenderingTransaction, Transaction.Mixin);
111
-mixInto(ReactServerRenderingTransaction, Mixin);
109
+Object.assign(
110
+ ReactServerRenderingTransaction.prototype,
111
+ Transaction.Mixin,
112
+ Mixin
113
+);
114
115
PooledClass.addPoolingTo(ReactServerRenderingTransaction);
116
src/browser/syntheticEvents/SyntheticEvent.js
+3
-5
@@ -23,8 +23,6 @@ var PooledClass = require('PooledClass');
23
24
var emptyFunction = require('emptyFunction');
25
var getEventTarget = require('getEventTarget');
26
-var merge = require('merge');
27
-var mergeInto = require('mergeInto');
26
27
/**
28
* @interface Event
@@ -91,7 +89,7 @@ function SyntheticEvent(dispatchConfig, dispatchMarker, nativeEvent) {
89
this.isPropagationStopped = emptyFunction.thatReturnsFalse;
90
}
91
94
-mergeInto(SyntheticEvent.prototype, {
92
+Object.assign(SyntheticEvent.prototype, {
93
94
preventDefault: function() {
95
this.defaultPrevented = true;
@@ -149,11 +147,11 @@ SyntheticEvent.augmentClass = function(Class, Interface) {
147
var Super = this;
148
149
var prototype = Object.create(Super.prototype);
152
- mergeInto(prototype, Class.prototype);
150
+ Object.assign(prototype, Class.prototype);
151
Class.prototype = prototype;
152
Class.prototype.constructor = Class;
153
156
- Class.Interface = merge(Super.Interface, Interface);
154
+ Class.Interface = Object.assign({}, Super.Interface, Interface);
155
Class.augmentClass = Super.augmentClass;
156
157
PooledClass.addPoolingTo(Class, PooledClass.threeArgumentPooler);
src/browser/ui/ReactDOMComponent.js
+9
-8
@@ -33,8 +33,6 @@ var escapeTextForBrowser = require('escapeTextForBrowser');
33
var invariant = require('invariant');
34
var isEventSupported = require('isEventSupported');
35
var keyOf = require('keyOf');
36
-var merge = require('merge');
37
-var mixInto = require('mixInto');
36
var monitorCodeUse = require('monitorCodeUse');
37
38
var deleteListener = ReactBrowserEventEmitter.deleteListener;
@@ -207,7 +205,7 @@ ReactDOMComponent.Mixin = {
205
} else {
206
if (propKey === STYLE) {
207
if (propValue) {
210
- propValue = props.style = merge(props.style);
208
+ propValue = props.style = Object.assign({}, props.style);
209
}
210
propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
211
}
@@ -356,7 +354,7 @@ ReactDOMComponent.Mixin = {
354
}
355
if (propKey === STYLE) {
356
if (nextProp) {
359
- nextProp = nextProps.style = merge(nextProp);
357
+ nextProp = nextProps.style = Object.assign({}, nextProp);
358
}
359
if (lastProp) {
360
// Unset styles on `lastProp` but not on `nextProp`.
@@ -465,9 +463,12 @@ ReactDOMComponent.Mixin = {
463
464
};
465
468
-mixInto(ReactDOMComponent, ReactComponent.Mixin);
469
-mixInto(ReactDOMComponent, ReactDOMComponent.Mixin);
470
-mixInto(ReactDOMComponent, ReactMultiChild.Mixin);
471
-mixInto(ReactDOMComponent, ReactBrowserComponentMixin);
466
+Object.assign(
467
+ ReactDOMComponent.prototype,
468
+ ReactComponent.Mixin,
469
+ ReactDOMComponent.Mixin,
470
+ ReactMultiChild.Mixin,
471
+ ReactBrowserComponentMixin
472
+);
473
474
module.exports = ReactDOMComponent;
src/browser/ui/ReactEventListener.js
+1
-2
@@ -28,7 +28,6 @@ var ReactUpdates = require('ReactUpdates');
28
29
var getEventTarget = require('getEventTarget');
30
var getUnboundedScrollPosition = require('getUnboundedScrollPosition');
31
-var mixInto = require('mixInto');
31
32
/**
33
* Finds the parent React component of `node`.
@@ -54,7 +53,7 @@ function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) {
53
this.nativeEvent = nativeEvent;
54
this.ancestors = [];
55
}
57
-mixInto(TopLevelCallbackBookKeeping, {
56
+Object.assign(TopLevelCallbackBookKeeping.prototype, {
57
destructor: function() {
58
this.topLevelType = null;
59
this.nativeEvent = null;
src/browser/ui/__tests__/ReactDOMComponent-test.js
+5
-8
@@ -224,7 +224,6 @@ describe('ReactDOMComponent', function() {
224
var ReactDefaultInjection = require('ReactDefaultInjection');
225
ReactDefaultInjection.inject();
226
227
- var mixInto = require('mixInto');
227
var ReactDOMComponent = require('ReactDOMComponent');
228
var ReactReconcileTransaction = require('ReactReconcileTransaction');
229
@@ -232,7 +231,7 @@ describe('ReactDOMComponent', function() {
231
this.props = initialProps || {};
232
this._rootNodeID = 'test';
233
};
235
- mixInto(NodeStub, ReactDOMComponent.Mixin);
234
+ Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
235
236
genMarkup = function(props) {
237
var transaction = new ReactReconcileTransaction();
@@ -275,7 +274,6 @@ describe('ReactDOMComponent', function() {
274
beforeEach(function() {
275
require('mock-modules').dumpCache();
276
278
- var mixInto = require('mixInto');
277
var ReactDOMComponent = require('ReactDOMComponent');
278
var ReactReconcileTransaction = require('ReactReconcileTransaction');
279
@@ -283,7 +281,7 @@ describe('ReactDOMComponent', function() {
281
this.props = initialProps || {};
282
this._rootNodeID = 'test';
283
};
286
- mixInto(NodeStub, ReactDOMComponent.Mixin);
284
+ Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
285
286
genMarkup = function(props) {
287
var transaction = new ReactReconcileTransaction();
@@ -312,7 +310,6 @@ describe('ReactDOMComponent', function() {
310
beforeEach(function() {
311
require('mock-modules').dumpCache();
312
315
- var mixInto = require('mixInto');
313
var ReactComponent = require('ReactComponent');
314
var ReactMultiChild = require('ReactMultiChild');
315
var ReactDOMComponent = require('ReactDOMComponent');
@@ -321,9 +318,9 @@ describe('ReactDOMComponent', function() {
318
var StubNativeComponent = function(element) {
319
ReactComponent.Mixin.construct.call(this, element);
320
};
324
- mixInto(StubNativeComponent, ReactComponent.Mixin);
325
- mixInto(StubNativeComponent, ReactDOMComponent.Mixin);
326
- mixInto(StubNativeComponent, ReactMultiChild.Mixin);
321
+ Object.assign(StubNativeComponent.prototype, ReactComponent.Mixin);
322
+ Object.assign(StubNativeComponent.prototype, ReactDOMComponent.Mixin);
323
+ Object.assign(StubNativeComponent.prototype, ReactMultiChild.Mixin);
324
325
mountComponent = function(props) {
326
var transaction = new ReactReconcileTransaction();
src/browser/ui/dom/components/ReactDOMInput.js
+1
-2
@@ -29,7 +29,6 @@ var ReactMount = require('ReactMount');
29
var ReactUpdates = require('ReactUpdates');
30
31
var invariant = require('invariant');
32
-var merge = require('merge');
32
33
// Store a reference to the <input> `ReactDOMComponent`. TODO: use string
34
var input = ReactElement.createFactory(ReactDOM.input.type);
@@ -74,7 +73,7 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
73
74
render: function() {
75
// Clone `this.props` so we don't mutate the input.
77
- var props = merge(this.props);
76
+ var props = Object.assign({}, this.props);
77
78
props.defaultChecked = null;
79
props.defaultValue = null;
src/browser/ui/dom/components/ReactDOMSelect.js
+1
-3
@@ -26,8 +26,6 @@ var ReactElement = require('ReactElement');
26
var ReactDOM = require('ReactDOM');
27
var ReactUpdates = require('ReactUpdates');
28
29
-var merge = require('merge');
30
-
29
// Store a reference to the <select> `ReactDOMComponent`. TODO: use string
30
var select = ReactElement.createFactory(ReactDOM.select.type);
31
@@ -138,7 +136,7 @@ var ReactDOMSelect = ReactCompositeComponent.createClass({
136
137
render: function() {
138
// Clone `this.props` so we don't mutate the input.
141
- var props = merge(this.props);
139
+ var props = Object.assign({}, this.props);
140
141
props.onChange = this._handleChange;
142
props.value = null;
src/browser/ui/dom/components/ReactDOMTextarea.js
+1
-2
@@ -28,7 +28,6 @@ var ReactDOM = require('ReactDOM');
28
var ReactUpdates = require('ReactUpdates');
29
30
var invariant = require('invariant');
31
-var merge = require('merge');
31
32
var warning = require('warning');
33
@@ -103,7 +102,7 @@ var ReactDOMTextarea = ReactCompositeComponent.createClass({
102
103
render: function() {
104
// Clone `this.props` so we don't mutate the input.
106
- var props = merge(this.props);
105
+ var props = Object.assign({}, this.props);
106
107
invariant(
108
props.dangerouslySetInnerHTML == null,
src/core/ReactComponent.js
+2
-3
@@ -24,7 +24,6 @@ var ReactUpdates = require('ReactUpdates');
24
25
var invariant = require('invariant');
26
var keyMirror = require('keyMirror');
27
-var merge = require('merge');
27
28
/**
29
* Every React component is in one of these life cycles.
@@ -151,7 +150,7 @@ var ReactComponent = {
150
// element props.
151
var element = this._pendingElement || this._currentElement;
152
this.replaceProps(
154
- merge(element.props, partialProps),
153
+ Object.assign({}, element.props, partialProps),
154
callback
155
);
156
},
@@ -200,7 +199,7 @@ var ReactComponent = {
199
var element = this._pendingElement || this._currentElement;
200
this._pendingElement = ReactElement.cloneAndReplaceProps(
201
element,
203
- merge(element.props, partialProps)
202
+ Object.assign({}, element.props, partialProps)
203
);
204
ReactUpdates.enqueueUpdate(this, callback);
205
},
src/core/ReactCompositeComponent.js
+22
-12
@@ -37,8 +37,6 @@ var instantiateReactComponent = require('instantiateReactComponent');
37
var invariant = require('invariant');
38
var keyMirror = require('keyMirror');
39
var keyOf = require('keyOf');
40
-var merge = require('merge');
41
-var mixInto = require('mixInto');
40
var monitorCodeUse = require('monitorCodeUse');
41
var mapObject = require('mapObject');
42
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
@@ -349,7 +347,8 @@ var RESERVED_SPEC_KEYS = {
347
childContextTypes,
348
ReactPropTypeLocations.childContext
349
);
352
- Constructor.childContextTypes = merge(
350
+ Constructor.childContextTypes = Object.assign(
351
+ {},
352
Constructor.childContextTypes,
353
childContextTypes
354
);
@@ -360,7 +359,11 @@ var RESERVED_SPEC_KEYS = {
359
contextTypes,
360
ReactPropTypeLocations.context
361
);
363
- Constructor.contextTypes = merge(Constructor.contextTypes, contextTypes);
362
+ Constructor.contextTypes = Object.assign(
363
+ {},
364
+ Constructor.contextTypes,
365
+ contextTypes
366
+ );
367
},
368
/**
369
* Special case getDefaultProps which should move into statics but requires
@@ -382,7 +385,11 @@ var RESERVED_SPEC_KEYS = {
385
propTypes,
386
ReactPropTypeLocations.prop
387
);
385
- Constructor.propTypes = merge(Constructor.propTypes, propTypes);
388
+ Constructor.propTypes = Object.assign(
389
+ {},
390
+ Constructor.propTypes,
391
+ propTypes
392
+ );
393
},
394
statics: function(Constructor, statics) {
395
mixStaticSpecIntoComponent(Constructor, statics);
@@ -462,7 +469,7 @@ function validateLifeCycleOnReplaceState(instance) {
469
}
470
471
/**
465
- * Custom version of `mixInto` which handles policy validation and reserved
472
+ * Mixin helper which handles policy validation and reserved
473
* specification keys when building `ReactCompositeComponent` classses.
474
*/
475
function mixSpecIntoComponent(Constructor, spec) {
@@ -866,7 +873,7 @@ var ReactCompositeComponentMixin = {
873
}
874
// Merge with `_pendingState` if it exists, otherwise with existing state.
875
this.replaceState(
869
- merge(this._pendingState || this.state, partialState),
876
+ Object.assign({}, this._pendingState || this.state, partialState),
877
callback
878
);
879
},
@@ -954,7 +961,7 @@ var ReactCompositeComponentMixin = {
961
name
962
);
963
}
957
- return merge(currentContext, childContext);
964
+ return Object.assign({}, currentContext, childContext);
965
}
966
return currentContext;
967
},
@@ -1332,10 +1339,13 @@ var ReactCompositeComponentMixin = {
1339
};
1340
1341
var ReactCompositeComponentBase = function() {};
1335
-mixInto(ReactCompositeComponentBase, ReactComponent.Mixin);
1336
-mixInto(ReactCompositeComponentBase, ReactOwner.Mixin);
1337
-mixInto(ReactCompositeComponentBase, ReactPropTransferer.Mixin);
1338
-mixInto(ReactCompositeComponentBase, ReactCompositeComponentMixin);
1342
+Object.assign(
1343
+ ReactCompositeComponentBase.prototype,
1344
+ ReactComponent.Mixin,
1345
+ ReactOwner.Mixin,
1346
+ ReactPropTransferer.Mixin,
1347
+ ReactCompositeComponentMixin
1348
+);
1349
1350
/**
1351
* Module for creating composite components.
src/core/ReactContext.js
+1
-3
@@ -18,8 +18,6 @@
18
19
"use strict";
20
21
-var merge = require('merge');
22
-
21
/**
22
* Keeps track of the current context.
23
*
@@ -53,7 +51,7 @@ var ReactContext = {
51
withContext: function(newContext, scopedCallback) {
52
var result;
53
var previousContext = ReactContext.current;
56
- ReactContext.current = merge(previousContext, newContext);
54
+ ReactContext.current = Object.assign({}, previousContext, newContext);
55
try {
56
result = scopedCallback();
57
} finally {
src/core/ReactDefaultBatchingStrategy.js
+8
-6
@@ -22,7 +22,6 @@ var ReactUpdates = require('ReactUpdates');
22
var Transaction = require('Transaction');
23
24
var emptyFunction = require('emptyFunction');
25
-var mixInto = require('mixInto');
25
26
var RESET_BATCHED_UPDATES = {
27
initialize: emptyFunction,
@@ -42,12 +41,15 @@ function ReactDefaultBatchingStrategyTransaction() {
41
this.reinitializeTransaction();
42
}
43
45
-mixInto(ReactDefaultBatchingStrategyTransaction, Transaction.Mixin);
46
-mixInto(ReactDefaultBatchingStrategyTransaction, {
47
- getTransactionWrappers: function() {
48
- return TRANSACTION_WRAPPERS;
44
+Object.assign(
45
+ ReactDefaultBatchingStrategyTransaction.prototype,
46
+ Transaction.Mixin,
47
+ {
48
+ getTransactionWrappers: function() {
49
+ return TRANSACTION_WRAPPERS;
50
+ }
51
}
50
-});
52
+);
53
54
var transaction = new ReactDefaultBatchingStrategyTransaction();
55
src/core/ReactLegacyElement.js
+1
-1
@@ -99,7 +99,7 @@ function proxyStaticMethods(target, source) {
99
if (typeof value === 'function') {
100
var bound = value.bind(source);
101
// Copy any properties defined on the function, such as `isRequired` on
102
- // a PropTypes validator. (mergeInto refuses to work on functions.)
102
+ // a PropTypes validator.
103
for (var k in value) {
104
if (value.hasOwnProperty(k)) {
105
bound[k] = value[k];
src/core/ReactNativeComponent.js
+1
-2
@@ -19,7 +19,6 @@
19
"use strict";
20
21
var invariant = require('invariant');
22
-var mergeInto = require('mergeInto');
22
23
var genericComponentClass = null;
24
// This registry keeps track of wrapper classes around native tags
@@ -34,7 +33,7 @@ var ReactNativeComponentInjection = {
33
// This accepts a keyed object with classes as values. Each key represents a
34
// tag. That particular tag will use this class instead of the generic one.
35
injectComponentClasses: function(componentClasses) {
37
- mergeInto(tagToComponentClass, componentClasses);
36
+ Object.assign(tagToComponentClass, componentClasses);
37
}
38
};
39
src/core/ReactPropTransferer.js
+2
-3
@@ -21,7 +21,6 @@
21
var emptyFunction = require('emptyFunction');
22
var invariant = require('invariant');
23
var joinClasses = require('joinClasses');
24
-var merge = require('merge');
24
var warning = require('warning');
25
26
var didWarn = false;
@@ -47,7 +46,7 @@ var transferStrategyMerge = createTransferStrategy(function(a, b) {
46
// `merge` overrides the first object's (`props[key]` above) keys using the
47
// second object's (`value`) keys. An object's style's existing `propA` would
48
// get overridden. Flip the order here.
50
- return merge(b, a);
49
+ return Object.assign({}, b, a);
50
});
51
52
/**
@@ -113,7 +112,7 @@ var ReactPropTransferer = {
112
* @return {object} a new object containing both sets of props merged.
113
*/
114
mergeProps: function(oldProps, newProps) {
116
- return transferInto(merge(oldProps), newProps);
115
+ return transferInto(Object.assign({}, oldProps), newProps);
116
},
117
118
/**
src/core/ReactUpdates.js
+3
-3
@@ -25,7 +25,6 @@ var ReactPerf = require('ReactPerf');
25
var Transaction = require('Transaction');
26
27
var invariant = require('invariant');
28
-var mixInto = require('mixInto');
28
var warning = require('warning');
29
30
var dirtyComponents = [];
@@ -80,8 +79,9 @@ function ReactUpdatesFlushTransaction() {
79
ReactUpdates.ReactReconcileTransaction.getPooled();
80
}
81
83
-mixInto(ReactUpdatesFlushTransaction, Transaction.Mixin);
84
-mixInto(ReactUpdatesFlushTransaction, {
82
+Object.assign(
83
+ ReactUpdatesFlushTransaction.prototype,
84
+ Transaction.Mixin, {
85
getTransactionWrappers: function() {
86
return TRANSACTION_WRAPPERS;
87
},
src/event/__tests__/EventPluginRegistry-test.js
+1
-3
@@ -18,8 +18,6 @@
18
19
"use strict";
20
21
-var merge = require('merge');
22
-
21
describe('EventPluginRegistry', function() {
22
var EventPluginRegistry;
23
var createPlugin;
@@ -29,7 +27,7 @@ describe('EventPluginRegistry', function() {
27
EventPluginRegistry._resetEventPlugins();
28
29
createPlugin = function(properties) {
32
- return merge({extractEvents: function() {}}, properties);
30
+ return Object.assign({extractEvents: function() {}}, properties);
31
};
32
});
33
src/test/ReactDefaultPerfAnalysis.js
+11
-5
@@ -16,8 +16,6 @@
16
* @providesModule ReactDefaultPerfAnalysis
17
*/
18
19
-var merge = require('merge');
20
-
19
// Don't try to save users less than 1.2ms (a number I made up)
20
var DONT_CARE_THRESHOLD = 1.2;
21
var DOM_OPERATION_TYPES = {
@@ -71,7 +69,11 @@ function getExclusiveSummary(measurements) {
69
70
for (var i = 0; i < measurements.length; i++) {
71
var measurement = measurements[i];
74
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
72
+ var allIDs = Object.assign(
73
+ {},
74
+ measurement.exclusive,
75
+ measurement.inclusive
76
+ );
77
78
for (var id in allIDs) {
79
displayName = measurement.displayNames[id].current;
@@ -119,7 +121,11 @@ function getInclusiveSummary(measurements, onlyClean) {
121
122
for (var i = 0; i < measurements.length; i++) {
123
var measurement = measurements[i];
122
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
124
+ var allIDs = Object.assign(
125
+ {},
126
+ measurement.exclusive,
127
+ measurement.inclusive
128
+ );
129
var cleanComponents;
130
131
if (onlyClean) {
@@ -174,7 +180,7 @@ function getUnchangedComponents(measurement) {
180
// the amount of time it took to render the entire subtree.
181
var cleanComponents = {};
182
var dirtyLeafIDs = Object.keys(measurement.writes);
177
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
183
+ var allIDs = Object.assign({}, measurement.exclusive, measurement.inclusive);
184
185
for (var id in allIDs) {
186
var isDirty = false;
src/test/ReactTestUtils.js
+2
-4
@@ -29,8 +29,6 @@ var ReactTextComponent = require('ReactTextComponent');
29
var ReactUpdates = require('ReactUpdates');
30
var SyntheticEvent = require('SyntheticEvent');
31
32
-var mergeInto = require('mergeInto');
33
-
32
var topLevelTypes = EventConstants.topLevelTypes;
33
34
function Event(suffix) {}
@@ -327,7 +325,7 @@ function makeSimulator(eventType) {
325
ReactMount.getID(node),
326
fakeNativeEvent
327
);
330
- mergeInto(event, eventData);
328
+ Object.assign(event, eventData);
329
EventPropagators.accumulateTwoPhaseDispatches(event);
330
331
ReactUpdates.batchedUpdates(function() {
@@ -383,7 +381,7 @@ buildSimulators();
381
function makeNativeSimulator(eventType) {
382
return function(domComponentOrNode, nativeEventData) {
383
var fakeNativeEvent = new Event(eventType);
386
- mergeInto(fakeNativeEvent, nativeEventData);
384
+ Object.assign(fakeNativeEvent, nativeEventData);
385
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
386
ReactTestUtils.simulateNativeEventOnDOMComponent(
387
eventType,
src/test/reactComponentExpect.js
+1
-3
@@ -21,8 +21,6 @@
21
22
var ReactTestUtils = require('ReactTestUtils');
23
24
-var mergeInto = require('mergeInto');
25
-
24
function reactComponentExpect(instance) {
25
if (instance instanceof reactComponentExpect) {
26
return instance;
@@ -38,7 +36,7 @@ function reactComponentExpect(instance) {
36
expect(ReactTestUtils.isElement(instance)).toBe(false);
37
}
38
41
-mergeInto(reactComponentExpect.prototype, {
39
+Object.assign(reactComponentExpect.prototype, {
40
// Getters -------------------------------------------------------------------
41
42
/**
src/utils/CallbackQueue.js
+1
-2
@@ -21,7 +21,6 @@
21
var PooledClass = require('PooledClass');
22
23
var invariant = require('invariant');
24
-var mixInto = require('mixInto');
24
25
/**
26
* A specialized pseudo-event module to help keep track of components waiting to
@@ -39,7 +38,7 @@ function CallbackQueue() {
38
this._contexts = null;
39
}
40
42
-mixInto(CallbackQueue, {
41
+Object.assign(CallbackQueue.prototype, {
42
43
/**
44
* Enqueues a callback to be invoked when `notifyAll` is invoked.
src/utils/LegacyImmutableObject.js
+4
-6
@@ -21,8 +21,6 @@
21
22
var invariant = require('invariant');
23
var isNode = require('isNode');
24
-var merge = require('merge');
25
-var mergeInto = require('mergeInto');
24
var mergeHelpers = require('mergeHelpers');
25
26
var checkMergeObjectArgs = mergeHelpers.checkMergeObjectArgs;
@@ -51,7 +49,7 @@ if (__DEV__) {
49
* @constructor
50
*/
51
LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
54
- mergeInto(this, initialProperties);
52
+ Object.assign(this, initialProperties);
53
deepFreeze(this);
54
};
55
@@ -100,7 +98,7 @@ if (__DEV__) {
98
*/
99
LegacyImmutableObject.set = function(immutableObject, put) {
100
assertLegacyImmutableObject(immutableObject);
103
- var totalNewFields = merge(immutableObject, put);
101
+ var totalNewFields = Object.assign({}, immutableObject, put);
102
return new LegacyImmutableObject(totalNewFields);
103
};
104
@@ -112,7 +110,7 @@ if (__DEV__) {
110
* @constructor
111
*/
112
LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
115
- mergeInto(this, initialProperties);
113
+ Object.assign(this, initialProperties);
114
};
115
116
/**
@@ -126,7 +124,7 @@ if (__DEV__) {
124
LegacyImmutableObject.set = function(immutableObject, put) {
125
assertLegacyImmutableObject(immutableObject);
126
var newMap = new LegacyImmutableObject(immutableObject);
129
- mergeInto(newMap, put);
127
+ Object.assign(newMap, put);
128
return newMap;
129
};
130
}
src/utils/OrderedMap.js
+1
-2
@@ -19,7 +19,6 @@
19
"use strict";
20
21
var invariant = require('invariant');
22
-var mixInto = require('mixInto');
22
23
var PREFIX = 'key:';
24
@@ -483,7 +482,7 @@ var OrderedMapMethods = {
482
}
483
};
484
486
-mixInto(OrderedMapImpl, OrderedMapMethods);
485
+Object.assign(OrderedMapImpl.prototype, OrderedMapMethods);
486
487
var OrderedMap = {
488
from: function(orderedMap) {
src/utils/__tests__/Transaction-test.js
+6
-8
@@ -19,14 +19,12 @@
19
"use strict";
20
21
var Transaction;
22
-var mixInto;
22
23
var INIT_ERRORED = 'initErrored'; // Just a dummy value to check for.
24
describe('Transaction', function() {
25
beforeEach(function() {
26
require('mock-modules').dumpCache();
27
Transaction = require('Transaction');
29
- mixInto = require('mixInto');
28
});
29
30
/**
@@ -53,7 +51,7 @@ describe('Transaction', function() {
51
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
52
this.lastCloseParam = INIT_ERRORED; // WON'T be set to something else
53
};
56
- mixInto(TestTransaction, Transaction.Mixin);
54
+ Object.assign(TestTransaction.prototype, Transaction.Mixin);
55
TestTransaction.prototype.getTransactionWrappers = function() {
56
return [
57
{
@@ -102,7 +100,7 @@ describe('Transaction', function() {
100
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
101
this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
102
};
105
- mixInto(TestTransaction, Transaction.Mixin);
103
+ Object.assign(TestTransaction.prototype, Transaction.Mixin);
104
TestTransaction.prototype.getTransactionWrappers = function() {
105
return [
106
{
@@ -163,7 +161,7 @@ describe('Transaction', function() {
161
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
162
this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
163
};
166
- mixInto(TestTransaction, Transaction.Mixin);
164
+ Object.assign(TestTransaction.prototype, Transaction.Mixin);
165
// Now, none of the close/inits throw, but the operation we wrap will throw.
166
TestTransaction.prototype.getTransactionWrappers = function() {
167
return [
@@ -227,7 +225,7 @@ describe('Transaction', function() {
225
var TestTransaction = function() {
226
this.reinitializeTransaction();
227
};
230
- mixInto(TestTransaction, Transaction.Mixin);
228
+ Object.assign(TestTransaction.prototype, Transaction.Mixin);
229
var exceptionMsg = 'This exception should throw.';
230
TestTransaction.prototype.getTransactionWrappers = function() {
231
return [
@@ -256,7 +254,7 @@ describe('Transaction', function() {
254
this.reinitializeTransaction();
255
this.firstCloseParam = INIT_ERRORED; // WILL be set to something else
256
};
259
- mixInto(TestTransaction, Transaction.Mixin);
257
+ Object.assign(TestTransaction.prototype, Transaction.Mixin);
258
TestTransaction.prototype.getTransactionWrappers = function() {
259
return [
260
{
@@ -284,7 +282,7 @@ describe('Transaction', function() {
282
var NestedTransaction = function() {
283
this.reinitializeTransaction();
284
};
287
- mixInto(NestedTransaction, Transaction.Mixin);
285
+ Object.assign(NestedTransaction.prototype, Transaction.Mixin);
286
NestedTransaction.prototype.getTransactionWrappers = function() {
287
return [{
288
initialize: function() {
src/utils/mixInto.js
deleted
-34
@@ -1,34 +0,0 @@
1
-/**
2
- * Copyright 2013-2014 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule mixInto
17
- */
18
-
19
-"use strict";
20
-
21
-/**
22
- * Simply copies properties to the prototype.
23
- */
24
-var mixInto = function(constructor, methodBag) {
25
- var methodName;
26
- for (methodName in methodBag) {
27
- if (!methodBag.hasOwnProperty(methodName)) {
28
- continue;
29
- }
30
- constructor.prototype[methodName] = methodBag[methodName];
31
- }
32
-};
33
-
34
-module.exports = mixInto;
src/vendor/core/emptyFunction.js
+1
-3
@@ -16,8 +16,6 @@
16
* @providesModule emptyFunction
17
*/
18
19
-var copyProperties = require('copyProperties');
20
-
19
function makeEmptyFunction(arg) {
20
return function() {
21
return arg;
@@ -31,7 +29,7 @@ function makeEmptyFunction(arg) {
29
*/
30
function emptyFunction() {}
31
34
-copyProperties(emptyFunction, {
32
+Object.assign(emptyFunction, {
33
thatReturns: makeEmptyFunction,
34
thatReturnsFalse: makeEmptyFunction(false),
35
thatReturnsTrue: makeEmptyFunction(true),
src/vendor/immutable/Immutable.js
+1
-2
@@ -19,7 +19,6 @@
19
var invariant = require('invariant');
20
var isNode = require('isNode');
21
var keyOf = require('keyOf');
22
-var mergeInto = require('mergeInto');
22
23
var SECRET_KEY = keyOf({_DONT_EVER_TYPE_THIS_SECRET_KEY: null});
24
@@ -67,7 +66,7 @@ class Immutable {
66
static mergeAllPropertiesInto(destination, propertyObjects) {
67
var argLength = propertyObjects.length;
68
for (var i = 0; i < argLength; i++) {
70
- mergeInto(destination, propertyObjects[i]);
69
+ Object.assign(destination, propertyObjects[i]);
70
}
71
}
72