Summary: remove `copyProperties` module, and replace the functionality with `Object.assign`

Reviewed By: javache

Differential Revision: D4745771

fbshipit-source-id: 2440620757e7539dbd7fd39f5920ac0b5b4183c5
This commit is contained in:
David Aurelio 2017-03-21 07:49:54 -07:00 коммит произвёл Facebook Github Bot
Родитель 439cb76a00
Коммит a34956f2fb
3 изменённых файлов: 4 добавлений и 55 удалений

Просмотреть файл

@ -11,8 +11,6 @@
*/
'use strict';
const copyProperties = require('copyProperties');
/**
* EventValidator is designed to validate event types to make it easier to catch
* common mistakes. It accepts a map of all of the different types of events
@ -37,7 +35,7 @@ const EventValidator = {
const eventTypes = Object.keys(types);
const emitterWithValidation = Object.create(emitter);
copyProperties(emitterWithValidation, {
Object.assign(emitterWithValidation, {
emit: function emit(type, a, b, c, d, e, _) {
assertAllowsEventType(type, eventTypes);
return emitter.emit.call(this, type, a, b, c, d, e, _);

Просмотреть файл

@ -16,7 +16,6 @@ const EventEmitterWithHolding = require('EventEmitterWithHolding');
const EventHolder = require('EventHolder');
const EventValidator = require('EventValidator');
const copyProperties = require('copyProperties');
const invariant = require('fbjs/lib/invariant');
const keyOf = require('fbjs/lib/keyOf');
@ -63,13 +62,13 @@ function mixInEventEmitter(cls: Function | Object, types: Object) {
// Keep track of the provided types, union the types if they already exist,
// which allows for prototype subclasses to provide more types.
if (target.hasOwnProperty(TYPES_KEY)) {
copyProperties(target.__types, types);
Object.assign(target.__types, types);
} else if (target.__types) {
target.__types = copyProperties({}, target.__types, types);
target.__types = Object.assign({}, target.__types, types);
} else {
target.__types = types;
}
copyProperties(target, EventEmitterMixin);
Object.assign(target, EventEmitterMixin);
}
const EventEmitterMixin = {

48
Libraries/vendor/core/copyProperties.js поставляемый
Просмотреть файл

@ -1,48 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule copyProperties
*/
'use strict';
/**
* Copy properties from one or more objects (up to 5) into the first object.
* This is a shallow copy. It mutates the first object and also returns it.
*
* NOTE: `arguments` has a very significant performance penalty, which is why
* we don't support unlimited arguments.
*/
function copyProperties(obj, a, b, c, d, e, f) {
obj = obj || {};
if (__DEV__) {
if (f) {
throw new Error('Too many arguments passed to copyProperties');
}
}
var args = [a, b, c, d, e];
var ii = 0, v;
while (args[ii]) {
v = args[ii++];
for (var k in v) {
obj[k] = v[k];
}
// IE ignores toString in object iteration.. See:
// webreflection.blogspot.com/2007/07/quick-fix-internet-explorer-and.html
if (v.hasOwnProperty && v.hasOwnProperty('toString') &&
(typeof v.toString !== 'undefined') && (obj.toString !== v.toString)) {
obj.toString = v.toString;
}
}
return obj;
}
module.exports = copyProperties;