@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.
Files changed (74) hide show
  1. package/CHANGELOG.json +31 -1
  2. package/CHANGELOG.md +18 -2
  3. package/lib/component-patterns/renderSlot.d.ts +21 -0
  4. package/lib/component-patterns/renderSlot.d.ts.map +1 -0
  5. package/lib/component-patterns/renderSlot.js +14 -0
  6. package/lib/component-patterns/renderSlot.js.map +1 -0
  7. package/lib/component-patterns/stagedComponent.d.ts +39 -0
  8. package/lib/component-patterns/stagedComponent.d.ts.map +1 -0
  9. package/lib/component-patterns/stagedComponent.js +20 -0
  10. package/lib/component-patterns/stagedComponent.js.map +1 -0
  11. package/lib/component-patterns/withSlots.d.ts +15 -0
  12. package/lib/component-patterns/withSlots.d.ts.map +1 -0
  13. package/lib/component-patterns/withSlots.js +19 -0
  14. package/lib/component-patterns/withSlots.js.map +1 -0
  15. package/lib/index.d.ts +7 -2
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +5 -1
  18. package/lib/index.js.map +1 -1
  19. package/lib/memo-cache/getCacheEntry.d.ts +8 -6
  20. package/lib/memo-cache/getCacheEntry.d.ts.map +1 -1
  21. package/lib/memo-cache/getCacheEntry.js +5 -16
  22. package/lib/memo-cache/getCacheEntry.js.map +1 -1
  23. package/lib/memo-cache/getMemoCache.d.ts +15 -3
  24. package/lib/memo-cache/getMemoCache.d.ts.map +1 -1
  25. package/lib/memo-cache/getMemoCache.js +11 -1
  26. package/lib/memo-cache/getMemoCache.js.map +1 -1
  27. package/lib/memo-cache/getMemoCache.test.js +2 -2
  28. package/lib/memo-cache/getMemoCache.test.js.map +1 -1
  29. package/lib/memo-cache/memoize.js.map +1 -1
  30. package/lib-commonjs/component-patterns/renderSlot.d.ts +21 -0
  31. package/lib-commonjs/component-patterns/renderSlot.d.ts.map +1 -0
  32. package/lib-commonjs/component-patterns/renderSlot.js +19 -0
  33. package/lib-commonjs/component-patterns/renderSlot.js.map +1 -0
  34. package/lib-commonjs/component-patterns/stagedComponent.d.ts +39 -0
  35. package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -0
  36. package/lib-commonjs/component-patterns/stagedComponent.js +25 -0
  37. package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -0
  38. package/lib-commonjs/component-patterns/withSlots.d.ts +15 -0
  39. package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -0
  40. package/lib-commonjs/component-patterns/withSlots.js +23 -0
  41. package/lib-commonjs/component-patterns/withSlots.js.map +1 -0
  42. package/lib-commonjs/index.d.ts +7 -2
  43. package/lib-commonjs/index.d.ts.map +1 -1
  44. package/lib-commonjs/index.js +9 -1
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/memo-cache/getCacheEntry.d.ts +8 -6
  47. package/lib-commonjs/memo-cache/getCacheEntry.d.ts.map +1 -1
  48. package/lib-commonjs/memo-cache/getCacheEntry.js +5 -16
  49. package/lib-commonjs/memo-cache/getCacheEntry.js.map +1 -1
  50. package/lib-commonjs/memo-cache/getMemoCache.d.ts +15 -3
  51. package/lib-commonjs/memo-cache/getMemoCache.d.ts.map +1 -1
  52. package/lib-commonjs/memo-cache/getMemoCache.js +13 -2
  53. package/lib-commonjs/memo-cache/getMemoCache.js.map +1 -1
  54. package/lib-commonjs/memo-cache/getMemoCache.test.js +1 -1
  55. package/lib-commonjs/memo-cache/getMemoCache.test.js.map +1 -1
  56. package/lib-commonjs/memo-cache/memoize.js.map +1 -1
  57. package/package.json +1 -16
  58. package/src/component-patterns/renderSlot.ts +27 -0
  59. package/src/component-patterns/stagedComponent.ts +53 -0
  60. package/src/component-patterns/withSlots.tsx +25 -0
  61. package/src/index.ts +9 -2
  62. package/src/memo-cache/getCacheEntry.ts +17 -25
  63. package/src/memo-cache/getMemoCache.test.ts +2 -2
  64. package/src/memo-cache/getMemoCache.ts +24 -8
  65. package/src/memo-cache/memoize.ts +2 -2
  66. package/lib/memo-cache/index.d.ts +0 -4
  67. package/lib/memo-cache/index.d.ts.map +0 -1
  68. package/lib/memo-cache/index.js +0 -3
  69. package/lib/memo-cache/index.js.map +0 -1
  70. package/lib-commonjs/memo-cache/index.d.ts +0 -4
  71. package/lib-commonjs/memo-cache/index.d.ts.map +0 -1
  72. package/lib-commonjs/memo-cache/index.js +0 -8
  73. package/lib-commonjs/memo-cache/index.js.map +0 -1
  74. 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
- /** signature for the cache function */
7
- export type GetMemoValue<T, TGet = any> = (factory: T | ValueFactory<T>, keys: any[]) => [T, GetMemoValue<TGet>];
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<any> = {};
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, TGet = any>(entry: CacheEntry<any>, factory: T | ValueFactory<T>, keys: any[]): [T, GetMemoValue<TGet>] {
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 (!foundEntry.hasOwnProperty('value')) {
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: TGet | ValueFactory<TGet>, args: any[]) => getMemoValueWorker<TGet>(foundEntry, fact, args)];
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<T = any>(globalKey?: object): GetMemoValue<T> {
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: T | ValueFactory<T>, args: any[]) => getMemoValueWorker<T>(entry, fact, args);
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<any>();
10
+ const cache = getMemoCache();
11
11
  // create the closure which wraps the calling function
12
- const closure = (...args: any[]) => {
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,4 +0,0 @@
1
- export type { GetMemoValue } from './getMemoCache';
2
- export { getMemoCache } from './getMemoCache';
3
- export { memoize } from './memoize';
4
- //# sourceMappingURL=index.d.ts.map
@@ -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,3 +0,0 @@
1
- export { getMemoCache } from './getMemoCache';
2
- export { memoize } from './memoize';
3
- //# sourceMappingURL=index.js.map
@@ -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,4 +0,0 @@
1
- export type { GetMemoValue } from './getMemoCache';
2
- export { getMemoCache } from './getMemoCache';
3
- export { memoize } from './memoize';
4
- //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,3 +0,0 @@
1
- export type { GetMemoValue } from './getMemoCache';
2
- export { getMemoCache } from './getMemoCache';
3
- export { memoize } from './memoize';