Skip to content

Commit

Permalink
Stop relying on variable hoisting (facebook#8380)
Browse files Browse the repository at this point in the history
Only declare the variable once in this scope, instead of declaring them multiple times in the same scope.

This fixes facebook#8318, even though it might technically be a shortcoming in Rollup.
  • Loading branch information
LinusU authored and acusti committed Mar 15, 2017
1 parent f282830 commit 77447c9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions docs/js/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -1351,30 +1351,31 @@ typeof Set === 'function' && isNative(Set) &&
// Set.prototype.keys
Set.prototype != null && typeof Set.prototype.keys === 'function' && isNative(Set.prototype.keys);

var setItem, getItem, removeItem, getItemIDs, addRoot, removeRoot, getRootIDs;
if (canUseCollections) {
var itemMap = new Map();
var rootIDSet = new Set();

var setItem = function (id, item) {
setItem = function (id, item) {
itemMap.set(id, item);
};
var getItem = function (id) {
getItem = function (id) {
return itemMap.get(id);
};
var removeItem = function (id) {
removeItem = function (id) {
itemMap['delete'](id);
};
var getItemIDs = function () {
getItemIDs = function () {
return Array.from(itemMap.keys());
};

var addRoot = function (id) {
addRoot = function (id) {
rootIDSet.add(id);
};
var removeRoot = function (id) {
removeRoot = function (id) {
rootIDSet['delete'](id);
};
var getRootIDs = function () {
getRootIDs = function () {
return Array.from(rootIDSet.keys());
};
} else {
Expand All @@ -1390,31 +1391,31 @@ if (canUseCollections) {
return parseInt(key.substr(1), 10);
};

var setItem = function (id, item) {
setItem = function (id, item) {
var key = getKeyFromID(id);
itemByKey[key] = item;
};
var getItem = function (id) {
getItem = function (id) {
var key = getKeyFromID(id);
return itemByKey[key];
};
var removeItem = function (id) {
removeItem = function (id) {
var key = getKeyFromID(id);
delete itemByKey[key];
};
var getItemIDs = function () {
getItemIDs = function () {
return Object.keys(itemByKey).map(getIDFromKey);
};

var addRoot = function (id) {
addRoot = function (id) {
var key = getKeyFromID(id);
rootByKey[key] = true;
};
var removeRoot = function (id) {
removeRoot = function (id) {
var key = getKeyFromID(id);
delete rootByKey[key];
};
var getRootIDs = function () {
getRootIDs = function () {
return Object.keys(rootByKey).map(getIDFromKey);
};
}
Expand Down Expand Up @@ -3745,4 +3746,4 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) {
};

},{}]},{},[18])(18)
});
});

0 comments on commit 77447c9

Please sign in to comment.