mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
This commit is contained in:
@@ -28,8 +28,6 @@ var ReactCSSTransitionGroupChild = React.createFactory(
|
||||
require('ReactCSSTransitionGroupChild')
|
||||
);
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
var ReactCSSTransitionGroup = React.createClass({
|
||||
displayName: 'ReactCSSTransitionGroup',
|
||||
|
||||
@@ -63,7 +61,7 @@ var ReactCSSTransitionGroup = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
ReactTransitionGroup(
|
||||
merge(this.props, {childFactory: this._wrapChild})
|
||||
Object.assign({}, this.props, {childFactory: this._wrapChild})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ var ReactTransitionChildMapping = require('ReactTransitionChildMapping');
|
||||
|
||||
var cloneWithProps = require('cloneWithProps');
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var merge = require('merge');
|
||||
|
||||
var ReactTransitionGroup = React.createClass({
|
||||
displayName: 'ReactTransitionGroup',
|
||||
@@ -159,7 +158,7 @@ var ReactTransitionGroup = React.createClass({
|
||||
// This entered again before it fully left. Add it again.
|
||||
this.performEnter(key);
|
||||
} else {
|
||||
var newChildren = merge(this.state.children);
|
||||
var newChildren = Object.assign({}, this.state.children);
|
||||
delete newChildren[key];
|
||||
this.setState({children: newChildren});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var copyProperties = require('copyProperties');
|
||||
var keyOf = require('keyOf');
|
||||
var invariant = require('invariant');
|
||||
|
||||
@@ -26,7 +25,7 @@ function shallowCopy(x) {
|
||||
if (Array.isArray(x)) {
|
||||
return x.concat();
|
||||
} else if (x && typeof x === 'object') {
|
||||
return copyProperties(new x.constructor(), x);
|
||||
return Object.assign(new x.constructor(), x);
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
@@ -106,7 +105,7 @@ function update(value, spec) {
|
||||
COMMAND_MERGE,
|
||||
nextValue
|
||||
);
|
||||
copyProperties(nextValue, spec[COMMAND_MERGE]);
|
||||
Object.assign(nextValue, spec[COMMAND_MERGE]);
|
||||
}
|
||||
|
||||
if (spec.hasOwnProperty(COMMAND_PUSH)) {
|
||||
|
||||
@@ -26,7 +26,6 @@ var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
|
||||
var ViewportMetrics = require('ViewportMetrics');
|
||||
|
||||
var isEventSupported = require('isEventSupported');
|
||||
var merge = require('merge');
|
||||
|
||||
/**
|
||||
* Summary of `ReactBrowserEventEmitter` event handling:
|
||||
@@ -155,7 +154,7 @@ function getListeningForDocument(mountAt) {
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
var ReactBrowserEventEmitter = merge(ReactEventEmitterMixin, {
|
||||
var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
|
||||
|
||||
/**
|
||||
* Injectable event backend
|
||||
|
||||
@@ -21,13 +21,11 @@
|
||||
var PooledClass = require('PooledClass');
|
||||
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
|
||||
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
function ReactPutListenerQueue() {
|
||||
this.listenersToPut = [];
|
||||
}
|
||||
|
||||
mixInto(ReactPutListenerQueue, {
|
||||
Object.assign(ReactPutListenerQueue.prototype, {
|
||||
enqueuePutListener: function(rootNodeID, propKey, propValue) {
|
||||
this.listenersToPut.push({
|
||||
rootNodeID: rootNodeID,
|
||||
|
||||
@@ -26,8 +26,6 @@ var ReactInputSelection = require('ReactInputSelection');
|
||||
var ReactPutListenerQueue = require('ReactPutListenerQueue');
|
||||
var Transaction = require('Transaction');
|
||||
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
/**
|
||||
* Ensures that, when possible, the selection range (currently selected text
|
||||
* input) is not disturbed by performing the transaction.
|
||||
@@ -174,8 +172,7 @@ var Mixin = {
|
||||
};
|
||||
|
||||
|
||||
mixInto(ReactReconcileTransaction, Transaction.Mixin);
|
||||
mixInto(ReactReconcileTransaction, Mixin);
|
||||
Object.assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
|
||||
|
||||
PooledClass.addPoolingTo(ReactReconcileTransaction);
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ var ReactComponent = require('ReactComponent');
|
||||
var ReactElement = require('ReactElement');
|
||||
|
||||
var escapeTextForBrowser = require('escapeTextForBrowser');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
/**
|
||||
* Text nodes violate a couple assumptions that React makes about components:
|
||||
@@ -46,8 +45,7 @@ var ReactTextComponent = function(props) {
|
||||
// This constructor and it's argument is currently used by mocks.
|
||||
};
|
||||
|
||||
mixInto(ReactTextComponent, ReactComponent.Mixin);
|
||||
mixInto(ReactTextComponent, {
|
||||
Object.assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
|
||||
|
||||
/**
|
||||
* Creates the markup for this text node. This node is not intended to have
|
||||
|
||||
@@ -25,7 +25,6 @@ var ReactPutListenerQueue = require('ReactPutListenerQueue');
|
||||
var Transaction = require('Transaction');
|
||||
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
/**
|
||||
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks
|
||||
@@ -107,8 +106,11 @@ var Mixin = {
|
||||
};
|
||||
|
||||
|
||||
mixInto(ReactServerRenderingTransaction, Transaction.Mixin);
|
||||
mixInto(ReactServerRenderingTransaction, Mixin);
|
||||
Object.assign(
|
||||
ReactServerRenderingTransaction.prototype,
|
||||
Transaction.Mixin,
|
||||
Mixin
|
||||
);
|
||||
|
||||
PooledClass.addPoolingTo(ReactServerRenderingTransaction);
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ var PooledClass = require('PooledClass');
|
||||
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var getEventTarget = require('getEventTarget');
|
||||
var merge = require('merge');
|
||||
var mergeInto = require('mergeInto');
|
||||
|
||||
/**
|
||||
* @interface Event
|
||||
@@ -91,7 +89,7 @@ function SyntheticEvent(dispatchConfig, dispatchMarker, nativeEvent) {
|
||||
this.isPropagationStopped = emptyFunction.thatReturnsFalse;
|
||||
}
|
||||
|
||||
mergeInto(SyntheticEvent.prototype, {
|
||||
Object.assign(SyntheticEvent.prototype, {
|
||||
|
||||
preventDefault: function() {
|
||||
this.defaultPrevented = true;
|
||||
@@ -149,11 +147,11 @@ SyntheticEvent.augmentClass = function(Class, Interface) {
|
||||
var Super = this;
|
||||
|
||||
var prototype = Object.create(Super.prototype);
|
||||
mergeInto(prototype, Class.prototype);
|
||||
Object.assign(prototype, Class.prototype);
|
||||
Class.prototype = prototype;
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
Class.Interface = merge(Super.Interface, Interface);
|
||||
Class.Interface = Object.assign({}, Super.Interface, Interface);
|
||||
Class.augmentClass = Super.augmentClass;
|
||||
|
||||
PooledClass.addPoolingTo(Class, PooledClass.threeArgumentPooler);
|
||||
|
||||
@@ -33,8 +33,6 @@ var escapeTextForBrowser = require('escapeTextForBrowser');
|
||||
var invariant = require('invariant');
|
||||
var isEventSupported = require('isEventSupported');
|
||||
var keyOf = require('keyOf');
|
||||
var merge = require('merge');
|
||||
var mixInto = require('mixInto');
|
||||
var monitorCodeUse = require('monitorCodeUse');
|
||||
|
||||
var deleteListener = ReactBrowserEventEmitter.deleteListener;
|
||||
@@ -207,7 +205,7 @@ ReactDOMComponent.Mixin = {
|
||||
} else {
|
||||
if (propKey === STYLE) {
|
||||
if (propValue) {
|
||||
propValue = props.style = merge(props.style);
|
||||
propValue = props.style = Object.assign({}, props.style);
|
||||
}
|
||||
propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
|
||||
}
|
||||
@@ -356,7 +354,7 @@ ReactDOMComponent.Mixin = {
|
||||
}
|
||||
if (propKey === STYLE) {
|
||||
if (nextProp) {
|
||||
nextProp = nextProps.style = merge(nextProp);
|
||||
nextProp = nextProps.style = Object.assign({}, nextProp);
|
||||
}
|
||||
if (lastProp) {
|
||||
// Unset styles on `lastProp` but not on `nextProp`.
|
||||
@@ -465,9 +463,12 @@ ReactDOMComponent.Mixin = {
|
||||
|
||||
};
|
||||
|
||||
mixInto(ReactDOMComponent, ReactComponent.Mixin);
|
||||
mixInto(ReactDOMComponent, ReactDOMComponent.Mixin);
|
||||
mixInto(ReactDOMComponent, ReactMultiChild.Mixin);
|
||||
mixInto(ReactDOMComponent, ReactBrowserComponentMixin);
|
||||
Object.assign(
|
||||
ReactDOMComponent.prototype,
|
||||
ReactComponent.Mixin,
|
||||
ReactDOMComponent.Mixin,
|
||||
ReactMultiChild.Mixin,
|
||||
ReactBrowserComponentMixin
|
||||
);
|
||||
|
||||
module.exports = ReactDOMComponent;
|
||||
|
||||
@@ -28,7 +28,6 @@ var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var getEventTarget = require('getEventTarget');
|
||||
var getUnboundedScrollPosition = require('getUnboundedScrollPosition');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
/**
|
||||
* Finds the parent React component of `node`.
|
||||
@@ -54,7 +53,7 @@ function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) {
|
||||
this.nativeEvent = nativeEvent;
|
||||
this.ancestors = [];
|
||||
}
|
||||
mixInto(TopLevelCallbackBookKeeping, {
|
||||
Object.assign(TopLevelCallbackBookKeeping.prototype, {
|
||||
destructor: function() {
|
||||
this.topLevelType = null;
|
||||
this.nativeEvent = null;
|
||||
|
||||
@@ -224,7 +224,6 @@ describe('ReactDOMComponent', function() {
|
||||
var ReactDefaultInjection = require('ReactDefaultInjection');
|
||||
ReactDefaultInjection.inject();
|
||||
|
||||
var mixInto = require('mixInto');
|
||||
var ReactDOMComponent = require('ReactDOMComponent');
|
||||
var ReactReconcileTransaction = require('ReactReconcileTransaction');
|
||||
|
||||
@@ -232,7 +231,7 @@ describe('ReactDOMComponent', function() {
|
||||
this.props = initialProps || {};
|
||||
this._rootNodeID = 'test';
|
||||
};
|
||||
mixInto(NodeStub, ReactDOMComponent.Mixin);
|
||||
Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
|
||||
|
||||
genMarkup = function(props) {
|
||||
var transaction = new ReactReconcileTransaction();
|
||||
@@ -275,7 +274,6 @@ describe('ReactDOMComponent', function() {
|
||||
beforeEach(function() {
|
||||
require('mock-modules').dumpCache();
|
||||
|
||||
var mixInto = require('mixInto');
|
||||
var ReactDOMComponent = require('ReactDOMComponent');
|
||||
var ReactReconcileTransaction = require('ReactReconcileTransaction');
|
||||
|
||||
@@ -283,7 +281,7 @@ describe('ReactDOMComponent', function() {
|
||||
this.props = initialProps || {};
|
||||
this._rootNodeID = 'test';
|
||||
};
|
||||
mixInto(NodeStub, ReactDOMComponent.Mixin);
|
||||
Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
|
||||
|
||||
genMarkup = function(props) {
|
||||
var transaction = new ReactReconcileTransaction();
|
||||
@@ -312,7 +310,6 @@ describe('ReactDOMComponent', function() {
|
||||
beforeEach(function() {
|
||||
require('mock-modules').dumpCache();
|
||||
|
||||
var mixInto = require('mixInto');
|
||||
var ReactComponent = require('ReactComponent');
|
||||
var ReactMultiChild = require('ReactMultiChild');
|
||||
var ReactDOMComponent = require('ReactDOMComponent');
|
||||
@@ -321,9 +318,9 @@ describe('ReactDOMComponent', function() {
|
||||
var StubNativeComponent = function(element) {
|
||||
ReactComponent.Mixin.construct.call(this, element);
|
||||
};
|
||||
mixInto(StubNativeComponent, ReactComponent.Mixin);
|
||||
mixInto(StubNativeComponent, ReactDOMComponent.Mixin);
|
||||
mixInto(StubNativeComponent, ReactMultiChild.Mixin);
|
||||
Object.assign(StubNativeComponent.prototype, ReactComponent.Mixin);
|
||||
Object.assign(StubNativeComponent.prototype, ReactDOMComponent.Mixin);
|
||||
Object.assign(StubNativeComponent.prototype, ReactMultiChild.Mixin);
|
||||
|
||||
mountComponent = function(props) {
|
||||
var transaction = new ReactReconcileTransaction();
|
||||
|
||||
@@ -29,7 +29,6 @@ var ReactMount = require('ReactMount');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var merge = require('merge');
|
||||
|
||||
// Store a reference to the <input> `ReactDOMComponent`. TODO: use string
|
||||
var input = ReactElement.createFactory(ReactDOM.input.type);
|
||||
@@ -74,7 +73,7 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
|
||||
|
||||
render: function() {
|
||||
// Clone `this.props` so we don't mutate the input.
|
||||
var props = merge(this.props);
|
||||
var props = Object.assign({}, this.props);
|
||||
|
||||
props.defaultChecked = null;
|
||||
props.defaultValue = null;
|
||||
|
||||
@@ -26,8 +26,6 @@ var ReactElement = require('ReactElement');
|
||||
var ReactDOM = require('ReactDOM');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
// Store a reference to the <select> `ReactDOMComponent`. TODO: use string
|
||||
var select = ReactElement.createFactory(ReactDOM.select.type);
|
||||
|
||||
@@ -138,7 +136,7 @@ var ReactDOMSelect = ReactCompositeComponent.createClass({
|
||||
|
||||
render: function() {
|
||||
// Clone `this.props` so we don't mutate the input.
|
||||
var props = merge(this.props);
|
||||
var props = Object.assign({}, this.props);
|
||||
|
||||
props.onChange = this._handleChange;
|
||||
props.value = null;
|
||||
|
||||
@@ -28,7 +28,6 @@ var ReactDOM = require('ReactDOM');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var merge = require('merge');
|
||||
|
||||
var warning = require('warning');
|
||||
|
||||
@@ -103,7 +102,7 @@ var ReactDOMTextarea = ReactCompositeComponent.createClass({
|
||||
|
||||
render: function() {
|
||||
// Clone `this.props` so we don't mutate the input.
|
||||
var props = merge(this.props);
|
||||
var props = Object.assign({}, this.props);
|
||||
|
||||
invariant(
|
||||
props.dangerouslySetInnerHTML == null,
|
||||
|
||||
@@ -24,7 +24,6 @@ var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var keyMirror = require('keyMirror');
|
||||
var merge = require('merge');
|
||||
|
||||
/**
|
||||
* Every React component is in one of these life cycles.
|
||||
@@ -151,7 +150,7 @@ var ReactComponent = {
|
||||
// element props.
|
||||
var element = this._pendingElement || this._currentElement;
|
||||
this.replaceProps(
|
||||
merge(element.props, partialProps),
|
||||
Object.assign({}, element.props, partialProps),
|
||||
callback
|
||||
);
|
||||
},
|
||||
@@ -200,7 +199,7 @@ var ReactComponent = {
|
||||
var element = this._pendingElement || this._currentElement;
|
||||
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
||||
element,
|
||||
merge(element.props, partialProps)
|
||||
Object.assign({}, element.props, partialProps)
|
||||
);
|
||||
ReactUpdates.enqueueUpdate(this, callback);
|
||||
},
|
||||
|
||||
@@ -37,8 +37,6 @@ var instantiateReactComponent = require('instantiateReactComponent');
|
||||
var invariant = require('invariant');
|
||||
var keyMirror = require('keyMirror');
|
||||
var keyOf = require('keyOf');
|
||||
var merge = require('merge');
|
||||
var mixInto = require('mixInto');
|
||||
var monitorCodeUse = require('monitorCodeUse');
|
||||
var mapObject = require('mapObject');
|
||||
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
|
||||
@@ -349,7 +347,8 @@ var RESERVED_SPEC_KEYS = {
|
||||
childContextTypes,
|
||||
ReactPropTypeLocations.childContext
|
||||
);
|
||||
Constructor.childContextTypes = merge(
|
||||
Constructor.childContextTypes = Object.assign(
|
||||
{},
|
||||
Constructor.childContextTypes,
|
||||
childContextTypes
|
||||
);
|
||||
@@ -360,7 +359,11 @@ var RESERVED_SPEC_KEYS = {
|
||||
contextTypes,
|
||||
ReactPropTypeLocations.context
|
||||
);
|
||||
Constructor.contextTypes = merge(Constructor.contextTypes, contextTypes);
|
||||
Constructor.contextTypes = Object.assign(
|
||||
{},
|
||||
Constructor.contextTypes,
|
||||
contextTypes
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Special case getDefaultProps which should move into statics but requires
|
||||
@@ -382,7 +385,11 @@ var RESERVED_SPEC_KEYS = {
|
||||
propTypes,
|
||||
ReactPropTypeLocations.prop
|
||||
);
|
||||
Constructor.propTypes = merge(Constructor.propTypes, propTypes);
|
||||
Constructor.propTypes = Object.assign(
|
||||
{},
|
||||
Constructor.propTypes,
|
||||
propTypes
|
||||
);
|
||||
},
|
||||
statics: function(Constructor, statics) {
|
||||
mixStaticSpecIntoComponent(Constructor, statics);
|
||||
@@ -462,7 +469,7 @@ function validateLifeCycleOnReplaceState(instance) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom version of `mixInto` which handles policy validation and reserved
|
||||
* Mixin helper which handles policy validation and reserved
|
||||
* specification keys when building `ReactCompositeComponent` classses.
|
||||
*/
|
||||
function mixSpecIntoComponent(Constructor, spec) {
|
||||
@@ -866,7 +873,7 @@ var ReactCompositeComponentMixin = {
|
||||
}
|
||||
// Merge with `_pendingState` if it exists, otherwise with existing state.
|
||||
this.replaceState(
|
||||
merge(this._pendingState || this.state, partialState),
|
||||
Object.assign({}, this._pendingState || this.state, partialState),
|
||||
callback
|
||||
);
|
||||
},
|
||||
@@ -954,7 +961,7 @@ var ReactCompositeComponentMixin = {
|
||||
name
|
||||
);
|
||||
}
|
||||
return merge(currentContext, childContext);
|
||||
return Object.assign({}, currentContext, childContext);
|
||||
}
|
||||
return currentContext;
|
||||
},
|
||||
@@ -1332,10 +1339,13 @@ var ReactCompositeComponentMixin = {
|
||||
};
|
||||
|
||||
var ReactCompositeComponentBase = function() {};
|
||||
mixInto(ReactCompositeComponentBase, ReactComponent.Mixin);
|
||||
mixInto(ReactCompositeComponentBase, ReactOwner.Mixin);
|
||||
mixInto(ReactCompositeComponentBase, ReactPropTransferer.Mixin);
|
||||
mixInto(ReactCompositeComponentBase, ReactCompositeComponentMixin);
|
||||
Object.assign(
|
||||
ReactCompositeComponentBase.prototype,
|
||||
ReactComponent.Mixin,
|
||||
ReactOwner.Mixin,
|
||||
ReactPropTransferer.Mixin,
|
||||
ReactCompositeComponentMixin
|
||||
);
|
||||
|
||||
/**
|
||||
* Module for creating composite components.
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
/**
|
||||
* Keeps track of the current context.
|
||||
*
|
||||
@@ -53,7 +51,7 @@ var ReactContext = {
|
||||
withContext: function(newContext, scopedCallback) {
|
||||
var result;
|
||||
var previousContext = ReactContext.current;
|
||||
ReactContext.current = merge(previousContext, newContext);
|
||||
ReactContext.current = Object.assign({}, previousContext, newContext);
|
||||
try {
|
||||
result = scopedCallback();
|
||||
} finally {
|
||||
|
||||
@@ -22,7 +22,6 @@ var ReactUpdates = require('ReactUpdates');
|
||||
var Transaction = require('Transaction');
|
||||
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
var RESET_BATCHED_UPDATES = {
|
||||
initialize: emptyFunction,
|
||||
@@ -42,12 +41,15 @@ function ReactDefaultBatchingStrategyTransaction() {
|
||||
this.reinitializeTransaction();
|
||||
}
|
||||
|
||||
mixInto(ReactDefaultBatchingStrategyTransaction, Transaction.Mixin);
|
||||
mixInto(ReactDefaultBatchingStrategyTransaction, {
|
||||
getTransactionWrappers: function() {
|
||||
return TRANSACTION_WRAPPERS;
|
||||
Object.assign(
|
||||
ReactDefaultBatchingStrategyTransaction.prototype,
|
||||
Transaction.Mixin,
|
||||
{
|
||||
getTransactionWrappers: function() {
|
||||
return TRANSACTION_WRAPPERS;
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
var transaction = new ReactDefaultBatchingStrategyTransaction();
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ function proxyStaticMethods(target, source) {
|
||||
if (typeof value === 'function') {
|
||||
var bound = value.bind(source);
|
||||
// Copy any properties defined on the function, such as `isRequired` on
|
||||
// a PropTypes validator. (mergeInto refuses to work on functions.)
|
||||
// a PropTypes validator.
|
||||
for (var k in value) {
|
||||
if (value.hasOwnProperty(k)) {
|
||||
bound[k] = value[k];
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
"use strict";
|
||||
|
||||
var invariant = require('invariant');
|
||||
var mergeInto = require('mergeInto');
|
||||
|
||||
var genericComponentClass = null;
|
||||
// This registry keeps track of wrapper classes around native tags
|
||||
@@ -34,7 +33,7 @@ var ReactNativeComponentInjection = {
|
||||
// This accepts a keyed object with classes as values. Each key represents a
|
||||
// tag. That particular tag will use this class instead of the generic one.
|
||||
injectComponentClasses: function(componentClasses) {
|
||||
mergeInto(tagToComponentClass, componentClasses);
|
||||
Object.assign(tagToComponentClass, componentClasses);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var invariant = require('invariant');
|
||||
var joinClasses = require('joinClasses');
|
||||
var merge = require('merge');
|
||||
var warning = require('warning');
|
||||
|
||||
var didWarn = false;
|
||||
@@ -47,7 +46,7 @@ var transferStrategyMerge = createTransferStrategy(function(a, b) {
|
||||
// `merge` overrides the first object's (`props[key]` above) keys using the
|
||||
// second object's (`value`) keys. An object's style's existing `propA` would
|
||||
// get overridden. Flip the order here.
|
||||
return merge(b, a);
|
||||
return Object.assign({}, b, a);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -113,7 +112,7 @@ var ReactPropTransferer = {
|
||||
* @return {object} a new object containing both sets of props merged.
|
||||
*/
|
||||
mergeProps: function(oldProps, newProps) {
|
||||
return transferInto(merge(oldProps), newProps);
|
||||
return transferInto(Object.assign({}, oldProps), newProps);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@ var ReactPerf = require('ReactPerf');
|
||||
var Transaction = require('Transaction');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var mixInto = require('mixInto');
|
||||
var warning = require('warning');
|
||||
|
||||
var dirtyComponents = [];
|
||||
@@ -80,8 +79,9 @@ function ReactUpdatesFlushTransaction() {
|
||||
ReactUpdates.ReactReconcileTransaction.getPooled();
|
||||
}
|
||||
|
||||
mixInto(ReactUpdatesFlushTransaction, Transaction.Mixin);
|
||||
mixInto(ReactUpdatesFlushTransaction, {
|
||||
Object.assign(
|
||||
ReactUpdatesFlushTransaction.prototype,
|
||||
Transaction.Mixin, {
|
||||
getTransactionWrappers: function() {
|
||||
return TRANSACTION_WRAPPERS;
|
||||
},
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
describe('EventPluginRegistry', function() {
|
||||
var EventPluginRegistry;
|
||||
var createPlugin;
|
||||
@@ -29,7 +27,7 @@ describe('EventPluginRegistry', function() {
|
||||
EventPluginRegistry._resetEventPlugins();
|
||||
|
||||
createPlugin = function(properties) {
|
||||
return merge({extractEvents: function() {}}, properties);
|
||||
return Object.assign({extractEvents: function() {}}, properties);
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
* @providesModule ReactDefaultPerfAnalysis
|
||||
*/
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
// Don't try to save users less than 1.2ms (a number I made up)
|
||||
var DONT_CARE_THRESHOLD = 1.2;
|
||||
var DOM_OPERATION_TYPES = {
|
||||
@@ -71,7 +69,11 @@ function getExclusiveSummary(measurements) {
|
||||
|
||||
for (var i = 0; i < measurements.length; i++) {
|
||||
var measurement = measurements[i];
|
||||
var allIDs = merge(measurement.exclusive, measurement.inclusive);
|
||||
var allIDs = Object.assign(
|
||||
{},
|
||||
measurement.exclusive,
|
||||
measurement.inclusive
|
||||
);
|
||||
|
||||
for (var id in allIDs) {
|
||||
displayName = measurement.displayNames[id].current;
|
||||
@@ -119,7 +121,11 @@ function getInclusiveSummary(measurements, onlyClean) {
|
||||
|
||||
for (var i = 0; i < measurements.length; i++) {
|
||||
var measurement = measurements[i];
|
||||
var allIDs = merge(measurement.exclusive, measurement.inclusive);
|
||||
var allIDs = Object.assign(
|
||||
{},
|
||||
measurement.exclusive,
|
||||
measurement.inclusive
|
||||
);
|
||||
var cleanComponents;
|
||||
|
||||
if (onlyClean) {
|
||||
@@ -174,7 +180,7 @@ function getUnchangedComponents(measurement) {
|
||||
// the amount of time it took to render the entire subtree.
|
||||
var cleanComponents = {};
|
||||
var dirtyLeafIDs = Object.keys(measurement.writes);
|
||||
var allIDs = merge(measurement.exclusive, measurement.inclusive);
|
||||
var allIDs = Object.assign({}, measurement.exclusive, measurement.inclusive);
|
||||
|
||||
for (var id in allIDs) {
|
||||
var isDirty = false;
|
||||
|
||||
@@ -29,8 +29,6 @@ var ReactTextComponent = require('ReactTextComponent');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
var SyntheticEvent = require('SyntheticEvent');
|
||||
|
||||
var mergeInto = require('mergeInto');
|
||||
|
||||
var topLevelTypes = EventConstants.topLevelTypes;
|
||||
|
||||
function Event(suffix) {}
|
||||
@@ -327,7 +325,7 @@ function makeSimulator(eventType) {
|
||||
ReactMount.getID(node),
|
||||
fakeNativeEvent
|
||||
);
|
||||
mergeInto(event, eventData);
|
||||
Object.assign(event, eventData);
|
||||
EventPropagators.accumulateTwoPhaseDispatches(event);
|
||||
|
||||
ReactUpdates.batchedUpdates(function() {
|
||||
@@ -383,7 +381,7 @@ buildSimulators();
|
||||
function makeNativeSimulator(eventType) {
|
||||
return function(domComponentOrNode, nativeEventData) {
|
||||
var fakeNativeEvent = new Event(eventType);
|
||||
mergeInto(fakeNativeEvent, nativeEventData);
|
||||
Object.assign(fakeNativeEvent, nativeEventData);
|
||||
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
||||
ReactTestUtils.simulateNativeEventOnDOMComponent(
|
||||
eventType,
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
var mergeInto = require('mergeInto');
|
||||
|
||||
function reactComponentExpect(instance) {
|
||||
if (instance instanceof reactComponentExpect) {
|
||||
return instance;
|
||||
@@ -38,7 +36,7 @@ function reactComponentExpect(instance) {
|
||||
expect(ReactTestUtils.isElement(instance)).toBe(false);
|
||||
}
|
||||
|
||||
mergeInto(reactComponentExpect.prototype, {
|
||||
Object.assign(reactComponentExpect.prototype, {
|
||||
// Getters -------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
var PooledClass = require('PooledClass');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
/**
|
||||
* A specialized pseudo-event module to help keep track of components waiting to
|
||||
@@ -39,7 +38,7 @@ function CallbackQueue() {
|
||||
this._contexts = null;
|
||||
}
|
||||
|
||||
mixInto(CallbackQueue, {
|
||||
Object.assign(CallbackQueue.prototype, {
|
||||
|
||||
/**
|
||||
* Enqueues a callback to be invoked when `notifyAll` is invoked.
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
var invariant = require('invariant');
|
||||
var isNode = require('isNode');
|
||||
var merge = require('merge');
|
||||
var mergeInto = require('mergeInto');
|
||||
var mergeHelpers = require('mergeHelpers');
|
||||
|
||||
var checkMergeObjectArgs = mergeHelpers.checkMergeObjectArgs;
|
||||
@@ -51,7 +49,7 @@ if (__DEV__) {
|
||||
* @constructor
|
||||
*/
|
||||
LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
|
||||
mergeInto(this, initialProperties);
|
||||
Object.assign(this, initialProperties);
|
||||
deepFreeze(this);
|
||||
};
|
||||
|
||||
@@ -100,7 +98,7 @@ if (__DEV__) {
|
||||
*/
|
||||
LegacyImmutableObject.set = function(immutableObject, put) {
|
||||
assertLegacyImmutableObject(immutableObject);
|
||||
var totalNewFields = merge(immutableObject, put);
|
||||
var totalNewFields = Object.assign({}, immutableObject, put);
|
||||
return new LegacyImmutableObject(totalNewFields);
|
||||
};
|
||||
|
||||
@@ -112,7 +110,7 @@ if (__DEV__) {
|
||||
* @constructor
|
||||
*/
|
||||
LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
|
||||
mergeInto(this, initialProperties);
|
||||
Object.assign(this, initialProperties);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -126,7 +124,7 @@ if (__DEV__) {
|
||||
LegacyImmutableObject.set = function(immutableObject, put) {
|
||||
assertLegacyImmutableObject(immutableObject);
|
||||
var newMap = new LegacyImmutableObject(immutableObject);
|
||||
mergeInto(newMap, put);
|
||||
Object.assign(newMap, put);
|
||||
return newMap;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
"use strict";
|
||||
|
||||
var invariant = require('invariant');
|
||||
var mixInto = require('mixInto');
|
||||
|
||||
var PREFIX = 'key:';
|
||||
|
||||
@@ -483,7 +482,7 @@ var OrderedMapMethods = {
|
||||
}
|
||||
};
|
||||
|
||||
mixInto(OrderedMapImpl, OrderedMapMethods);
|
||||
Object.assign(OrderedMapImpl.prototype, OrderedMapMethods);
|
||||
|
||||
var OrderedMap = {
|
||||
from: function(orderedMap) {
|
||||
|
||||
@@ -19,14 +19,12 @@
|
||||
"use strict";
|
||||
|
||||
var Transaction;
|
||||
var mixInto;
|
||||
|
||||
var INIT_ERRORED = 'initErrored'; // Just a dummy value to check for.
|
||||
describe('Transaction', function() {
|
||||
beforeEach(function() {
|
||||
require('mock-modules').dumpCache();
|
||||
Transaction = require('Transaction');
|
||||
mixInto = require('mixInto');
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -53,7 +51,7 @@ describe('Transaction', function() {
|
||||
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
this.lastCloseParam = INIT_ERRORED; // WON'T be set to something else
|
||||
};
|
||||
mixInto(TestTransaction, Transaction.Mixin);
|
||||
Object.assign(TestTransaction.prototype, Transaction.Mixin);
|
||||
TestTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [
|
||||
{
|
||||
@@ -102,7 +100,7 @@ describe('Transaction', function() {
|
||||
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
};
|
||||
mixInto(TestTransaction, Transaction.Mixin);
|
||||
Object.assign(TestTransaction.prototype, Transaction.Mixin);
|
||||
TestTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [
|
||||
{
|
||||
@@ -163,7 +161,7 @@ describe('Transaction', function() {
|
||||
this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
};
|
||||
mixInto(TestTransaction, Transaction.Mixin);
|
||||
Object.assign(TestTransaction.prototype, Transaction.Mixin);
|
||||
// Now, none of the close/inits throw, but the operation we wrap will throw.
|
||||
TestTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [
|
||||
@@ -227,7 +225,7 @@ describe('Transaction', function() {
|
||||
var TestTransaction = function() {
|
||||
this.reinitializeTransaction();
|
||||
};
|
||||
mixInto(TestTransaction, Transaction.Mixin);
|
||||
Object.assign(TestTransaction.prototype, Transaction.Mixin);
|
||||
var exceptionMsg = 'This exception should throw.';
|
||||
TestTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [
|
||||
@@ -256,7 +254,7 @@ describe('Transaction', function() {
|
||||
this.reinitializeTransaction();
|
||||
this.firstCloseParam = INIT_ERRORED; // WILL be set to something else
|
||||
};
|
||||
mixInto(TestTransaction, Transaction.Mixin);
|
||||
Object.assign(TestTransaction.prototype, Transaction.Mixin);
|
||||
TestTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [
|
||||
{
|
||||
@@ -284,7 +282,7 @@ describe('Transaction', function() {
|
||||
var NestedTransaction = function() {
|
||||
this.reinitializeTransaction();
|
||||
};
|
||||
mixInto(NestedTransaction, Transaction.Mixin);
|
||||
Object.assign(NestedTransaction.prototype, Transaction.Mixin);
|
||||
NestedTransaction.prototype.getTransactionWrappers = function() {
|
||||
return [{
|
||||
initialize: function() {
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule mixInto
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Simply copies properties to the prototype.
|
||||
*/
|
||||
var mixInto = function(constructor, methodBag) {
|
||||
var methodName;
|
||||
for (methodName in methodBag) {
|
||||
if (!methodBag.hasOwnProperty(methodName)) {
|
||||
continue;
|
||||
}
|
||||
constructor.prototype[methodName] = methodBag[methodName];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = mixInto;
|
||||
Vendored
+1
-3
@@ -16,8 +16,6 @@
|
||||
* @providesModule emptyFunction
|
||||
*/
|
||||
|
||||
var copyProperties = require('copyProperties');
|
||||
|
||||
function makeEmptyFunction(arg) {
|
||||
return function() {
|
||||
return arg;
|
||||
@@ -31,7 +29,7 @@ function makeEmptyFunction(arg) {
|
||||
*/
|
||||
function emptyFunction() {}
|
||||
|
||||
copyProperties(emptyFunction, {
|
||||
Object.assign(emptyFunction, {
|
||||
thatReturns: makeEmptyFunction,
|
||||
thatReturnsFalse: makeEmptyFunction(false),
|
||||
thatReturnsTrue: makeEmptyFunction(true),
|
||||
|
||||
Vendored
+1
-2
@@ -19,7 +19,6 @@
|
||||
var invariant = require('invariant');
|
||||
var isNode = require('isNode');
|
||||
var keyOf = require('keyOf');
|
||||
var mergeInto = require('mergeInto');
|
||||
|
||||
var SECRET_KEY = keyOf({_DONT_EVER_TYPE_THIS_SECRET_KEY: null});
|
||||
|
||||
@@ -67,7 +66,7 @@ class Immutable {
|
||||
static mergeAllPropertiesInto(destination, propertyObjects) {
|
||||
var argLength = propertyObjects.length;
|
||||
for (var i = 0; i < argLength; i++) {
|
||||
mergeInto(destination, propertyObjects[i]);
|
||||
Object.assign(destination, propertyObjects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user