@microsoft/live-share-react 1.0.0-preview.8 → 1.0.1-preview.1

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 (220) hide show
  1. package/README.md +99 -34
  2. package/bin/index.d.ts +6 -6
  3. package/bin/index.js +6 -6
  4. package/bin/interfaces/LiveInterfaceExtensions.d.ts +25 -8
  5. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -1
  6. package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
  7. package/bin/interfaces/index.d.ts +1 -1
  8. package/bin/interfaces/index.js +1 -1
  9. package/bin/internal/errors.d.ts +26 -0
  10. package/bin/internal/errors.d.ts.map +1 -0
  11. package/bin/internal/errors.js +39 -0
  12. package/bin/internal/errors.js.map +1 -0
  13. package/bin/internal/index.d.ts +4 -0
  14. package/bin/internal/index.d.ts.map +1 -0
  15. package/bin/internal/index.js +4 -0
  16. package/bin/internal/index.js.map +1 -0
  17. package/bin/internal/type-guards.d.ts +6 -0
  18. package/bin/internal/type-guards.d.ts.map +1 -0
  19. package/bin/internal/type-guards.js +8 -0
  20. package/bin/internal/type-guards.js.map +1 -0
  21. package/bin/{internal-hooks → internal}/useSharedStateRegistry.d.ts +30 -30
  22. package/bin/internal/useSharedStateRegistry.d.ts.map +1 -0
  23. package/bin/{internal-hooks → internal}/useSharedStateRegistry.js +101 -99
  24. package/bin/internal/useSharedStateRegistry.js.map +1 -0
  25. package/bin/live-hooks/index.d.ts +6 -6
  26. package/bin/live-hooks/index.js +6 -6
  27. package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
  28. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -1
  29. package/bin/live-hooks/useLiveCanvas.js +158 -166
  30. package/bin/live-hooks/useLiveCanvas.js.map +1 -1
  31. package/bin/live-hooks/useLiveEvent.d.ts +21 -21
  32. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
  33. package/bin/live-hooks/useLiveEvent.js +100 -85
  34. package/bin/live-hooks/useLiveEvent.js.map +1 -1
  35. package/bin/live-hooks/useLivePresence.d.ts +25 -25
  36. package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
  37. package/bin/live-hooks/useLivePresence.js +106 -92
  38. package/bin/live-hooks/useLivePresence.js.map +1 -1
  39. package/bin/live-hooks/useLiveState.d.ts +19 -19
  40. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  41. package/bin/live-hooks/useLiveState.js +79 -70
  42. package/bin/live-hooks/useLiveState.js.map +1 -1
  43. package/bin/live-hooks/useLiveTimer.d.ts +7 -7
  44. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
  45. package/bin/live-hooks/useLiveTimer.js +150 -131
  46. package/bin/live-hooks/useLiveTimer.js.map +1 -1
  47. package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
  48. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
  49. package/bin/live-hooks/useMediaSynchronizer.js +206 -161
  50. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  51. package/bin/providers/AzureProvider.d.ts +33 -33
  52. package/bin/providers/AzureProvider.d.ts.map +1 -1
  53. package/bin/providers/AzureProvider.js +101 -101
  54. package/bin/providers/AzureProvider.js.map +1 -1
  55. package/bin/providers/LiveShareProvider.d.ts +62 -41
  56. package/bin/providers/LiveShareProvider.d.ts.map +1 -1
  57. package/bin/providers/LiveShareProvider.js +68 -65
  58. package/bin/providers/LiveShareProvider.js.map +1 -1
  59. package/bin/providers/index.d.ts +2 -2
  60. package/bin/providers/index.js +2 -2
  61. package/bin/shared-hooks/index.d.ts +3 -4
  62. package/bin/shared-hooks/index.d.ts.map +1 -1
  63. package/bin/shared-hooks/index.js +3 -4
  64. package/bin/shared-hooks/index.js.map +1 -1
  65. package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
  66. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
  67. package/bin/shared-hooks/useDynamicDDS.js +67 -67
  68. package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
  69. package/bin/shared-hooks/useSharedMap.d.ts +21 -21
  70. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
  71. package/bin/shared-hooks/useSharedMap.js +112 -105
  72. package/bin/shared-hooks/useSharedMap.js.map +1 -1
  73. package/bin/shared-hooks/useSharedState.d.ts +20 -20
  74. package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
  75. package/bin/shared-hooks/useSharedState.js +72 -62
  76. package/bin/shared-hooks/useSharedState.js.map +1 -1
  77. package/bin/types/ActionTypes.d.ts +111 -29
  78. package/bin/types/ActionTypes.d.ts.map +1 -1
  79. package/bin/types/ActionTypes.js +5 -5
  80. package/bin/types/PropTypes.d.ts +7 -7
  81. package/bin/types/PropTypes.d.ts.map +1 -1
  82. package/bin/types/PropTypes.js +5 -5
  83. package/bin/types/ResultTypes.d.ts +174 -162
  84. package/bin/types/ResultTypes.d.ts.map +1 -1
  85. package/bin/types/ResultTypes.js +5 -5
  86. package/bin/types/index.d.ts +3 -3
  87. package/bin/types/index.js +3 -3
  88. package/bin/utils/index.d.ts +1 -1
  89. package/bin/utils/index.js +1 -1
  90. package/bin/utils/type-check.d.ts +14 -14
  91. package/bin/utils/type-check.js +53 -53
  92. package/package.json +18 -14
  93. package/src/interfaces/LiveInterfaceExtensions.ts +19 -2
  94. package/src/internal/errors.ts +48 -0
  95. package/src/internal/index.ts +3 -0
  96. package/src/internal/type-guards.ts +9 -0
  97. package/src/{internal-hooks → internal}/useSharedStateRegistry.ts +6 -5
  98. package/src/live-hooks/useLiveCanvas.ts +12 -20
  99. package/src/live-hooks/useLiveEvent.ts +41 -22
  100. package/src/live-hooks/useLivePresence.ts +52 -33
  101. package/src/live-hooks/useLiveState.ts +48 -53
  102. package/src/live-hooks/useLiveTimer.ts +50 -41
  103. package/src/live-hooks/useMediaSynchronizer.ts +108 -41
  104. package/src/providers/AzureProvider.tsx +3 -8
  105. package/src/providers/LiveShareProvider.tsx +46 -16
  106. package/src/shared-hooks/index.ts +0 -1
  107. package/src/shared-hooks/useDynamicDDS.ts +15 -8
  108. package/src/shared-hooks/useSharedMap.ts +48 -22
  109. package/src/shared-hooks/useSharedState.ts +15 -5
  110. package/src/types/ActionTypes.ts +100 -15
  111. package/src/types/ResultTypes.ts +23 -9
  112. package/bin/internal-hooks/index.d.ts +0 -2
  113. package/bin/internal-hooks/index.d.ts.map +0 -1
  114. package/bin/internal-hooks/index.js +0 -2
  115. package/bin/internal-hooks/index.js.map +0 -1
  116. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +0 -14
  117. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +0 -1
  118. package/bin/internal-hooks/useDynamicDDSRegistry.js +0 -142
  119. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +0 -1
  120. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
  121. package/bin/internal-hooks/useSharedStateRegistry.js.map +0 -1
  122. package/bin/internal-hooks/useStateRef.d.ts +0 -7
  123. package/bin/internal-hooks/useStateRef.d.ts.map +0 -1
  124. package/bin/internal-hooks/useStateRef.js +0 -15
  125. package/bin/internal-hooks/useStateRef.js.map +0 -1
  126. package/bin/live-hooks/useLiveAICompletion.d.ts +0 -29
  127. package/bin/live-hooks/useLiveAICompletion.d.ts.map +0 -1
  128. package/bin/live-hooks/useLiveAICompletion.js +0 -186
  129. package/bin/live-hooks/useLiveAICompletion.js.map +0 -1
  130. package/bin/live-hooks/useLiveCoPilot.d.ts +0 -28
  131. package/bin/live-hooks/useLiveCoPilot.d.ts.map +0 -1
  132. package/bin/live-hooks/useLiveCoPilot.js +0 -178
  133. package/bin/live-hooks/useLiveCoPilot.js.map +0 -1
  134. package/bin/live-share-turbo/AzureTurboClient.d.ts +0 -39
  135. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +0 -1
  136. package/bin/live-share-turbo/AzureTurboClient.js +0 -56
  137. package/bin/live-share-turbo/AzureTurboClient.js.map +0 -1
  138. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +0 -53
  139. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +0 -1
  140. package/bin/live-share-turbo/LiveShareTurboClient.js +0 -69
  141. package/bin/live-share-turbo/LiveShareTurboClient.js.map +0 -1
  142. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +0 -31
  143. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +0 -1
  144. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +0 -75
  145. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +0 -1
  146. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +0 -48
  147. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +0 -1
  148. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +0 -104
  149. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +0 -1
  150. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +0 -28
  151. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +0 -1
  152. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +0 -68
  153. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +0 -1
  154. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +0 -60
  155. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +0 -1
  156. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +0 -111
  157. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +0 -1
  158. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +0 -77
  159. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +0 -1
  160. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +0 -137
  161. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +0 -1
  162. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +0 -30
  163. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +0 -1
  164. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +0 -74
  165. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +0 -1
  166. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +0 -61
  167. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +0 -1
  168. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +0 -108
  169. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +0 -1
  170. package/bin/live-share-turbo/dds-objects/index.d.ts +0 -8
  171. package/bin/live-share-turbo/dds-objects/index.d.ts.map +0 -1
  172. package/bin/live-share-turbo/dds-objects/index.js +0 -8
  173. package/bin/live-share-turbo/dds-objects/index.js.map +0 -1
  174. package/bin/live-share-turbo/index.d.ts +0 -5
  175. package/bin/live-share-turbo/index.d.ts.map +0 -1
  176. package/bin/live-share-turbo/index.js +0 -5
  177. package/bin/live-share-turbo/index.js.map +0 -1
  178. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +0 -15
  179. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +0 -1
  180. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +0 -2
  181. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +0 -1
  182. package/bin/live-share-turbo/interfaces/index.d.ts +0 -3
  183. package/bin/live-share-turbo/interfaces/index.d.ts.map +0 -1
  184. package/bin/live-share-turbo/interfaces/index.js +0 -3
  185. package/bin/live-share-turbo/interfaces/index.js.map +0 -1
  186. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +0 -39
  187. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +0 -1
  188. package/bin/live-share-turbo/internals/FluidTurboClient.js +0 -121
  189. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +0 -1
  190. package/bin/live-share-turbo/internals/index.d.ts +0 -2
  191. package/bin/live-share-turbo/internals/index.d.ts.map +0 -1
  192. package/bin/live-share-turbo/internals/index.js +0 -2
  193. package/bin/live-share-turbo/internals/index.js.map +0 -1
  194. package/bin/live-share-turbo/internals/types.d.ts +0 -4
  195. package/bin/live-share-turbo/internals/types.d.ts.map +0 -1
  196. package/bin/live-share-turbo/internals/types.js +0 -2
  197. package/bin/live-share-turbo/internals/types.js.map +0 -1
  198. package/bin/providers/FluidContextProvider.d.ts +0 -34
  199. package/bin/providers/FluidContextProvider.d.ts.map +0 -1
  200. package/bin/providers/FluidContextProvider.js +0 -99
  201. package/bin/providers/FluidContextProvider.js.map +0 -1
  202. package/bin/providers/LiveShareContextProvider.d.ts +0 -42
  203. package/bin/providers/LiveShareContextProvider.d.ts.map +0 -1
  204. package/bin/providers/LiveShareContextProvider.js +0 -63
  205. package/bin/providers/LiveShareContextProvider.js.map +0 -1
  206. package/bin/shared-hooks/useLockedTask.d.ts +0 -11
  207. package/bin/shared-hooks/useLockedTask.d.ts.map +0 -1
  208. package/bin/shared-hooks/useLockedTask.js +0 -82
  209. package/bin/shared-hooks/useLockedTask.js.map +0 -1
  210. package/bin/shared-hooks/useTaskManager.d.ts +0 -13
  211. package/bin/shared-hooks/useTaskManager.d.ts.map +0 -1
  212. package/bin/shared-hooks/useTaskManager.js +0 -86
  213. package/bin/shared-hooks/useTaskManager.js.map +0 -1
  214. package/bin/utils/getContainerSchema.d.ts +0 -8
  215. package/bin/utils/getContainerSchema.d.ts.map +0 -1
  216. package/bin/utils/getContainerSchema.js +0 -41
  217. package/bin/utils/getContainerSchema.js.map +0 -1
  218. package/src/internal-hooks/index.ts +0 -1
  219. package/src/shared-hooks/useTaskManager.ts +0 -82
  220. package/tinylicious.log +0 -4
