@microsoft/live-share-react 1.0.0-preview.9 → 1.0.2-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.
- package/README.md +99 -35
- package/bin/index.d.ts +6 -6
- package/bin/index.js +6 -6
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +25 -8
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -1
- package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
- package/bin/interfaces/index.d.ts +1 -1
- package/bin/interfaces/index.js +1 -1
- package/bin/internal/errors.d.ts +26 -0
- package/bin/internal/errors.d.ts.map +1 -0
- package/bin/internal/errors.js +39 -0
- package/bin/internal/errors.js.map +1 -0
- package/bin/internal/index.d.ts +4 -0
- package/bin/internal/index.d.ts.map +1 -0
- package/bin/internal/index.js +4 -0
- package/bin/internal/index.js.map +1 -0
- package/bin/internal/type-guards.d.ts +6 -0
- package/bin/internal/type-guards.d.ts.map +1 -0
- package/bin/internal/type-guards.js +8 -0
- package/bin/internal/type-guards.js.map +1 -0
- package/bin/{internal-hooks → internal}/useSharedStateRegistry.d.ts +30 -30
- package/bin/internal/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/{internal-hooks → internal}/useSharedStateRegistry.js +101 -99
- package/bin/internal/useSharedStateRegistry.js.map +1 -0
- package/bin/live-hooks/index.d.ts +6 -6
- package/bin/live-hooks/index.js +6 -6
- package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
- package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -1
- package/bin/live-hooks/useLiveCanvas.js +158 -166
- package/bin/live-hooks/useLiveCanvas.js.map +1 -1
- package/bin/live-hooks/useLiveEvent.d.ts +21 -21
- package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
- package/bin/live-hooks/useLiveEvent.js +100 -85
- package/bin/live-hooks/useLiveEvent.js.map +1 -1
- package/bin/live-hooks/useLivePresence.d.ts +25 -25
- package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
- package/bin/live-hooks/useLivePresence.js +106 -92
- package/bin/live-hooks/useLivePresence.js.map +1 -1
- package/bin/live-hooks/useLiveState.d.ts +19 -19
- package/bin/live-hooks/useLiveState.d.ts.map +1 -1
- package/bin/live-hooks/useLiveState.js +79 -70
- package/bin/live-hooks/useLiveState.js.map +1 -1
- package/bin/live-hooks/useLiveTimer.d.ts +7 -7
- package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
- package/bin/live-hooks/useLiveTimer.js +150 -131
- package/bin/live-hooks/useLiveTimer.js.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.js +206 -161
- package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
- package/bin/providers/AzureProvider.d.ts +33 -33
- package/bin/providers/AzureProvider.d.ts.map +1 -1
- package/bin/providers/AzureProvider.js +101 -101
- package/bin/providers/AzureProvider.js.map +1 -1
- package/bin/providers/LiveShareProvider.d.ts +62 -41
- package/bin/providers/LiveShareProvider.d.ts.map +1 -1
- package/bin/providers/LiveShareProvider.js +68 -65
- package/bin/providers/LiveShareProvider.js.map +1 -1
- package/bin/providers/index.d.ts +2 -2
- package/bin/providers/index.js +2 -2
- package/bin/shared-hooks/index.d.ts +3 -4
- package/bin/shared-hooks/index.d.ts.map +1 -1
- package/bin/shared-hooks/index.js +3 -4
- package/bin/shared-hooks/index.js.map +1 -1
- package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
- package/bin/shared-hooks/useDynamicDDS.js +67 -67
- package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
- package/bin/shared-hooks/useSharedMap.d.ts +21 -21
- package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedMap.js +112 -105
- package/bin/shared-hooks/useSharedMap.js.map +1 -1
- package/bin/shared-hooks/useSharedState.d.ts +20 -20
- package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedState.js +72 -62
- package/bin/shared-hooks/useSharedState.js.map +1 -1
- package/bin/types/ActionTypes.d.ts +111 -29
- package/bin/types/ActionTypes.d.ts.map +1 -1
- package/bin/types/ActionTypes.js +5 -5
- package/bin/types/PropTypes.d.ts +7 -7
- package/bin/types/PropTypes.d.ts.map +1 -1
- package/bin/types/PropTypes.js +5 -5
- package/bin/types/ResultTypes.d.ts +174 -162
- package/bin/types/ResultTypes.d.ts.map +1 -1
- package/bin/types/ResultTypes.js +5 -5
- package/bin/types/index.d.ts +3 -3
- package/bin/types/index.js +3 -3
- package/bin/utils/index.d.ts +1 -1
- package/bin/utils/index.js +1 -1
- package/bin/utils/type-check.d.ts +14 -14
- package/bin/utils/type-check.js +53 -53
- package/package.json +18 -14
- package/src/interfaces/LiveInterfaceExtensions.ts +19 -2
- package/src/internal/errors.ts +48 -0
- package/src/internal/index.ts +3 -0
- package/src/internal/type-guards.ts +9 -0
- package/src/{internal-hooks → internal}/useSharedStateRegistry.ts +6 -5
- package/src/live-hooks/useLiveCanvas.ts +12 -20
- package/src/live-hooks/useLiveEvent.ts +41 -22
- package/src/live-hooks/useLivePresence.ts +52 -33
- package/src/live-hooks/useLiveState.ts +48 -53
- package/src/live-hooks/useLiveTimer.ts +50 -41
- package/src/live-hooks/useMediaSynchronizer.ts +108 -41
- package/src/providers/AzureProvider.tsx +3 -8
- package/src/providers/LiveShareProvider.tsx +46 -16
- package/src/shared-hooks/index.ts +0 -1
- package/src/shared-hooks/useDynamicDDS.ts +15 -8
- package/src/shared-hooks/useSharedMap.ts +48 -22
- package/src/shared-hooks/useSharedState.ts +15 -5
- package/src/types/ActionTypes.ts +100 -15
- package/src/types/ResultTypes.ts +23 -9
- package/bin/internal-hooks/index.d.ts +0 -2
- package/bin/internal-hooks/index.d.ts.map +0 -1
- package/bin/internal-hooks/index.js +0 -2
- package/bin/internal-hooks/index.js.map +0 -1
- package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +0 -14
- package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +0 -1
- package/bin/internal-hooks/useDynamicDDSRegistry.js +0 -142
- package/bin/internal-hooks/useDynamicDDSRegistry.js.map +0 -1
- package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/internal-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/internal-hooks/useStateRef.d.ts +0 -7
- package/bin/internal-hooks/useStateRef.d.ts.map +0 -1
- package/bin/internal-hooks/useStateRef.js +0 -15
- package/bin/internal-hooks/useStateRef.js.map +0 -1
- package/bin/live-hooks/useLiveAICompletion.d.ts +0 -29
- package/bin/live-hooks/useLiveAICompletion.d.ts.map +0 -1
- package/bin/live-hooks/useLiveAICompletion.js +0 -186
- package/bin/live-hooks/useLiveAICompletion.js.map +0 -1
- package/bin/live-hooks/useLiveCoPilot.d.ts +0 -28
- package/bin/live-hooks/useLiveCoPilot.d.ts.map +0 -1
- package/bin/live-hooks/useLiveCoPilot.js +0 -178
- package/bin/live-hooks/useLiveCoPilot.js.map +0 -1
- package/bin/live-share-turbo/AzureTurboClient.d.ts +0 -39
- package/bin/live-share-turbo/AzureTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/AzureTurboClient.js +0 -56
- package/bin/live-share-turbo/AzureTurboClient.js.map +0 -1
- package/bin/live-share-turbo/LiveShareTurboClient.d.ts +0 -53
- package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/LiveShareTurboClient.js +0 -69
- package/bin/live-share-turbo/LiveShareTurboClient.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +0 -31
- package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboDataObject.js +0 -75
- package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +0 -48
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +0 -104
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +0 -28
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +0 -68
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +0 -60
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +0 -111
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +0 -77
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +0 -137
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +0 -30
- package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveState.js +0 -74
- package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +0 -61
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +0 -108
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/index.d.ts +0 -8
- package/bin/live-share-turbo/dds-objects/index.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/index.js +0 -8
- package/bin/live-share-turbo/dds-objects/index.js.map +0 -1
- package/bin/live-share-turbo/index.d.ts +0 -5
- package/bin/live-share-turbo/index.d.ts.map +0 -1
- package/bin/live-share-turbo/index.js +0 -5
- package/bin/live-share-turbo/index.js.map +0 -1
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +0 -15
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +0 -2
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +0 -1
- package/bin/live-share-turbo/interfaces/index.d.ts +0 -3
- package/bin/live-share-turbo/interfaces/index.d.ts.map +0 -1
- package/bin/live-share-turbo/interfaces/index.js +0 -3
- package/bin/live-share-turbo/interfaces/index.js.map +0 -1
- package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +0 -39
- package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/FluidTurboClient.js +0 -121
- package/bin/live-share-turbo/internals/FluidTurboClient.js.map +0 -1
- package/bin/live-share-turbo/internals/index.d.ts +0 -2
- package/bin/live-share-turbo/internals/index.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/index.js +0 -2
- package/bin/live-share-turbo/internals/index.js.map +0 -1
- package/bin/live-share-turbo/internals/types.d.ts +0 -4
- package/bin/live-share-turbo/internals/types.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/types.js +0 -2
- package/bin/live-share-turbo/internals/types.js.map +0 -1
- package/bin/providers/FluidContextProvider.d.ts +0 -34
- package/bin/providers/FluidContextProvider.d.ts.map +0 -1
- package/bin/providers/FluidContextProvider.js +0 -99
- package/bin/providers/FluidContextProvider.js.map +0 -1
- package/bin/providers/LiveShareContextProvider.d.ts +0 -42
- package/bin/providers/LiveShareContextProvider.d.ts.map +0 -1
- package/bin/providers/LiveShareContextProvider.js +0 -63
- package/bin/providers/LiveShareContextProvider.js.map +0 -1
- package/bin/shared-hooks/useLockedTask.d.ts +0 -11
- package/bin/shared-hooks/useLockedTask.d.ts.map +0 -1
- package/bin/shared-hooks/useLockedTask.js +0 -82
- package/bin/shared-hooks/useLockedTask.js.map +0 -1
- package/bin/shared-hooks/useTaskManager.d.ts +0 -13
- package/bin/shared-hooks/useTaskManager.d.ts.map +0 -1
- package/bin/shared-hooks/useTaskManager.js +0 -86
- package/bin/shared-hooks/useTaskManager.js.map +0 -1
- package/bin/utils/getContainerSchema.d.ts +0 -8
- package/bin/utils/getContainerSchema.d.ts.map +0 -1
- package/bin/utils/getContainerSchema.js +0 -41
- package/bin/utils/getContainerSchema.js.map +0 -1
- package/src/internal-hooks/index.ts +0 -1
- package/src/shared-hooks/useTaskManager.ts +0 -82
- 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
|
|
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,C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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 `
|
|
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
|
|
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;
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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,EA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AS,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;
|
|
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
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @param
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}, [uniqueKey,
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|