@fluentui-react-native/framework-base 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +31 -1
- package/CHANGELOG.md +18 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/memo-cache/getCacheEntry.d.ts +8 -6
- package/lib/memo-cache/getCacheEntry.d.ts.map +1 -1
- package/lib/memo-cache/getCacheEntry.js +5 -16
- package/lib/memo-cache/getCacheEntry.js.map +1 -1
- package/lib/memo-cache/getMemoCache.d.ts +15 -3
- package/lib/memo-cache/getMemoCache.d.ts.map +1 -1
- package/lib/memo-cache/getMemoCache.js +11 -1
- package/lib/memo-cache/getMemoCache.js.map +1 -1
- package/lib/memo-cache/getMemoCache.test.js +2 -2
- package/lib/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib/memo-cache/memoize.js.map +1 -1
- package/lib-commonjs/index.d.ts +2 -2
- package/lib-commonjs/index.d.ts.map +1 -1
- package/lib-commonjs/index.js +2 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.d.ts +8 -6
- package/lib-commonjs/memo-cache/getCacheEntry.d.ts.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.js +5 -16
- package/lib-commonjs/memo-cache/getCacheEntry.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.d.ts +15 -3
- package/lib-commonjs/memo-cache/getMemoCache.d.ts.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.js +13 -2
- package/lib-commonjs/memo-cache/getMemoCache.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.js +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib-commonjs/memo-cache/memoize.js.map +1 -1
- package/package.json +2 -17
- package/src/index.ts +2 -2
- package/src/memo-cache/getCacheEntry.ts +17 -25
- package/src/memo-cache/getMemoCache.test.ts +2 -2
- package/src/memo-cache/getMemoCache.ts +24 -8
- package/src/memo-cache/memoize.ts +2 -2
- package/lib/memo-cache/index.d.ts +0 -4
- package/lib/memo-cache/index.d.ts.map +0 -1
- package/lib/memo-cache/index.js +0 -3
- package/lib/memo-cache/index.js.map +0 -1
- package/lib-commonjs/memo-cache/index.d.ts +0 -4
- package/lib-commonjs/memo-cache/index.d.ts.map +0 -1
- package/lib-commonjs/memo-cache/index.js +0 -8
- package/lib-commonjs/memo-cache/index.js.map +0 -1
- package/src/memo-cache/index.ts +0 -3
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,37 @@
|
|
|
2
2
|
"name": "@fluentui-react-native/framework-base",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 25 Jul 2025 21:32:26 GMT",
|
|
6
|
+
"version": "0.1.4",
|
|
7
|
+
"tag": "@fluentui-react-native/framework-base_v0.1.4",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "jasonmo@microsoft.com",
|
|
12
|
+
"package": "@fluentui-react-native/framework-base",
|
|
13
|
+
"commit": "d541dadbec1c9a1750ca45509aa41df3f8a04349",
|
|
14
|
+
"comment": "tune lage.config and fix @types/node version"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 23 Jul 2025 00:22:13 GMT",
|
|
21
|
+
"version": "0.1.3",
|
|
22
|
+
"tag": "@fluentui-react-native/framework-base_v0.1.3",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "jasonmo@microsoft.com",
|
|
27
|
+
"package": "@fluentui-react-native/framework-base",
|
|
28
|
+
"commit": "dd4d507b4ebca7f13757f54cb36f762a3a50d9cc",
|
|
29
|
+
"comment": "fix types in memo-cache as well as a codescan security issue"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Tue, 22 Jul 2025 19:06:23 GMT",
|
|
6
36
|
"version": "0.1.2",
|
|
7
37
|
"tag": "@fluentui-react-native/framework-base_v0.1.2",
|
|
8
38
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/framework-base
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Fri, 25 Jul 2025 21:32:26 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.1.4
|
|
8
|
+
|
|
9
|
+
Fri, 25 Jul 2025 21:32:26 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- tune lage.config and fix @types/node version (jasonmo@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.1.3
|
|
16
|
+
|
|
17
|
+
Wed, 23 Jul 2025 00:22:13 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- fix types in memo-cache as well as a codescan security issue (jasonmo@microsoft.com)
|
|
22
|
+
|
|
7
23
|
## 0.1.2
|
|
8
24
|
|
|
9
|
-
Tue, 22 Jul 2025 19:
|
|
25
|
+
Tue, 22 Jul 2025 19:06:23 GMT
|
|
10
26
|
|
|
11
27
|
### Patches
|
|
12
28
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { immutableMerge, immutableMergeCore, processImmutable, filterToObjects } from './immutable-merge/Merge';
|
|
2
2
|
export type { BuiltinRecursionHandlers, CustomRecursionHandler, MergeOptions, ObjectBase, RecursionHandler, RecursionOption, } from './immutable-merge/Merge';
|
|
3
|
-
export type { GetMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
3
|
+
export type { GetMemoValue, GetTypedMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
5
5
|
export { memoize } from './memo-cache/memoize';
|
|
6
6
|
export type { StyleProp } from './merge-props/mergeStyles.types';
|
|
7
7
|
export { mergeStyles } from './merge-props/mergeStyles';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// immutable-merge exports
|
|
2
2
|
export { immutableMerge, immutableMergeCore, processImmutable, filterToObjects } from './immutable-merge/Merge';
|
|
3
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
3
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
4
4
|
export { memoize } from './memo-cache/memoize';
|
|
5
5
|
export { mergeStyles } from './merge-props/mergeStyles';
|
|
6
6
|
export { mergeProps } from './merge-props/mergeProps';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,4BAA4B;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/** signature for the object/function key values, used for memoization */
|
|
2
|
+
export type MemoObjectKey = object | Function;
|
|
3
|
+
export type CacheEntry<T = unknown> = {
|
|
2
4
|
/** stores the cached value if any */
|
|
3
5
|
value?: T;
|
|
4
6
|
/** entry used for undefined and null values, these both collapse to the same type */
|
|
5
|
-
empty?: CacheEntry<
|
|
7
|
+
empty?: CacheEntry<T>;
|
|
6
8
|
/** entry used for the case where the array of args is null or length 0 */
|
|
7
|
-
noargs?: CacheEntry<
|
|
9
|
+
noargs?: CacheEntry<T>;
|
|
8
10
|
/** all remaining non-object types are keyed as strings for lookups */
|
|
9
11
|
str?: {
|
|
10
|
-
[key: string]: CacheEntry<
|
|
12
|
+
[key: string]: CacheEntry<T>;
|
|
11
13
|
};
|
|
12
14
|
/** object types are keyed in a weak map on object identity */
|
|
13
|
-
obj?: WeakMap<
|
|
15
|
+
obj?: WeakMap<MemoObjectKey, CacheEntry<T>>;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -18,5 +20,5 @@ export type CacheEntry<T, TGet = any> = {
|
|
|
18
20
|
* @param entry - entry to use as the base of the cache walk
|
|
19
21
|
* @param args - array of arguments to use to progress deeper into the cache
|
|
20
22
|
*/
|
|
21
|
-
export declare function getCacheEntry
|
|
23
|
+
export declare function getCacheEntry(entry: CacheEntry, args: unknown[]): CacheEntry;
|
|
22
24
|
//# sourceMappingURL=getCacheEntry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9C,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI;IACpC,qCAAqC;IACrC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV,qFAAqF;IACrF,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEvB,sEAAsE;IACtE,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;IAEvC,8DAA8D;IAC9D,GAAG,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC;AA0BF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAO5E"}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
3
|
-
* @param entry - entry to ensure a key value for
|
|
4
|
-
* @param key - which key of that entry to ensure the value for
|
|
5
|
-
*/
|
|
6
|
-
function ensureAndReturn(entry, key) {
|
|
7
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
8
|
-
throw new Error('Invalid key');
|
|
9
|
-
}
|
|
10
|
-
return (entry[key] = entry[key] || {});
|
|
11
|
-
}
|
|
12
1
|
/**
|
|
13
2
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
14
3
|
*
|
|
@@ -20,17 +9,17 @@ function jumpToCacheEntry(entry, val) {
|
|
|
20
9
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
21
10
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
22
11
|
// where null is just being set on non-object types.
|
|
23
|
-
return
|
|
12
|
+
return (entry.empty ??= {});
|
|
24
13
|
}
|
|
25
14
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
26
15
|
// objects and functions will be treated as key values in a WeakMap
|
|
27
|
-
const byObj = (entry.obj
|
|
16
|
+
const byObj = (entry.obj ??= new WeakMap());
|
|
28
17
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
29
18
|
}
|
|
30
19
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
31
20
|
const key = val + '';
|
|
32
|
-
const byString =
|
|
33
|
-
return (byString[key]
|
|
21
|
+
const byString = (entry.str ??= {});
|
|
22
|
+
return (byString[key] ??= {});
|
|
34
23
|
}
|
|
35
24
|
/**
|
|
36
25
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -44,6 +33,6 @@ export function getCacheEntry(entry, args) {
|
|
|
44
33
|
// - otherwise if there are no args just use the noargs branch
|
|
45
34
|
return args && args.length > 0
|
|
46
35
|
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
|
|
47
|
-
:
|
|
36
|
+
: (entry.noargs ??= {});
|
|
48
37
|
}
|
|
49
38
|
//# sourceMappingURL=getCacheEntry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.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=> T;
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Signature for the cache function. While the implementation is generic, it can run in two modes:
|
|
4
|
+
* - Typed: the cache will enforce the type of both the factory and returned value
|
|
5
|
+
* - Untyped: the cache will infer the type on each call from the factory return value
|
|
6
|
+
*/
|
|
7
|
+
export type GetTypedMemoValue<T> = (factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetTypedMemoValue<T>];
|
|
8
|
+
export type GetMemoValue = <T>(factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetMemoValue];
|
|
4
9
|
/**
|
|
5
10
|
* Get a memo cache instance, this can either be completely self-contained or associated with a global key
|
|
6
11
|
*
|
|
7
12
|
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
8
13
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
9
14
|
*/
|
|
10
|
-
export declare function getMemoCache
|
|
15
|
+
export declare function getMemoCache(globalKey?: object): GetMemoValue;
|
|
16
|
+
/**
|
|
17
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
18
|
+
*
|
|
19
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
20
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getTypedMemoCache<T>(globalKey?: object): GetTypedMemoValue<T>;
|
|
11
23
|
//# sourceMappingURL=getMemoCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAqBnG;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAG7D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAG7E"}
|
|
@@ -11,7 +11,7 @@ const _baseEntry = {};
|
|
|
11
11
|
function getMemoValueWorker(entry, factory, keys) {
|
|
12
12
|
const foundEntry = getCacheEntry(entry, keys);
|
|
13
13
|
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
14
|
-
if (!
|
|
14
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
15
15
|
foundEntry.value = typeof factory === 'function' ? factory() : factory;
|
|
16
16
|
}
|
|
17
17
|
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
|
|
@@ -26,4 +26,14 @@ export function getMemoCache(globalKey) {
|
|
|
26
26
|
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
27
27
|
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
31
|
+
*
|
|
32
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
33
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
34
|
+
*/
|
|
35
|
+
export function getTypedMemoCache(globalKey) {
|
|
36
|
+
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
37
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
38
|
+
}
|
|
29
39
|
//# sourceMappingURL=getMemoCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,oEAAoE;AACpE,MAAM,UAAU,GAAe,EAAE,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAI,KAAiB,EAAE,OAA4B,EAAE,IAAe;IAC7F,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9C,6HAA6H;IAC7H,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;QAC9D,UAAU,CAAC,KAAK,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAE,OAA2B,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;KAC7F;IACD,OAAO,CAAC,UAAU,CAAC,KAAU,EAAE,CAAI,IAAyB,EAAE,IAAe,EAAE,EAAE,CAAC,kBAAkB,CAAI,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnI,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,SAAkB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAI,SAAkB;IACrD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getMemoCache } from './getMemoCache';
|
|
1
|
+
import { getMemoCache, getTypedMemoCache } from './getMemoCache';
|
|
2
2
|
function getObjFactory() {
|
|
3
3
|
const obj = { id: 0 };
|
|
4
4
|
return () => ({
|
|
@@ -28,7 +28,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
28
28
|
expect(val).toBe(obj);
|
|
29
29
|
});
|
|
30
30
|
test('memoValue executes function', () => {
|
|
31
|
-
const memoValue =
|
|
31
|
+
const memoValue = getTypedMemoCache();
|
|
32
32
|
const fn = getObjFactory();
|
|
33
33
|
const v1 = fn();
|
|
34
34
|
const [v2] = memoValue(fn, ['bar', 'baz']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"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I,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzB,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;QAC3B,MAAM,CAAC,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,MAAM,UAAU,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,MAAM,UAAU,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;IAC7B,sDAAsD;IACtD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QACrC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,0DAA0D;IAC1D,OAAO,OAAuB,CAAC;AACjC,CAAC"}
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { immutableMerge, immutableMergeCore, processImmutable, filterToObjects } from './immutable-merge/Merge';
|
|
2
2
|
export type { BuiltinRecursionHandlers, CustomRecursionHandler, MergeOptions, ObjectBase, RecursionHandler, RecursionOption, } from './immutable-merge/Merge';
|
|
3
|
-
export type { GetMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
3
|
+
export type { GetMemoValue, GetTypedMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
5
5
|
export { memoize } from './memo-cache/memoize';
|
|
6
6
|
export type { StyleProp } from './merge-props/mergeStyles.types';
|
|
7
7
|
export { mergeStyles } from './merge-props/mergeStyles';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stagedComponent = exports.withSlots = exports.renderSlot = exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
|
|
3
|
+
exports.stagedComponent = exports.withSlots = exports.renderSlot = exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getTypedMemoCache = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
|
|
4
4
|
// immutable-merge exports
|
|
5
5
|
var Merge_1 = require("./immutable-merge/Merge");
|
|
6
6
|
Object.defineProperty(exports, "immutableMerge", { enumerable: true, get: function () { return Merge_1.immutableMerge; } });
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "processImmutable", { enumerable: true, get: func
|
|
|
9
9
|
Object.defineProperty(exports, "filterToObjects", { enumerable: true, get: function () { return Merge_1.filterToObjects; } });
|
|
10
10
|
var getMemoCache_1 = require("./memo-cache/getMemoCache");
|
|
11
11
|
Object.defineProperty(exports, "getMemoCache", { enumerable: true, get: function () { return getMemoCache_1.getMemoCache; } });
|
|
12
|
+
Object.defineProperty(exports, "getTypedMemoCache", { enumerable: true, get: function () { return getMemoCache_1.getTypedMemoCache; } });
|
|
12
13
|
var memoize_1 = require("./memo-cache/memoize");
|
|
13
14
|
Object.defineProperty(exports, "memoize", { enumerable: true, get: function () { return memoize_1.memoize; } });
|
|
14
15
|
var mergeStyles_1 = require("./merge-props/mergeStyles");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,0DAA4E;AAAnE,4GAAA,YAAY,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AACxC,gDAA+C;AAAtC,kGAAA,OAAO,OAAA;AAIhB,yDAAwD;AAA/C,0GAAA,WAAW,OAAA;AACpB,uDAAsD;AAA7C,wGAAA,UAAU,OAAA;AAEnB,4BAA4B;AAC5B,8DAA6D;AAApD,wGAAA,UAAU,OAAA;AAEnB,4DAA2D;AAAlD,sGAAA,SAAS,OAAA;AAClB,wEAAuE;AAA9D,kHAAA,eAAe,OAAA"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/** signature for the object/function key values, used for memoization */
|
|
2
|
+
export type MemoObjectKey = object | Function;
|
|
3
|
+
export type CacheEntry<T = unknown> = {
|
|
2
4
|
/** stores the cached value if any */
|
|
3
5
|
value?: T;
|
|
4
6
|
/** entry used for undefined and null values, these both collapse to the same type */
|
|
5
|
-
empty?: CacheEntry<
|
|
7
|
+
empty?: CacheEntry<T>;
|
|
6
8
|
/** entry used for the case where the array of args is null or length 0 */
|
|
7
|
-
noargs?: CacheEntry<
|
|
9
|
+
noargs?: CacheEntry<T>;
|
|
8
10
|
/** all remaining non-object types are keyed as strings for lookups */
|
|
9
11
|
str?: {
|
|
10
|
-
[key: string]: CacheEntry<
|
|
12
|
+
[key: string]: CacheEntry<T>;
|
|
11
13
|
};
|
|
12
14
|
/** object types are keyed in a weak map on object identity */
|
|
13
|
-
obj?: WeakMap<
|
|
15
|
+
obj?: WeakMap<MemoObjectKey, CacheEntry<T>>;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -18,5 +20,5 @@ export type CacheEntry<T, TGet = any> = {
|
|
|
18
20
|
* @param entry - entry to use as the base of the cache walk
|
|
19
21
|
* @param args - array of arguments to use to progress deeper into the cache
|
|
20
22
|
*/
|
|
21
|
-
export declare function getCacheEntry
|
|
23
|
+
export declare function getCacheEntry(entry: CacheEntry, args: unknown[]): CacheEntry;
|
|
22
24
|
//# sourceMappingURL=getCacheEntry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9C,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI;IACpC,qCAAqC;IACrC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV,qFAAqF;IACrF,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEvB,sEAAsE;IACtE,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;IAEvC,8DAA8D;IAC9D,GAAG,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC;AA0BF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAO5E"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCacheEntry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
6
|
-
* @param entry - entry to ensure a key value for
|
|
7
|
-
* @param key - which key of that entry to ensure the value for
|
|
8
|
-
*/
|
|
9
|
-
function ensureAndReturn(entry, key) {
|
|
10
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
11
|
-
throw new Error('Invalid key');
|
|
12
|
-
}
|
|
13
|
-
return (entry[key] = entry[key] || {});
|
|
14
|
-
}
|
|
15
4
|
/**
|
|
16
5
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
17
6
|
*
|
|
@@ -23,17 +12,17 @@ function jumpToCacheEntry(entry, val) {
|
|
|
23
12
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
24
13
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
25
14
|
// where null is just being set on non-object types.
|
|
26
|
-
return
|
|
15
|
+
return (entry.empty ??= {});
|
|
27
16
|
}
|
|
28
17
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
29
18
|
// objects and functions will be treated as key values in a WeakMap
|
|
30
|
-
const byObj = (entry.obj
|
|
19
|
+
const byObj = (entry.obj ??= new WeakMap());
|
|
31
20
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
32
21
|
}
|
|
33
22
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
34
23
|
const key = val + '';
|
|
35
|
-
const byString =
|
|
36
|
-
return (byString[key]
|
|
24
|
+
const byString = (entry.str ??= {});
|
|
25
|
+
return (byString[key] ??= {});
|
|
37
26
|
}
|
|
38
27
|
/**
|
|
39
28
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -47,7 +36,7 @@ function getCacheEntry(entry, args) {
|
|
|
47
36
|
// - otherwise if there are no args just use the noargs branch
|
|
48
37
|
return args && args.length > 0
|
|
49
38
|
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
|
|
50
|
-
:
|
|
39
|
+
: (entry.noargs ??= {});
|
|
51
40
|
}
|
|
52
41
|
exports.getCacheEntry = getCacheEntry;
|
|
53
42
|
//# sourceMappingURL=getCacheEntry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mapp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;
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Signature for the cache function. While the implementation is generic, it can run in two modes:
|
|
4
|
+
* - Typed: the cache will enforce the type of both the factory and returned value
|
|
5
|
+
* - Untyped: the cache will infer the type on each call from the factory return value
|
|
6
|
+
*/
|
|
7
|
+
export type GetTypedMemoValue<T> = (factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetTypedMemoValue<T>];
|
|
8
|
+
export type GetMemoValue = <T>(factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetMemoValue];
|
|
4
9
|
/**
|
|
5
10
|
* Get a memo cache instance, this can either be completely self-contained or associated with a global key
|
|
6
11
|
*
|
|
7
12
|
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
8
13
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
9
14
|
*/
|
|
10
|
-
export declare function getMemoCache
|
|
15
|
+
export declare function getMemoCache(globalKey?: object): GetMemoValue;
|
|
16
|
+
/**
|
|
17
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
18
|
+
*
|
|
19
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
20
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getTypedMemoCache<T>(globalKey?: object): GetTypedMemoValue<T>;
|
|
11
23
|
//# sourceMappingURL=getMemoCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAqBnG;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAG7D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAG7E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMemoCache = void 0;
|
|
3
|
+
exports.getTypedMemoCache = exports.getMemoCache = void 0;
|
|
4
4
|
const getCacheEntry_1 = require("./getCacheEntry");
|
|
5
5
|
/** base node used to remember references when a globalKey is set */
|
|
6
6
|
const _baseEntry = {};
|
|
@@ -14,7 +14,7 @@ const _baseEntry = {};
|
|
|
14
14
|
function getMemoValueWorker(entry, factory, keys) {
|
|
15
15
|
const foundEntry = (0, getCacheEntry_1.getCacheEntry)(entry, keys);
|
|
16
16
|
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
17
|
-
if (!
|
|
17
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
18
18
|
foundEntry.value = typeof factory === 'function' ? factory() : factory;
|
|
19
19
|
}
|
|
20
20
|
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
|
|
@@ -30,4 +30,15 @@ function getMemoCache(globalKey) {
|
|
|
30
30
|
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
31
31
|
}
|
|
32
32
|
exports.getMemoCache = getMemoCache;
|
|
33
|
+
/**
|
|
34
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
35
|
+
*
|
|
36
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
37
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
38
|
+
*/
|
|
39
|
+
function getTypedMemoCache(globalKey) {
|
|
40
|
+
const entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
|
|
41
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
42
|
+
}
|
|
43
|
+
exports.getTypedMemoCache = getTypedMemoCache;
|
|
33
44
|
//# sourceMappingURL=getMemoCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":";;;AACA,mDAAgD;
|
|
1
|
+
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":";;;AACA,mDAAgD;AAYhD,oEAAoE;AACpE,MAAM,UAAU,GAAe,EAAE,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAI,KAAiB,EAAE,OAA4B,EAAE,IAAe;IAC7F,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9C,6HAA6H;IAC7H,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;QAC9D,UAAU,CAAC,KAAK,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAE,OAA2B,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;KAC7F;IACD,OAAO,CAAC,UAAU,CAAC,KAAU,EAAE,CAAI,IAAyB,EAAE,IAAe,EAAE,EAAE,CAAC,kBAAkB,CAAI,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnI,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,SAAkB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,IAAA,6BAAa,EAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC;AAHD,oCAGC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAI,SAAkB;IACrD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,IAAA,6BAAa,EAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC;AAHD,8CAGC"}
|
|
@@ -30,7 +30,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
30
30
|
expect(val).toBe(obj);
|
|
31
31
|
});
|
|
32
32
|
test('memoValue executes function', () => {
|
|
33
|
-
const memoValue = (0, getMemoCache_1.
|
|
33
|
+
const memoValue = (0, getMemoCache_1.getTypedMemoCache)();
|
|
34
34
|
const fn = getObjFactory();
|
|
35
35
|
const v1 = fn();
|
|
36
36
|
const [v2] = memoValue(fn, ['bar', 'baz']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":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ACxB,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;QACjC,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzB,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;QAC3B,MAAM,CAAC,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,SAAgB,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAA,2BAAY,
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,SAAgB,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAA,2BAAY,GAAE,CAAC;IAC7B,sDAAsD;IACtD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QACrC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,0DAA0D;IAC1D,OAAO,OAAuB,CAAC;AACjC,CAAC;AATD,0BASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/framework-base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Base types and utilities fluentui-react-native frameworks",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,21 +16,6 @@
|
|
|
16
16
|
"import": "./lib/index.js",
|
|
17
17
|
"require": "./lib-commonjs/index.js",
|
|
18
18
|
"types": "./lib/index.d.ts"
|
|
19
|
-
},
|
|
20
|
-
"./immutable-merge": {
|
|
21
|
-
"import": "./lib/immutable-merge/Merge.js",
|
|
22
|
-
"require": "./lib-commonjs/immutable-merge/Merge.js",
|
|
23
|
-
"types": "./lib/immutable-merge/Merge.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./memo-cache": {
|
|
26
|
-
"import": "./lib/memo-cache/index.js",
|
|
27
|
-
"require": "./lib-commonjs/memo-cache/index.js",
|
|
28
|
-
"types": "./lib/memo-cache/index.d.ts"
|
|
29
|
-
},
|
|
30
|
-
"./merge-props": {
|
|
31
|
-
"import": "./lib/merge-props/index.js",
|
|
32
|
-
"require": "./lib-commonjs/merge-props/index.js",
|
|
33
|
-
"types": "./lib/merge-props/lib/index.d.ts"
|
|
34
19
|
}
|
|
35
20
|
},
|
|
36
21
|
"scripts": {
|
|
@@ -53,6 +38,6 @@
|
|
|
53
38
|
"@fluentui-react-native/eslint-config-rules": "0.1.1",
|
|
54
39
|
"@fluentui-react-native/scripts": "0.1.1",
|
|
55
40
|
"@types/jest": "^29.0.0",
|
|
56
|
-
"@types/node": "^
|
|
41
|
+
"@types/node": "^22.0.0"
|
|
57
42
|
}
|
|
58
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,8 @@ export type {
|
|
|
10
10
|
} from './immutable-merge/Merge';
|
|
11
11
|
|
|
12
12
|
// memo-cache exports
|
|
13
|
-
export type { GetMemoValue } from './memo-cache/getMemoCache';
|
|
14
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
13
|
+
export type { GetMemoValue, GetTypedMemoValue } from './memo-cache/getMemoCache';
|
|
14
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
15
15
|
export { memoize } from './memo-cache/memoize';
|
|
16
16
|
|
|
17
17
|
// merge-props exports
|
|
@@ -1,54 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/** signature for the object/function key values, used for memoization */
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
3
|
+
export type MemoObjectKey = object | Function;
|
|
4
|
+
|
|
5
|
+
export type CacheEntry<T = unknown> = {
|
|
2
6
|
/** stores the cached value if any */
|
|
3
7
|
value?: T;
|
|
4
8
|
|
|
5
9
|
/** entry used for undefined and null values, these both collapse to the same type */
|
|
6
|
-
empty?: CacheEntry<
|
|
10
|
+
empty?: CacheEntry<T>;
|
|
7
11
|
|
|
8
12
|
/** entry used for the case where the array of args is null or length 0 */
|
|
9
|
-
noargs?: CacheEntry<
|
|
13
|
+
noargs?: CacheEntry<T>;
|
|
10
14
|
|
|
11
15
|
/** all remaining non-object types are keyed as strings for lookups */
|
|
12
|
-
str?: { [key: string]: CacheEntry<
|
|
16
|
+
str?: { [key: string]: CacheEntry<T> };
|
|
13
17
|
|
|
14
18
|
/** object types are keyed in a weak map on object identity */
|
|
15
|
-
obj?: WeakMap<
|
|
19
|
+
obj?: WeakMap<MemoObjectKey, CacheEntry<T>>;
|
|
16
20
|
};
|
|
17
21
|
|
|
18
|
-
/**
|
|
19
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
20
|
-
* @param entry - entry to ensure a key value for
|
|
21
|
-
* @param key - which key of that entry to ensure the value for
|
|
22
|
-
*/
|
|
23
|
-
function ensureAndReturn(entry: CacheEntry<any>, key: keyof CacheEntry<any>): CacheEntry<any> | { [key: string]: CacheEntry<any> } {
|
|
24
|
-
if ((key as string) === '__proto__' || (key as string) === 'constructor' || (key as string) === 'prototype') {
|
|
25
|
-
throw new Error('Invalid key');
|
|
26
|
-
}
|
|
27
|
-
return (entry[key] = entry[key] || {});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
/**
|
|
31
23
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
32
24
|
*
|
|
33
25
|
* @param entry - base entry to work from
|
|
34
26
|
* @param val - value to use as the key for progressing to the next level of the cache
|
|
35
27
|
*/
|
|
36
|
-
function jumpToCacheEntry(entry: CacheEntry
|
|
28
|
+
function jumpToCacheEntry(entry: CacheEntry, val: any): CacheEntry {
|
|
37
29
|
if (val === undefined || val === null) {
|
|
38
30
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
39
31
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
40
32
|
// where null is just being set on non-object types.
|
|
41
|
-
return
|
|
33
|
+
return (entry.empty ??= {});
|
|
42
34
|
}
|
|
43
35
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
44
36
|
// objects and functions will be treated as key values in a WeakMap
|
|
45
|
-
const byObj = (entry.obj
|
|
37
|
+
const byObj = (entry.obj ??= new WeakMap<MemoObjectKey, CacheEntry>());
|
|
46
38
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
47
39
|
}
|
|
48
40
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
49
41
|
const key = val + '';
|
|
50
|
-
const byString =
|
|
51
|
-
return (byString[key]
|
|
42
|
+
const byString = (entry.str ??= {});
|
|
43
|
+
return (byString[key] ??= {});
|
|
52
44
|
}
|
|
53
45
|
|
|
54
46
|
/**
|
|
@@ -57,11 +49,11 @@ function jumpToCacheEntry(entry: CacheEntry<any>, val: any): CacheEntry<any> {
|
|
|
57
49
|
* @param entry - entry to use as the base of the cache walk
|
|
58
50
|
* @param args - array of arguments to use to progress deeper into the cache
|
|
59
51
|
*/
|
|
60
|
-
export function getCacheEntry
|
|
52
|
+
export function getCacheEntry(entry: CacheEntry, args: unknown[]): CacheEntry {
|
|
61
53
|
// in the case where the args array exists and is > 0 length:
|
|
62
54
|
// - walk the cache from entry, like a linked list, jumping to the next entry by key, building it up as you go
|
|
63
55
|
// - otherwise if there are no args just use the noargs branch
|
|
64
56
|
return args && args.length > 0
|
|
65
|
-
? (args.reduce((previous: CacheEntry
|
|
66
|
-
:
|
|
57
|
+
? (args.reduce((previous: CacheEntry, arg: unknown) => jumpToCacheEntry(previous, arg), entry) as CacheEntry)
|
|
58
|
+
: (entry.noargs ??= {});
|
|
67
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getMemoCache } from './getMemoCache';
|
|
1
|
+
import { getMemoCache, getTypedMemoCache } from './getMemoCache';
|
|
2
2
|
|
|
3
3
|
interface TestObj {
|
|
4
4
|
id: number;
|
|
@@ -38,7 +38,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test('memoValue executes function', () => {
|
|
41
|
-
const memoValue =
|
|
41
|
+
const memoValue = getTypedMemoCache<TestObj>();
|
|
42
42
|
const fn = getObjFactory();
|
|
43
43
|
const v1 = fn();
|
|
44
44
|
const [v2] = memoValue(fn, ['bar', 'baz']);
|
|
@@ -3,11 +3,16 @@ import { getCacheEntry } from './getCacheEntry';
|
|
|
3
3
|
|
|
4
4
|
export type ValueFactory<T> = () => T;
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Signature for the cache function. While the implementation is generic, it can run in two modes:
|
|
8
|
+
* - Typed: the cache will enforce the type of both the factory and returned value
|
|
9
|
+
* - Untyped: the cache will infer the type on each call from the factory return value
|
|
10
|
+
*/
|
|
11
|
+
export type GetTypedMemoValue<T> = (factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetTypedMemoValue<T>];
|
|
12
|
+
export type GetMemoValue = <T>(factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetMemoValue];
|
|
8
13
|
|
|
9
14
|
/** base node used to remember references when a globalKey is set */
|
|
10
|
-
const _baseEntry: CacheEntry
|
|
15
|
+
const _baseEntry: CacheEntry = {};
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Primary functional worker used to implement the caching pattern
|
|
@@ -16,13 +21,13 @@ const _baseEntry: CacheEntry<any> = {};
|
|
|
16
21
|
* @param factory - generally a function who's results will be cached, and returned via the set of keys
|
|
17
22
|
* @param keys - an ordered array of values of any type, used as keys to look up the entry
|
|
18
23
|
*/
|
|
19
|
-
function getMemoValueWorker<T
|
|
24
|
+
function getMemoValueWorker<T>(entry: CacheEntry, factory: T | ValueFactory<T>, keys: unknown[]): [T, GetMemoValue] {
|
|
20
25
|
const foundEntry = getCacheEntry(entry, keys);
|
|
21
26
|
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
22
|
-
if (!
|
|
27
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
23
28
|
foundEntry.value = typeof factory === 'function' ? (factory as ValueFactory<T>)() : factory;
|
|
24
29
|
}
|
|
25
|
-
return [foundEntry.value, (fact:
|
|
30
|
+
return [foundEntry.value as T, <U>(fact: U | ValueFactory<U>, args: unknown[]) => getMemoValueWorker<U>(foundEntry, fact, args)];
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -31,7 +36,18 @@ function getMemoValueWorker<T, TGet = any>(entry: CacheEntry<any>, factory: T |
|
|
|
31
36
|
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
32
37
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
33
38
|
*/
|
|
34
|
-
export function getMemoCache
|
|
39
|
+
export function getMemoCache(globalKey?: object): GetMemoValue {
|
|
40
|
+
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
41
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
46
|
+
*
|
|
47
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
48
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
49
|
+
*/
|
|
50
|
+
export function getTypedMemoCache<T>(globalKey?: object): GetTypedMemoValue<T> {
|
|
35
51
|
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
36
|
-
return (fact
|
|
52
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
37
53
|
}
|
|
@@ -7,9 +7,9 @@ import { getMemoCache } from './getMemoCache';
|
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
8
8
|
export function memoize<T extends Function>(fn: T): T {
|
|
9
9
|
// create a unique cache that will be captured in the closure
|
|
10
|
-
const cache = getMemoCache
|
|
10
|
+
const cache = getMemoCache();
|
|
11
11
|
// create the closure which wraps the calling function
|
|
12
|
-
const closure = (...args:
|
|
12
|
+
const closure = (...args: unknown[]) => {
|
|
13
13
|
return cache(() => fn(...(args || [])), args)[0];
|
|
14
14
|
};
|
|
15
15
|
// now return that closure strongly typed as the function.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memo-cache/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/memo-cache/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memo-cache/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memo-cache/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memoize = exports.getMemoCache = void 0;
|
|
4
|
-
var getMemoCache_1 = require("./getMemoCache");
|
|
5
|
-
Object.defineProperty(exports, "getMemoCache", { enumerable: true, get: function () { return getMemoCache_1.getMemoCache; } });
|
|
6
|
-
var memoize_1 = require("./memoize");
|
|
7
|
-
Object.defineProperty(exports, "memoize", { enumerable: true, get: function () { return memoize_1.memoize; } });
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memo-cache/index.ts"],"names":[],"mappings":";;;AACA,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
package/src/memo-cache/index.ts
DELETED