@samitouri / QOS-React / commits / 93042c277e

Stop relying on variable hoisting (#8380)

Only declare the variable once in this scope, instead of declaring them multiple times in the same scope. This fixes #8318, even though it might technically be a shortcoming in Rollup.

Linus Unnebäck committed Nov 22, 2016 at 16:18 UTC 93042c277e57ec723480962a14397579c1bb21e3
1 file changed +16 -15
docs/js/react.js
+16 -15
@@ -1351,30 +1351,31 @@ typeof Set === 'function' && isNative(Set) &&
1351 // Set.prototype.keys
1352 Set.prototype != null && typeof Set.prototype.keys === 'function' && isNative(Set.prototype.keys);
1353
1354 +var setItem, getItem, removeItem, getItemIDs, addRoot, removeRoot, getRootIDs;
1355 if (canUseCollections) {
1356 var itemMap = new Map();
1357 var rootIDSet = new Set();
1358
1358 - var setItem = function (id, item) {
1359 + setItem = function (id, item) {
1360 itemMap.set(id, item);
1361 };
1361 - var getItem = function (id) {
1362 + getItem = function (id) {
1363 return itemMap.get(id);
1364 };
1364 - var removeItem = function (id) {
1365 + removeItem = function (id) {
1366 itemMap['delete'](id);
1367 };
1367 - var getItemIDs = function () {
1368 + getItemIDs = function () {
1369 return Array.from(itemMap.keys());
1370 };
1371
1371 - var addRoot = function (id) {
1372 + addRoot = function (id) {
1373 rootIDSet.add(id);
1374 };
1374 - var removeRoot = function (id) {
1375 + removeRoot = function (id) {
1376 rootIDSet['delete'](id);
1377 };
1377 - var getRootIDs = function () {
1378 + getRootIDs = function () {
1379 return Array.from(rootIDSet.keys());
1380 };
1381 } else {
@@ -1390,31 +1391,31 @@ if (canUseCollections) {
1391 return parseInt(key.substr(1), 10);
1392 };
1393
1393 - var setItem = function (id, item) {
1394 + setItem = function (id, item) {
1395 var key = getKeyFromID(id);
1396 itemByKey[key] = item;
1397 };
1397 - var getItem = function (id) {
1398 + getItem = function (id) {
1399 var key = getKeyFromID(id);
1400 return itemByKey[key];
1401 };
1401 - var removeItem = function (id) {
1402 + removeItem = function (id) {
1403 var key = getKeyFromID(id);
1404 delete itemByKey[key];
1405 };
1405 - var getItemIDs = function () {
1406 + getItemIDs = function () {
1407 return Object.keys(itemByKey).map(getIDFromKey);
1408 };
1409
1409 - var addRoot = function (id) {
1410 + addRoot = function (id) {
1411 var key = getKeyFromID(id);
1412 rootByKey[key] = true;
1413 };
1413 - var removeRoot = function (id) {
1414 + removeRoot = function (id) {
1415 var key = getKeyFromID(id);
1416 delete rootByKey[key];
1417 };
1417 - var getRootIDs = function () {
1418 + getRootIDs = function () {
1419 return Object.keys(rootByKey).map(getIDFromKey);
1420 };
1421 }
@@ -3745,4 +3746,4 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) {
3746 };
3747
3748 },{}]},{},[18])(18)
3748 -});
\ No newline at end of file
3749 +});