Use nested config structure

This commit is contained in:
Zaid Abdulla committed 2018-12-26 00:22:07 -08:00
1 parent 581a510960
commit 30dbf0cf40
15 files changed
+366 -251

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
"use strict";
let cache1 = new WeakMap();
let cache2 = new WeakMap();
function get(func, k) {
let c1 = cache1.get(func);
if (!c1) cache1.set(func, (c1 = new Map()));
if (c1.has(k)) return c1.get(k);
const c2 = cache2.get(func);
const v = c2 && c2.has(k) ? c2.get(k) : func(k);
c1.set(k, v);
return v;
}
function getter(func) {
return k => get(func, k);
}
function purge() {
cache2 = cache1;
cache1 = new WeakMap();
}
exports.get = get;
exports.getter = getter;
exports.purge = purge;