facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Remove dependency on object-assign #225

Closed Chalarangelo closed 6 years ago

Chalarangelo commented 6 years ago

As the code gets processed anyways, the dependency on a polyfill such as object-assign is not necessary. I replaced said dependency with an assignment to the native Object.assign method, so that the code works exactly like before but with one less dependency.

facebook-github-bot commented 6 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

facebook-github-bot commented 6 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

ljharb commented 6 years ago

If the negligible cost of a single dependency is a problem, you can alias it out in your bundler.

jimmywarting commented 5 years ago

What if we changed the only line it's used? from

var allKeys = assign({}, props[propName], shapeTypes);
for (var key in allKeys) {

to

var allKeys = Object.keys(props[propName]).concat(Object.keys(shapeTypes));
for (var i = 0; i < allKeys.length; i++) {
  var key = allKeys[i]

Object.keys is supported in more browsers

jimmywarting commented 5 years ago

Another tip since you have babel

var allKeys = assign({...props[propName], ...shapeTypes});
for (var key in allKeys) {
ljharb commented 5 years ago

That would be different; Object.keys doesn’t include symbols, and neither does for..in.