From 5ce325c700635d6a6df455e69e4b1b5731210af7 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 22 Nov 2016 19:02:22 +0000 Subject: [PATCH] Restructure code to work around a Rollup bug --- .../hooks/ReactComponentTreeHook.js | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/isomorphic/hooks/ReactComponentTreeHook.js b/src/isomorphic/hooks/ReactComponentTreeHook.js index ae769001c959a..fd778f753603b 100644 --- a/src/isomorphic/hooks/ReactComponentTreeHook.js +++ b/src/isomorphic/hooks/ReactComponentTreeHook.js @@ -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()); }; @@ -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); }; }