@@ -1,68 +1,68 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- import React from "react";
15
- import { useFluidObjectsContext } from "../providers";
16
- /**
17
- * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
18
- * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
19
- * @param uniqueKey uniqueKey value for the data object
20
- * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
21
- * @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
22
- * @returns the DDS object, which is of type T when loaded and undefined while loading
23
- */
24
- export function useDynamicDDS(uniqueKey, loadableObjectClass, onFirstInitialize) {
25
- const [dds, setDDS] = React.useState();
26
- const [error, setError] = React.useState();
27
- /**
28
- * Import container and DDS object register callbacks from AzureProvider.
29
- */
30
- const { container, clientRef, } = useFluidObjectsContext();
31
- /**
32
- * Once container is available, this effect will register the setter method so that the DDS loaded
33
- * from `dynamicObjects` that matches `uniqueKey` can be passed back to this hook. If one does not yet exist,
34
- * a new DDS is automatically created. If multiple users try to create a DDS at the same time when this component first
35
- * mounts, `live-share-turbo` ensures it will ultimately self correct using last-writer wins.
36
- */
37
- React.useEffect(() => {
38
- if (container === undefined)
39
- return;
40
- let mounted = true;
41
- // Callback method to set the `initialData` into the map when the DDS is first created.
42
- const onGetDDS = () => __awaiter(this, void 0, void 0, function* () {
43
- try {
44
- const dds = yield clientRef.current.getDDS(uniqueKey, loadableObjectClass, onFirstInitialize);
45
- if (mounted) {
46
- setDDS(dds);
47
- }
48
- }
49
- catch (error) {
50
- if (error instanceof Error) {
51
- setError(error);
52
- }
53
- else {
54
- setError(new Error("useDynamicDDS: an unknown error occurred while getting the DDS"));
55
- }
56
- }
57
- });
58
- onGetDDS();
59
- return () => {
60
- mounted = false;
61
- };
62
- }, [container, uniqueKey, onFirstInitialize]);
63
- return {
64
- dds,
65
- error,
66
- };
67
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import React from "react";
15
+ import { useFluidObjectsContext } from "../providers";
16
+ /**
17
+ * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
18
+ * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
19
+ * @param uniqueKey uniqueKey value for the data object
20
+ * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
21
+ * @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
22
+ * @returns the DDS object, which is of type T when loaded and undefined while loading
23
+ */
24
+ export function useDynamicDDS(uniqueKey, loadableObjectClass, onFirstInitialize) {
25
+ const [dds, setDDS] = React.useState();
26
+ const [error, setError] = React.useState();
27
+ /**
28
+ * Import container and DDS object register callbacks from AzureProvider.
29
+ */
30
+ const { container, clientRef } = useFluidObjectsContext();
31
+ /**
32
+ * Once container is available, this effect will register the setter method so that the DDS loaded
33
+ * from `dynamicObjects` that matches `uniqueKey` can be passed back to this hook. If one does not yet exist,
34
+ * a new DDS is automatically created. If multiple users try to create a DDS at the same time when this component first
35
+ * mounts, `live-share-turbo` ensures it will ultimately self correct using last-writer wins.
36
+ */
37
+ React.useEffect(() => {
38
+ if (container === undefined)
39
+ return;
40
+ let mounted = true;
41
+ // Callback method to set the `initialData` into the map when the DDS is first created.
42
+ const onGetDDS = () => __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const dds = yield clientRef.current.getDDS(uniqueKey, loadableObjectClass, onFirstInitialize);
45
+ if (mounted) {
46
+ setDDS(dds);
47
+ }
48
+ }
49
+ catch (error) {
50
+ if (error instanceof Error) {
51
+ setError(error);
52
+ }
53
+ else {
54
+ setError(new Error("useDynamicDDS: an unknown error occurred while getting the DDS"));
55
+ }
56
+ }
57
+ });
58
+ onGetDDS();
59
+ return () => {
60
+ mounted = false;
61
+ };
62
+ }, [container, uniqueKey, onFirstInitialize]);
63
+ return {
64
+ dds,
65
+ error,
66
+ };
67
+ }
68
68
  //# sourceMappingURL=useDynamicDDS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDynamicDDS.js","sourceRoot":"","sources":["../../src/shared-hooks/useDynamicDDS.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CACzB,SAAiB,EACjB,mBAA2C,EAC3C,iBAAoC;IAKpC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAK,CAAC;IAC1C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAS,CAAC;IAClD;;OAEG;IACH,MAAM,EACF,SAAS,EACT,SAAS,GACZ,GAAG,sBAAsB,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO;QACpC,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,uFAAuF;QACvF,MAAM,QAAQ,GAAG,GAAS,EAAE;YACx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IAAI,SAAS,KAAK,SAAS;YAAE,OAAO;QACpC,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,uFAAuF;QACvF,MAAM,QAAQ,GAAG,GAAS,EAAE;YACxB,IAAI;gBACA,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CACtC,SAAS,EACT,mBAAmB,EACnB,iBAAiB,CACpB,CAAC;gBACF,IAAI,OAAO,EAAE;oBACT,MAAM,CAAC,GAAG,CAAC,CAAC;iBACf;aACJ;YAAC,OAAO,KAAc,EAAE;gBACrB,IAAI,KAAK,YAAY,KAAK,EAAE;oBACxB,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACnB;qBAAM;oBACH,QAAQ,CACJ,IAAI,KAAK,CACL,gEAAgE,CACnE,CACJ,CAAC;iBACL;aACJ;QACL,CAAC,CAAA,CAAC;QACF,QAAQ,EAAE,CAAC;QACX,OAAO,GAAG,EAAE;YACR,OAAO,GAAG,KAAK,CAAC;QACpB,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAE9C,OAAO;QACH,GAAG;QACH,KAAK;KACR,CAAC;AACN,CAAC"}
