Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure code to work around a Rollup bug #8384

Merged
merged 1 commit into from
Nov 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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