@fluentui-react-native/framework-base 0.1.1 → 0.1.3
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/component-patterns/renderSlot.d.ts +21 -0
- package/lib/component-patterns/renderSlot.d.ts.map +1 -0
- package/lib/component-patterns/renderSlot.js +14 -0
- package/lib/component-patterns/renderSlot.js.map +1 -0
- package/lib/component-patterns/stagedComponent.d.ts +39 -0
- package/lib/component-patterns/stagedComponent.d.ts.map +1 -0
- package/lib/component-patterns/stagedComponent.js +20 -0
- package/lib/component-patterns/stagedComponent.js.map +1 -0
- package/lib/component-patterns/withSlots.d.ts +15 -0
- package/lib/component-patterns/withSlots.d.ts.map +1 -0
- package/lib/component-patterns/withSlots.js +19 -0
- package/lib/component-patterns/withSlots.js.map +1 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -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/component-patterns/renderSlot.d.ts +21 -0
- package/lib-commonjs/component-patterns/renderSlot.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/renderSlot.js +19 -0
- package/lib-commonjs/component-patterns/renderSlot.js.map +1 -0
- package/lib-commonjs/component-patterns/stagedComponent.d.ts +39 -0
- package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/stagedComponent.js +25 -0
- package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -0
- package/lib-commonjs/component-patterns/withSlots.d.ts +15 -0
- package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/withSlots.js +23 -0
- package/lib-commonjs/component-patterns/withSlots.js.map +1 -0
- package/lib-commonjs/index.d.ts +7 -2
- package/lib-commonjs/index.d.ts.map +1 -1
- package/lib-commonjs/index.js +9 -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 +1 -16
- package/src/component-patterns/renderSlot.ts +27 -0
- package/src/component-patterns/stagedComponent.ts +53 -0
- package/src/component-patterns/withSlots.tsx +25 -0
- package/src/index.ts +9 -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
|
@@ -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