Skip to content

Commit

Permalink
Replace isPlainObject with unmodified version from Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
timdorr committed Apr 25, 2018
1 parent 38a231b commit be77761
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/utils/isPlainObject.js
Expand Up @@ -3,14 +3,12 @@
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false

let prototypeOfObj = Object.getPrototypeOf(obj)
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)

}

return prototypeOfObj === proto
}
if (typeof obj !== 'object' || obj === null) return false

let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}

return Object.getPrototypeOf(obj) === proto
}

2 comments on commit be77761

@matthargett
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not worth saving a call to Object.getPrototypeOf(obj) ?

@timdorr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not particularly. Simplicity over absolute speed. It's already orders of magnitude faster than lodash's version, since it's not doing any expensive toString() calls.

Please sign in to comment.