@microsoft/live-share-react 1.0.0-preview.10 → 1.0.0-preview.11
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 +88 -21
- package/package.json +13 -9
- package/src/live-hooks/useLiveCanvas.ts +11 -19
- package/src/live-hooks/useLiveEvent.ts +1 -1
- package/src/live-hooks/useLivePresence.ts +10 -9
- package/src/shared-hooks/index.ts +0 -1
- package/src/types/ActionTypes.ts +1 -1
- package/bin/index.d.ts +0 -7
- package/bin/index.d.ts.map +0 -1
- package/bin/index.js +0 -7
- package/bin/index.js.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +0 -9
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.js +0 -6
- package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
- package/bin/interfaces/index.d.ts +0 -2
- package/bin/interfaces/index.d.ts.map +0 -1
- package/bin/interfaces/index.js +0 -2
- package/bin/interfaces/index.js.map +0 -1
- 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 +0 -31
- package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/internal-hooks/useSharedStateRegistry.js +0 -100
- 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/index.d.ts +0 -7
- package/bin/live-hooks/index.d.ts.map +0 -1
- package/bin/live-hooks/index.js +0 -7
- package/bin/live-hooks/index.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/useLiveCanvas.d.ts +0 -28
- package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
- package/bin/live-hooks/useLiveCanvas.js +0 -167
- package/bin/live-hooks/useLiveCanvas.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-hooks/useLiveEvent.d.ts +0 -22
- package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
- package/bin/live-hooks/useLiveEvent.js +0 -86
- package/bin/live-hooks/useLiveEvent.js.map +0 -1
- package/bin/live-hooks/useLivePresence.d.ts +0 -26
- package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
- package/bin/live-hooks/useLivePresence.js +0 -93
- package/bin/live-hooks/useLivePresence.js.map +0 -1
- package/bin/live-hooks/useLiveState.d.ts +0 -19
- package/bin/live-hooks/useLiveState.d.ts.map +0 -1
- package/bin/live-hooks/useLiveState.js +0 -61
- package/bin/live-hooks/useLiveState.js.map +0 -1
- package/bin/live-hooks/useLiveTimer.d.ts +0 -8
- package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
- package/bin/live-hooks/useLiveTimer.js +0 -132
- package/bin/live-hooks/useLiveTimer.js.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -23
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.js +0 -162
- package/bin/live-hooks/useMediaSynchronizer.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/AzureProvider.d.ts +0 -34
- package/bin/providers/AzureProvider.d.ts.map +0 -1
- package/bin/providers/AzureProvider.js +0 -102
- package/bin/providers/AzureProvider.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/providers/LiveShareProvider.d.ts +0 -42
- package/bin/providers/LiveShareProvider.d.ts.map +0 -1
- package/bin/providers/LiveShareProvider.js +0 -66
- package/bin/providers/LiveShareProvider.js.map +0 -1
- package/bin/providers/index.d.ts +0 -3
- package/bin/providers/index.d.ts.map +0 -1
- package/bin/providers/index.js +0 -3
- package/bin/providers/index.js.map +0 -1
- package/bin/shared-hooks/index.d.ts +0 -5
- package/bin/shared-hooks/index.d.ts.map +0 -1
- package/bin/shared-hooks/index.js +0 -5
- package/bin/shared-hooks/index.js.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.d.ts +0 -19
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.js +0 -68
- package/bin/shared-hooks/useDynamicDDS.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/useSharedMap.d.ts +0 -22
- package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedMap.js +0 -106
- package/bin/shared-hooks/useSharedMap.js.map +0 -1
- package/bin/shared-hooks/useSharedState.d.ts +0 -21
- package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedState.js +0 -63
- package/bin/shared-hooks/useSharedState.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/types/ActionTypes.d.ts +0 -30
- package/bin/types/ActionTypes.d.ts.map +0 -1
- package/bin/types/ActionTypes.js +0 -6
- package/bin/types/ActionTypes.js.map +0 -1
- package/bin/types/PropTypes.d.ts +0 -8
- package/bin/types/PropTypes.d.ts.map +0 -1
- package/bin/types/PropTypes.js +0 -6
- package/bin/types/PropTypes.js.map +0 -1
- package/bin/types/ResultTypes.d.ts +0 -163
- package/bin/types/ResultTypes.d.ts.map +0 -1
- package/bin/types/ResultTypes.js +0 -6
- package/bin/types/ResultTypes.js.map +0 -1
- package/bin/types/index.d.ts +0 -4
- package/bin/types/index.d.ts.map +0 -1
- package/bin/types/index.js +0 -4
- package/bin/types/index.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/bin/utils/index.d.ts +0 -2
- package/bin/utils/index.d.ts.map +0 -1
- package/bin/utils/index.js +0 -2
- package/bin/utils/index.js.map +0 -1
- package/bin/utils/type-check.d.ts +0 -15
- package/bin/utils/type-check.d.ts.map +0 -1
- package/bin/utils/type-check.js +0 -54
- package/bin/utils/type-check.js.map +0 -1
- package/src/shared-hooks/useTaskManager.ts +0 -82
- package/tinylicious.log +0 -4
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import React from "react";
|
|
12
|
-
import { useSharedStateRegistry } from "../internal-hooks";
|
|
13
|
-
import { FluidContext } from "./AzureProvider";
|
|
14
|
-
import { LiveShareTurboClient } from "@microsoft/live-share-turbo";
|
|
15
|
-
export const LiveShareContext = React.createContext({});
|
|
16
|
-
export const useLiveShareContext = () => {
|
|
17
|
-
const context = React.useContext(LiveShareContext);
|
|
18
|
-
return context;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
|
|
22
|
-
*/
|
|
23
|
-
export const LiveShareProvider = (props) => {
|
|
24
|
-
const startedRef = React.useRef(false);
|
|
25
|
-
const clientRef = React.useRef(new LiveShareTurboClient(props.host, props.clientOptions));
|
|
26
|
-
const [results, setResults] = React.useState();
|
|
27
|
-
const [joinError, setJoinError] = React.useState();
|
|
28
|
-
const stateRegistryCallbacks = useSharedStateRegistry(results);
|
|
29
|
-
/**
|
|
30
|
-
* Join container callback for joining the Live Share session
|
|
31
|
-
*/
|
|
32
|
-
const join = React.useCallback((initialObjects, onInitializeContainer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
startedRef.current = true;
|
|
34
|
-
const results = yield clientRef.current.join(initialObjects, onInitializeContainer);
|
|
35
|
-
setResults(results);
|
|
36
|
-
return results;
|
|
37
|
-
}), []);
|
|
38
|
-
/**
|
|
39
|
-
* Joins the container on load if `props.joinOnLoad` is true
|
|
40
|
-
*/
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
// This hook should only be called once, so we use a ref to track if it has been called.
|
|
43
|
-
// This is a workaround for the fact that useEffect is called twice on initial render in React V18.
|
|
44
|
-
// We are not doing this here for backwards compatibility. View the README for more information.
|
|
45
|
-
if (results !== undefined || startedRef.current || !props.joinOnLoad)
|
|
46
|
-
return;
|
|
47
|
-
join(props.initialObjects).catch((error) => {
|
|
48
|
-
console.log(error);
|
|
49
|
-
if (error instanceof Error) {
|
|
50
|
-
setJoinError(error);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
setJoinError(new Error("LiveShareProvider: An unknown error occurred while joining container."));
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}, [results, props.joinOnLoad, props.initialObjects, join]);
|
|
57
|
-
return (_jsx(LiveShareContext.Provider, Object.assign({ value: {
|
|
58
|
-
created: results === null || results === void 0 ? void 0 : results.created,
|
|
59
|
-
join,
|
|
60
|
-
} }, { children: _jsx(FluidContext.Provider, Object.assign({ value: Object.assign({ clientRef, container: results === null || results === void 0 ? void 0 : results.container, services: results === null || results === void 0 ? void 0 : results.services, joinError, getContainer: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
throw new Error("Cannot join new container through getContainer in LiveShareProvider");
|
|
62
|
-
}), createContainer: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
throw new Error("Cannot create new container through createContainer in LiveShareProvider");
|
|
64
|
-
}) }, stateRegistryCallbacks) }, { children: props.children })) })));
|
|
65
|
-
};
|
|
66
|
-
//# s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CAAC,CAAA,EACD,eAAe,EAAE,GAAS,EAAE;oBACxB,MAAM,IAAI,KAAK,CACX,0EAA0E,CAC7E,CAAC;gBACN,CAAC,CAAA,IACE,sBAAsB,iBAG5B,KAAK,CAAC,QAAQ,IACK,IACA,CAC/B,CAAC;AACN,CAAC,CAAC"}
|
package/bin/providers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
package/bin/providers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
import { FluidObject, IFluidLoadable } from "@fluidframework/core-interfaces";
|
|
6
|
-
import { LoadableObjectClass } from "fluid-framework";
|
|
7
|
-
/**
|
|
8
|
-
* Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
|
|
9
|
-
* @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
|
|
10
|
-
* @param uniqueKey uniqueKey value for the data object
|
|
11
|
-
* @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
|
|
12
|
-
* @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
|
|
13
|
-
* @returns the DDS object, which is of type T when loaded and undefined while loading
|
|
14
|
-
*/
|
|
15
|
-
export declare function useDynamicDDS<T extends IFluidLoadable = FluidObject<any> & IFluidLoadable>(uniqueKey: string, loadableObjectClass: LoadableObjectClass<T>, onFirstInitialize?: (dds: T) => void): {
|
|
16
|
-
dds: T | undefined;
|
|
17
|
-
error: Error | undefined;
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=useDynamicDDS.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicDDS.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useDynamicDDS.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,EACtF,SAAS,EAAE,MAAM,EACjB,mBAAmB,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC3C,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GACrC;IACC,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC5B,CA6CA"}
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=useDynamicDDS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;YACxB,IAAI;gBACA,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAI,SAAS,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CAAC;gBACjG,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,CAAC,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC,CAAC;iBACzF;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,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
|
|
3
|
-
*
|
|
4
|
-
* @param uniqueKey the unique key for the TaskManager DDS
|
|
5
|
-
* @param taskId the task id to lock
|
|
6
|
-
* @returns stateful data about the status of the task lock
|
|
7
|
-
*/
|
|
8
|
-
export declare const useLockedTask: (uniqueKey: string, taskId?: string) => {
|
|
9
|
-
lockedTask: boolean;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=useLockedTask.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLockedTask.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useLockedTask.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,cAAe,MAAM,WAAW,MAAM;gBAChD,OAAO;CA+DtB,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import React, { useEffect } from "react";
|
|
11
|
-
import { TaskManager } from "@fluid-experimental/task-manager";
|
|
12
|
-
import { useDynamicDDS } from "./useDynamicDDS";
|
|
13
|
-
/**
|
|
14
|
-
* A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
|
|
15
|
-
*
|
|
16
|
-
* @param uniqueKey the unique key for the TaskManager DDS
|
|
17
|
-
* @param taskId the task id to lock
|
|
18
|
-
* @returns stateful data about the status of the task lock
|
|
19
|
-
*/
|
|
20
|
-
export const useLockedTask = (uniqueKey, taskId) => {
|
|
21
|
-
/**
|
|
22
|
-
* TaskId currently in queue for
|
|
23
|
-
*/
|
|
24
|
-
const currentTaskIdRef = React.useRef(undefined);
|
|
25
|
-
/**
|
|
26
|
-
* Stateful boolean that is true when the user is currently assigned the task
|
|
27
|
-
*/
|
|
28
|
-
const [lockedTask, setLockedTask] = React.useState(false);
|
|
29
|
-
/**
|
|
30
|
-
* User facing: dynamically load the TaskManager DDS for the given unique key.
|
|
31
|
-
*/
|
|
32
|
-
const { dds: taskManager } = useDynamicDDS(uniqueKey, TaskManager);
|
|
33
|
-
/**
|
|
34
|
-
* When the task id changes, lock the task. When the task id is undefined, abandon the task.
|
|
35
|
-
*/
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
let mounted = true;
|
|
38
|
-
if (taskManager) {
|
|
39
|
-
if (taskId && currentTaskIdRef.current !== taskId) {
|
|
40
|
-
if (currentTaskIdRef.current) {
|
|
41
|
-
taskManager.abandon(currentTaskIdRef.current);
|
|
42
|
-
setLockedTask(false);
|
|
43
|
-
}
|
|
44
|
-
currentTaskIdRef.current = taskId;
|
|
45
|
-
const onLockTask = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
try {
|
|
47
|
-
yield taskManager.lockTask(taskId);
|
|
48
|
-
if (mounted) {
|
|
49
|
-
setLockedTask(true);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (_a) {
|
|
53
|
-
if (mounted) {
|
|
54
|
-
setLockedTask(false);
|
|
55
|
-
currentTaskIdRef.current = undefined;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
onLockTask();
|
|
60
|
-
}
|
|
61
|
-
else if (!taskId && currentTaskIdRef.current) {
|
|
62
|
-
taskManager.abandon(currentTaskIdRef.current);
|
|
63
|
-
setLockedTask(false);
|
|
64
|
-
currentTaskIdRef.current = undefined;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* When the component unmounts, abandon the task if it is still locked
|
|
69
|
-
*/
|
|
70
|
-
return () => {
|
|
71
|
-
mounted = false;
|
|
72
|
-
if (currentTaskIdRef.current) {
|
|
73
|
-
taskManager === null || taskManager === void 0 ? void 0 : taskManager.abandon(currentTaskIdRef.current);
|
|
74
|
-
}
|
|
75
|
-
currentTaskIdRef.current = undefined;
|
|
76
|
-
};
|
|
77
|
-
}, [taskManager, taskId]);
|
|
78
|
-
return {
|
|
79
|
-
lockedTask,
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
//# sourceMappingURL=useLockedTask.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLockedTask.js","sourceRoot":"","sources":["../../src/shared-hooks/useLockedTask.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,MAAe,EAE9D,EAAE;IACA;;OAEG;IACH,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAqB,SAAS,CAAC,CAAC;IACrE;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAU,KAAK,CAAC,CAAC;IAEnE;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,aAAa,CAAc,SAAS,EAAE,WAAW,CAAC,CAAC;IAEhF;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,WAAW,EAAE;YACb,IAAI,MAAM,IAAI,gBAAgB,CAAC,OAAO,KAAK,MAAM,EAAE;gBAC/C,IAAI,gBAAgB,CAAC,OAAO,EAAE;oBAC1B,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;oBAC9C,aAAa,CAAC,KAAK,CAAC,CAAC;iBACxB;gBACD,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC;gBAClC,MAAM,UAAU,GAAG,GAAS,EAAE;oBAC1B,IAAI;wBACA,MAAM,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;wBACnC,IAAI,OAAO,EAAE;4BACT,aAAa,CAAC,IAAI,CAAC,CAAC;yBACvB;qBACJ;oBAAC,WAAM;wBACJ,IAAI,OAAO,EAAE;4BACT,aAAa,CAAC,KAAK,CAAC,CAAC;4BACrB,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;yBACxC;qBACJ;gBACL,CAAC,CAAA,CAAA;gBACD,UAAU,EAAE,CAAC;aAChB;iBAAM,IAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBAC9C,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;aACxC;SACJ;QACD;;WAEG;QACH,OAAO,GAAG,EAAE;YACR,OAAO,GAAG,KAAK,CAAC;YAChB,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC1B,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;aAClD;YACD,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;QACzC,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1B,OAAO;QACH,UAAU;KACb,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
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>;
|
|
22
|
-
//# sourceMappingURL=useSharedMap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,106 +0,0 @@
|
|
|
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
|
-
}
|
|
106
|
-
//# sourceMappingURL=useSharedMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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AAC,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 +0,0 @@
|
|
|
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];
|
|
21
|
-
//# sourceMappingURL=useSharedState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,63 +0,0 @@
|
|
|
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
|
-
}
|
|
63
|
-
//# sourceMappingURL=useSharedState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSharedState.js","sourceRoot":"","sources":["../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAC1B,SAAiB,EACjB,YAAe;IAEf;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAI,YAAY,CAAC,CAAC;IACpE;;OAEG;IACH,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5C;;OAEG;IACH,MAAM,EACF,4BAA4B,EAC5B,8BAA8B,EAC9B,iBAAiB,EACjB,iBAAiB,GACpB,GAAG,sBAAsB,EAAE,CAAC;IAE7B;;OAEG;IACH,MAAM,cAAc,GAA4B,KAAK,CAAC,WAAW,CAC7D,CAAC,YAAe,EAAE,EAAE;QAChB,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC/C,CAAC,EACD,CAAC,SAAS,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAChD,CAAC;IAEF;;OAEG;IACH,MAAM,kBAAkB,GACpB,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACnB,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAEvC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,4BAA4B,CACxB,SAAS,EACT,cAAc,CAAC,OAAO,EACtB,aAAa,CAChB,CAAC;QACF,OAAO,GAAG,EAAE;YACR,8BAA8B,CAAC,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QACtE,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,EAAE,4BAA4B,EAAE,8BAA8B,CAAC,CAAC,CAAC;IAE9E,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TaskManager } from "@fluid-experimental/task-manager";
|
|
2
|
-
/**
|
|
3
|
-
* A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
|
|
4
|
-
*
|
|
5
|
-
* @param uniqueKey the unique key for the TaskManager DDS
|
|
6
|
-
* @param taskId the task id to lock
|
|
7
|
-
* @returns stateful data about the status of the task lock
|
|
8
|
-
*/
|
|
9
|
-
export declare const useTaskManager: (uniqueKey: string, taskId?: string) => {
|
|
10
|
-
lockedTask: boolean;
|
|
11
|
-
taskManager: TaskManager | undefined;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=useTaskManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTaskManager.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useTaskManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAG,MAAM,kCAAkC,CAAC;AAMhE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,cAAe,MAAM,WAAW,MAAM;gBACjD,OAAO;iBACN,WAAW,GAAG,SAAS;CAgEvC,CAAC"}
|