Skip to content

Commit

Permalink
Restructure code to work around a Rollup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 22, 2016
1 parent 91676a6 commit 5ce325c
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/isomorphic/hooks/ReactComponentTreeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,38 @@ var canUseCollections = (
isNative(Set.prototype.keys)
);

var setItem;
var getItem;
var removeItem;
var getItemIDs;
var addRoot;
var removeRoot;
var 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());
};

Expand All @@ -102,31 +110,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

0 comments on commit 5ce325c

Please sign in to comment.