Skip to content

Commit

Permalink
Don't polyfill Object.entries globally
Browse files Browse the repository at this point in the history
Patching `Object.entries` affects other code beyond this library, which
ideally should not happen. With this patch the polyfill is still used
when necessary but the global environment is not unexpectedly changed by
including react-i18next :)
  • Loading branch information
goto-bus-stop committed Jul 15, 2018
1 parent 02bffe8 commit f9e1f9d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/loadNamespaces.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// shim object entries
if (!Object.entries)
Object.entries = function( obj ){
const objectEntries = Object.entries ||
function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
Expand All @@ -14,7 +13,7 @@ if (!Object.entries)
function eachComponents(components, iterator) {
for (let i = 0, l = components.length; i < l; i++) { // eslint-disable-line id-length
if (typeof components[i] === 'object') {
for (const [key, value] of Object.entries(components[i])) {
for (const [key, value] of objectEntries(components[i])) {
iterator(value, i, key);
}
} else {
Expand Down

0 comments on commit f9e1f9d

Please sign in to comment.