@@ -1,22 +1,22 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { IUseSharedMapResults, SharedMapInitialData } from "../types";
6
- /**
7
- * React hook for using a Fluid `SharedMap`.
8
- *
9
- * @remarks
10
- * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
11
- * directly is that it integrates nicely with React state and automates repetitive tasks.
12
- * If you want to use `SharedMap` this hook creates directly, you can do that as well.
13
- *
14
- * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
15
- * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
16
- * will be created, otherwise it will use the existing one.
17
- * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
18
- * the DDS for the first time.
19
- * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
20
- */
21
- export declare function useSharedMap<TData extends object = object>(uniqueKey: string, initialData?: SharedMapInitialData<TData>): IUseSharedMapResults<TData>;
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { IUseSharedMapResults, SharedMapInitialData } from "../types";
6
+ /**
7
+ * React hook for using a Fluid `SharedMap`.
8
+ *
9
+ * @remarks
10
+ * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
11
+ * directly is that it integrates nicely with React state and automates repetitive tasks.
12
+ * If you want to use `SharedMap` this hook creates directly, you can do that as well.
13
+ *
14
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `any` type.
15
+ * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
16
+ * will be created, otherwise it will use the existing one.
17
+ * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
18
+ * the DDS for the first time.
19
+ * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
20
+ */
21
+ export declare function useSharedMap<TData = any>(uniqueKey: string, initialData?: SharedMapInitialData<TData>): IUseSharedMapResults<TData>;
22
22
  //# sourceMappingURL=useSharedMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSharedMap.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAItE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACtD,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAC1C,oBAAoB,CAAC,KAAK,CAAC,CA8E7B"}
