From 43e7d1d2cc55fd0277cf6cc7c81af912403746ce Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 20 Dec 2017 00:41:40 -0800 Subject: [PATCH] Use an object instead of a 2-tuple. --- packages/babel-core/src/config/caching.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/babel-core/src/config/caching.js b/packages/babel-core/src/config/caching.js index 47414fbc68..b9703560b5 100644 --- a/packages/babel-core/src/config/caching.js +++ b/packages/babel-core/src/config/caching.js @@ -14,9 +14,10 @@ type SimpleCacheConfiguratorObj = { invalidate: (handler: () => T) => T, }; -type CacheEntry = Array< - [ResultT, (SideChannel) => boolean], ->; +type CacheEntry = Array<{ + value: ResultT, + valid: SideChannel => boolean, +}>; export type { CacheConfigurator }; @@ -64,7 +65,7 @@ function makeCachedFunction< ); if (cachedValue) { - for (const [value, valid] of cachedValue) { + for (const { value, valid } of cachedValue) { if (valid(data)) return value; } } @@ -79,18 +80,18 @@ function makeCachedFunction< switch (cache.mode()) { case "forever": - cachedValue = [[value, () => true]]; + cachedValue = [{ value, valid: () => true }]; callCache.set(arg, cachedValue); break; case "invalidate": - cachedValue = [[value, cache.validator()]]; + cachedValue = [{ value, valid: cache.validator() }]; callCache.set(arg, cachedValue); break; case "valid": if (cachedValue) { - cachedValue.push([value, cache.validator()]); + cachedValue.push({ value, valid: cache.validator() }); } else { - cachedValue = [[value, cache.validator()]]; + cachedValue = [{ value, valid: cache.validator() }]; callCache.set(arg, cachedValue); } }