Maintain types for memoized functions

This commit is contained in:
Zaid Abdulla committed 2019-06-05 00:17:36 -07:00
1 parent faa12537e4
commit 63876025d2
6 files changed
+10 -9

No files matched your search

+1 -1
View File
@@ -285,7 +285,7 @@ const lang = parsimmon.createLanguage({
}
});
export function parse(str): Expression {
export function parse(str: string): Expression {
if (!str) return null;
return lang.Expression.tryParse(str);
}
+5 -4
View File
@@ -20,9 +20,10 @@ function getKey(obj): string {
return k;
}
export default function memoize(func): Function {
return (...args) => {
const key = JSON.stringify(args.map(getKey)) + getKey(func);
export default function memoize<T extends Function>(func: T): T {
const funcKey = getKey(func);
return ((...args) => {
const key = JSON.stringify(args.map(getKey)) + funcKey;
if (cache1.has(key)) return cache1.get(key);
@@ -31,7 +32,7 @@ export default function memoize(func): Function {
else r = func(...args);
cache1.set(key, r);
return r;
};
}) as any;
}
const interval = setInterval(() => {
+1 -1
View File
@@ -127,7 +127,7 @@ function parameterInfoList(xml: Element): [string, boolean][] {
});
}
const getValueType = memoize(str =>
const getValueType = memoize((str: string) =>
parseAttrs(str)
.find(s => s.localName === "type")
.value.trim()
+1 -1
View File
@@ -206,7 +206,7 @@ for (const [resource, flags] of Object.entries(resources)) {
const now = Date.now();
for (const [k, v] of Object.entries(columns)) {
const e = evaluate(parse(v), null, now);
const e = evaluate(parse(v as string), null, now);
columns[k] = e;
for (const p of extractParams(e)) options.projection[p] = 1;
}