1
+ {"version":3,"file":"useSharedMap.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAStE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EACpC,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAC1C,oBAAoB,CAAC,KAAK,CAAC,CAmG7B"}
@@ -1,106 +1,113 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import React from "react";
6
- import { isEntries, isJSON, isMap } from "../utils";
7
- import { useDynamicDDS } from "./useDynamicDDS";
8
- import { SharedMap } from "fluid-framework";
9
- /**
10
- * React hook for using a Fluid `SharedMap`.
11
- *
12
- * @remarks
13
- * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
14
- * directly is that it integrates nicely with React state and automates repetitive tasks.
15
- * If you want to use `SharedMap` this hook creates directly, you can do that as well.
16
- *
17
- * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
18
- * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
19
- * will be created, otherwise it will use the existing one.
20
- * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
21
- * the DDS for the first time.
22
- * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
23
- */
24
- export function useSharedMap(uniqueKey, initialData) {
25
- /**
26
- * Stateful readonly map (user facing) with most recent values from `SharedMap` and its setter method.
27
- */
28
- const [map, setMap] = React.useState(getInitialData(initialData));
29
- const onFirstInitialize = React.useCallback((newDDS) => {
30
- /**
31
- * Callback method to set the `initialData` into the map when the `SharedMap` is first created.
32
- * Only should be used as a prop to useDynamicDDS.
33
- */
34
- getInitialData(initialData).forEach((value, key) => {
35
- newDDS.set(key, value);
36
- });
37
- }, [initialData]);
38
- /**
39
- * User facing: dynamically load the SharedMap DDS for the given unique key.
40
- */
41
- const { dds: sharedMap } = useDynamicDDS(uniqueKey, SharedMap, onFirstInitialize);
42
- /**
43
- * User facing: set a value to the Fluid `SharedMap`.
44
- */
45
- const setEntry = React.useCallback((key, value) => {
46
- if (!sharedMap) {
47
- console.error(new Error("Cannot call set when sharedMap is undefined"));
48
- return;
49
- }
50
- sharedMap.set(key, value);
51
- }, [sharedMap]);
52
- /**
53
- * User facing: delete a value from the Fluid `SharedMap`.
54
- */
55
- const deleteEntry = React.useCallback((key) => {
56
- if (!sharedMap) {
57
- console.error(new Error("Cannot call remove when sharedMap is undefined"));
58
- return;
59
- }
60
- sharedMap.delete(key);
61
- }, [sharedMap]);
62
- // Setup change listeners, initial values, etc.
63
- React.useEffect(() => {
64
- if (!sharedMap)
65
- return;
66
- // Register valueChanged listener for `SharedMap`.
67
- const onValueChanged = () => {
68
- setMap(new Map(sharedMap.entries()));
69
- };
70
- sharedMap.on("valueChanged", onValueChanged);
71
- // Get initial values from `SharedMap`.
72
- onValueChanged();
73
- return () => {
74
- // Cleanup on component unmount.
75
- sharedMap === null || sharedMap === void 0 ? void 0 : sharedMap.off("valueChanged", onValueChanged);
76
- };
77
- }, [sharedMap]);
78
- return {
79
- map,
80
- setEntry,
81
- deleteEntry,
82
- sharedMap,
83
- };
84
- }
85
- /**
86
- * Helper method for converting different initial data props into a Map<string, TData> to insert into the Fluid SharedMap
87
- * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
88
- * @param initialData a JS Map, entries array, or JSON object.
89
- * @returns A Map<string, TData> with the entries provided.
90
- */
91
- function getInitialData(initialData) {
92
- if (isMap(initialData)) {
93
- return initialData;
94
- }
95
- else if (isEntries(initialData)) {
96
- return new Map(initialData);
97
- }
98
- else if (isJSON(initialData)) {
99
- const values = Object.keys(initialData).map((key) => {
100
- return [key, initialData[key]];
101
- });
102
- return new Map(values);
103
- }
104
- return new Map();
105
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ import { isEntries, isJSON, isMap } from "../utils";
7
+ import { useDynamicDDS } from "./useDynamicDDS";
8
+ import { SharedMap } from "fluid-framework";
9
+ import { useFluidObjectsContext } from "../providers";
10
+ import { ActionContainerNotJoinedError, ActionLiveDataObjectUndefinedError, } from "../internal";
11
+ /**
12
+ * React hook for using a Fluid `SharedMap`.
13
+ *
14
+ * @remarks
15
+ * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
16
+ * directly is that it integrates nicely with React state and automates repetitive tasks.
17
+ * If you want to use `SharedMap` this hook creates directly, you can do that as well.
18
+ *
19
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `any` type.
20
+ * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
21
+ * will be created, otherwise it will use the existing one.
22
+ * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
23
+ * the DDS for the first time.
24
+ * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
25
+ */
26
+ export function useSharedMap(uniqueKey, initialData) {
27
+ /**
28
+ * Stateful readonly map (user facing) with most recent values from `SharedMap` and its setter method.
29
+ */
30
+ const [map, setMap] = React.useState(getInitialData(initialData));
31
+ const onFirstInitialize = React.useCallback((newDDS) => {
32
+ /**
33
+ * Callback method to set the `initialData` into the map when the `SharedMap` is first created.
34
+ * Only should be used as a prop to useDynamicDDS.
35
+ */
36
+ getInitialData(initialData).forEach((value, key) => {
37
+ newDDS.set(key, value);
38
+ });
39
+ }, [initialData]);
40
+ /**
41
+ * User facing: dynamically load the SharedMap DDS for the given unique key.
42
+ */
43
+ const { dds: sharedMap } = useDynamicDDS(uniqueKey, SharedMap, onFirstInitialize);
44
+ const { container } = useFluidObjectsContext();
45
+ /**
46
+ * User facing: set a value to the Fluid `SharedMap`.
47
+ */
48
+ const setEntry = React.useCallback((key, value) => {
49
+ if (!container) {
50
+ throw new ActionContainerNotJoinedError("sharedMap", "setEntry");
51
+ }
52
+ if (sharedMap === undefined) {
53
+ throw new ActionLiveDataObjectUndefinedError("sharedMap", "setEntry");
54
+ }
55
+ sharedMap.set(key, value);
56
+ }, [container, sharedMap]);
57
+ /**
58
+ * User facing: delete a value from the Fluid `SharedMap`.
59
+ */
60
+ const deleteEntry = React.useCallback((key) => {
61
+ if (!container) {
62
+ throw new ActionContainerNotJoinedError("sharedMap", "deleteEntry");
63
+ }
64
+ if (sharedMap === undefined) {
65
+ throw new ActionLiveDataObjectUndefinedError("sharedMap", "deleteEntry");
66
+ }
67
+ sharedMap.delete(key);
68
+ }, [container, sharedMap]);
69
+ // Setup change listeners, initial values, etc.
70
+ React.useEffect(() => {
71
+ if (!sharedMap)
72
+ return;
73
+ // Register valueChanged listener for `SharedMap`.
74
+ const onValueChanged = () => {
75
+ setMap(new Map(sharedMap.entries()));
76
+ };
77
+ sharedMap.on("valueChanged", onValueChanged);
78
+ // Get initial values from `SharedMap`.
79
+ onValueChanged();
80
+ return () => {
81
+ // Cleanup on component unmount.
82
+ sharedMap === null || sharedMap === void 0 ? void 0 : sharedMap.off("valueChanged", onValueChanged);
83
+ };
84
+ }, [sharedMap]);
85
+ return {
86
+ map,
87
+ setEntry,
88
+ deleteEntry,
89
+ sharedMap,
90
+ };
91
+ }
92
+ /**
93
+ * Helper method for converting different initial data props into a Map<string, TData> to insert into the Fluid SharedMap
94
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
95
+ * @param initialData a JS Map, entries array, or JSON object.
96
+ * @returns A Map<string, TData> with the entries provided.
97
+ */
98
+ function getInitialData(initialData) {
99
+ if (isMap(initialData)) {
100
+ return initialData;
101
+ }
102
+ else if (isEntries(initialData)) {
103
+ return new Map(initialData);
104
+ }
105
+ else if (isJSON(initialData)) {
106
+ const values = Object.keys(initialData).map((key) => {
107
+ return [key, initialData[key]];
108
+ });
109
+ return new Map(values);
110
+ }
111
+ return new Map();
112
+ }
106
113
  //# sourceMappingURL=useSharedMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSharedMap.js","sourceRoot":"","sources":["../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,WAAyC;IAEzC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAChC,cAAc,CAAQ,WAAW,CAAC,CACrC,CAAC;IAEF,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,MAAiB,EAAQ,EAAE;QACpE;;;WAGG;QACH,cAAc,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CAAY,SAAS,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAE7F;;OAEG;IACH,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAC9B,CAAC,GAAW,EAAE,KAAY,EAAE,EAAE;QAC1B,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,CAAC,KAAK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B,MAAM,CAAC,IAAI,GAAG,CAAgB,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC;QACF,SAAS,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAC7C,uCAAuC;QACvC,cAAc,EAAE,CAAC;QAEjB,OAAO,GAAG,EAAE;YACR,gCAAgC;YAChC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QACnD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,GAAG;QACH,QAAQ;QACR,WAAW;QACX,SAAS;KACZ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CACnB,WAAwC;IAExC,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE;QACpB,OAAO,WAAW,CAAC;KACtB;SAAM,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE;QAC/B,OAAO,IAAI,GAAG,CAAgB,WAAW,CAAC,CAAC;KAC9C;SAAM,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE;QAC5B,MAAM,MAAM,GAAiC,MAAM,CAAC,IAAI,CACpD,WAAW,CACd,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACV,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,GAAG,CAAgB,MAAM,CAAC,CAAC;KACzC;IACD,OAAO,IAAI,GAAG,EAAiB,CAAC;AACpC,CAAC"}
@@ -1,21 +1,21 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { DisposeSharedStateAction, SetSharedStateAction } from "../types";
6
- /**
7
- * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
8
- *
9
- * @remarks
10
- * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
11
- * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
12
- * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
13
- *
14
- * @template S Typing for objects stored associated with the `uniqueKey`.
15
- * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
16
- * @param initialState a default state for the `SharedMap`.
17
- *
18
- * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
19
- */
20
- export declare function useSharedState<S>(uniqueKey: string, initialState: S): [S, SetSharedStateAction<S>, DisposeSharedStateAction];
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { DisposeSharedStateAction, SetSharedStateAction } from "../types";
6
+ /**
7
+ * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
8
+ *
9
+ * @remarks
10
+ * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
11
+ * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
12
+ * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
13
+ *
14
+ * @template S Typing for objects stored associated with the `uniqueKey`.
15
+ * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
16
+ * @param initialState a default state for the `SharedMap`.
17
+ *
18
+ * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
19
+ */
20
+ export declare function useSharedState<S = any>(uniqueKey: string, initialState: S): [S, SetSharedStateAction<S>, DisposeSharedStateAction];
21
21
  //# sourceMappingURL=useSharedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSharedState.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,GAChB,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAyDxD"}
1
+ {"version":3,"file":"useSharedState.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAI1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,GAAG,EAClC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,GAChB,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAkExD"}
@@ -1,63 +1,73 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import React from "react";
6
- import { useFluidObjectsContext } from "../providers";
7
- import { v4 as uuid } from "uuid";
8
- /**
9
- * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
10
- *
11
- * @remarks
12
- * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
13
- * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
14
- * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
15
- *
16
- * @template S Typing for objects stored associated with the `uniqueKey`.
17
- * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
18
- * @param initialState a default state for the `SharedMap`.
19
- *
20
- * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
21
- */
22
- export function useSharedState(uniqueKey, initialState) {
23
- /**
24
- * User facing: stateful value and non-user facing setter.
25
- */
26
- const [localState, setLocalState] = React.useState(initialState);
27
- /**
28
- * Unique ID reference for the component.
29
- */
30
- const componentIdRef = React.useRef(uuid());
31
- /**
32
- * Register set state callbacks from AzureProvider and update/delete callbacks for initial object's `stateMap`.
33
- */
34
- const { registerSharedSetStateAction, unregisterSharedSetStateAction, updateSharedState, deleteSharedState, } = useFluidObjectsContext();
35
- /**
36
- * User facing: callback to change the shared state.
37
- */
38
- const setSharedState = React.useCallback((updatedState) => {
39
- setLocalState(updatedState);
40
- updateSharedState(uniqueKey, updatedState);
41
- }, [uniqueKey, setLocalState, updateSharedState]);
42
- /**
43
- * User facing: callback to dispose the shared state from the `stateMap`.
44
- */
45
- const disposeSharedState = React.useCallback(() => {
46
- deleteSharedState(uniqueKey);
47
- }, [uniqueKey, deleteSharedState]);
48
- /**
49
- * Once container is available, this effect will register the setter method so that the `S` value
50
- * from `stateMap` that matches `uniqueKey` can be passed back to this hook whenever changed.
51
- *
52
- * @see registerSharedSetStateAction to see how new values from `stateMap` are passed to this hook.
53
- * @see unregisterSharedSetStateAction to see how this component stops listening to changes in the `stateMap`.
54
- */
55
- React.useEffect(() => {
56
- registerSharedSetStateAction(uniqueKey, componentIdRef.current, setLocalState);
57
- return () => {
58
- unregisterSharedSetStateAction(uniqueKey, componentIdRef.current);
59
- };
60
- }, [uniqueKey, registerSharedSetStateAction, unregisterSharedSetStateAction]);
61
- return [localState, setSharedState, disposeSharedState];
62
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ import { useFluidObjectsContext } from "../providers";
7
+ import { v4 as uuid } from "uuid";
8
+ import { isPrevStateCallback } from "../internal";
9
+ /**
10
+ * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
11
+ *
12
+ * @remarks
13
+ * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
14
+ * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
15
+ * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
16
+ *
17
+ * @template S Typing for objects stored associated with the `uniqueKey`.
18
+ * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
19
+ * @param initialState a default state for the `SharedMap`.
20
+ *
21
+ * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
22
+ */
23
+ export function useSharedState(uniqueKey, initialState) {
24
+ /**
25
+ * User facing: stateful value and non-user facing setter.
26
+ */
27
+ const [localState, setLocalState] = React.useState(initialState);
28
+ /**
29
+ * Unique ID reference for the component.
30
+ */
31
+ const componentIdRef = React.useRef(uuid());
32
+ /**
33
+ * Register set state callbacks from AzureProvider and update/delete callbacks for initial object's `stateMap`.
34
+ */
35
+ const { registerSharedSetStateAction, unregisterSharedSetStateAction, updateSharedState, deleteSharedState, } = useFluidObjectsContext();
36
+ /**
37
+ * User facing: callback to change the shared state.
38
+ */
39
+ const setSharedState = React.useCallback((state) => {
40
+ setLocalState((prevState) => {
41
+ const valueToSet = isPrevStateCallback(state)
42
+ ? state(prevState)
43
+ : state;
44
+ updateSharedState(uniqueKey, valueToSet);
45
+ return valueToSet;
46
+ });
47
+ }, [uniqueKey, setLocalState, updateSharedState]);
48
+ /**
49
+ * User facing: callback to dispose the shared state from the `stateMap`.
50
+ */
51
+ const disposeSharedState = React.useCallback(() => {
52
+ deleteSharedState(uniqueKey);
53
+ }, [uniqueKey, deleteSharedState]);
54
+ /**
55
+ * Once container is available, this effect will register the setter method so that the `S` value
56
+ * from `stateMap` that matches `uniqueKey` can be passed back to this hook whenever changed.
57
+ *
58
+ * @see registerSharedSetStateAction to see how new values from `stateMap` are passed to this hook.
59
+ * @see unregisterSharedSetStateAction to see how this component stops listening to changes in the `stateMap`.
60
+ */
61
+ React.useEffect(() => {
62
+ registerSharedSetStateAction(uniqueKey, componentIdRef.current, setLocalState);
63
+ return () => {
64
+ unregisterSharedSetStateAction(uniqueKey, componentIdRef.current);
65
+ };
66
+ }, [
67
+ uniqueKey,
68
+ registerSharedSetStateAction,
69
+ unregisterSharedSetStateAction,
70
+ ]);
71
+ return [localState, setSharedState, disposeSharedState];
72
+ }
63
73
  //# sourceMappingURL=useSharedState.js.map