@fluidframework/react 0.41.4 → 2.62.0
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/.eslintrc.cjs +11 -0
- package/.mocharc.cjs +15 -0
- package/CHANGELOG.md +282 -0
- package/README.md +122 -273
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-beta.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-beta.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/react.alpha.api.md +114 -0
- package/api-report/react.beta.api.md +7 -0
- package/api-report/react.public.api.md +7 -0
- package/biome.jsonc +4 -0
- package/dist/alpha.d.ts +45 -0
- package/dist/beta.d.ts +15 -0
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/dist/package.json +4 -0
- package/dist/propNode.d.ts +114 -0
- package/dist/propNode.d.ts.map +1 -0
- package/dist/propNode.js +43 -0
- package/dist/propNode.js.map +1 -0
- package/dist/public.d.ts +15 -0
- package/dist/reactSharedTreeView.d.ts +119 -0
- package/dist/reactSharedTreeView.d.ts.map +1 -0
- package/dist/reactSharedTreeView.js +206 -0
- package/dist/reactSharedTreeView.js.map +1 -0
- package/dist/simpleIdentifier.d.ts +19 -0
- package/dist/simpleIdentifier.d.ts.map +1 -0
- package/dist/simpleIdentifier.js +33 -0
- package/dist/simpleIdentifier.js.map +1 -0
- package/dist/useObservation.d.ts +83 -0
- package/dist/useObservation.d.ts.map +1 -0
- package/dist/useObservation.js +295 -0
- package/dist/useObservation.js.map +1 -0
- package/dist/useTree.d.ts +80 -0
- package/dist/useTree.d.ts.map +1 -0
- package/dist/useTree.js +137 -0
- package/dist/useTree.js.map +1 -0
- package/lib/alpha.d.ts +45 -0
- package/lib/beta.d.ts +15 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -7
- package/lib/index.js.map +1 -1
- package/lib/package.json +4 -0
- package/lib/propNode.d.ts +114 -0
- package/lib/propNode.d.ts.map +1 -0
- package/lib/propNode.js +36 -0
- package/lib/propNode.js.map +1 -0
- package/lib/public.d.ts +15 -0
- package/lib/reactSharedTreeView.d.ts +119 -0
- package/lib/reactSharedTreeView.d.ts.map +1 -0
- package/lib/reactSharedTreeView.js +176 -0
- package/lib/reactSharedTreeView.js.map +1 -0
- package/lib/simpleIdentifier.d.ts +19 -0
- package/lib/simpleIdentifier.d.ts.map +1 -0
- package/lib/simpleIdentifier.js +29 -0
- package/lib/simpleIdentifier.js.map +1 -0
- package/lib/test/propNode.spec.js +120 -0
- package/lib/test/propNode.spec.js.map +1 -0
- package/lib/test/reactSharedTreeView.spec.js +71 -0
- package/lib/test/reactSharedTreeView.spec.js.map +1 -0
- package/lib/test/simpleIdentifier.spec.js +18 -0
- package/lib/test/simpleIdentifier.spec.js.map +1 -0
- package/lib/test/useObservation.spec.js +162 -0
- package/lib/test/useObservation.spec.js.map +1 -0
- package/lib/test/useTree.spec.js +165 -0
- package/lib/test/useTree.spec.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/useObservation.d.ts +83 -0
- package/lib/useObservation.d.ts.map +1 -0
- package/lib/useObservation.js +266 -0
- package/lib/useObservation.js.map +1 -0
- package/lib/useTree.d.ts +80 -0
- package/lib/useTree.d.ts.map +1 -0
- package/lib/useTree.js +105 -0
- package/lib/useTree.js.map +1 -0
- package/package.json +150 -51
- package/react.test-files.tar +0 -0
- package/src/index.ts +42 -7
- package/src/propNode.ts +164 -0
- package/src/reactSharedTreeView.tsx +327 -0
- package/src/simpleIdentifier.ts +31 -0
- package/src/useObservation.ts +376 -0
- package/src/useTree.ts +147 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +12 -15
- package/tsdoc.json +4 -0
- package/.eslintrc.js +0 -11
- package/dist/createContextFluid.d.ts +0 -7
- package/dist/createContextFluid.d.ts.map +0 -1
- package/dist/createContextFluid.js +0 -46
- package/dist/createContextFluid.js.map +0 -1
- package/dist/helpers/generateFluidObjectSchema.d.ts +0 -16
- package/dist/helpers/generateFluidObjectSchema.d.ts.map +0 -1
- package/dist/helpers/generateFluidObjectSchema.js +0 -75
- package/dist/helpers/generateFluidObjectSchema.js.map +0 -1
- package/dist/helpers/getFluidFromView.d.ts +0 -15
- package/dist/helpers/getFluidFromView.d.ts.map +0 -1
- package/dist/helpers/getFluidFromView.js +0 -30
- package/dist/helpers/getFluidFromView.js.map +0 -1
- package/dist/helpers/getFluidState.d.ts +0 -15
- package/dist/helpers/getFluidState.d.ts.map +0 -1
- package/dist/helpers/getFluidState.js +0 -47
- package/dist/helpers/getFluidState.js.map +0 -1
- package/dist/helpers/getSchema.d.ts +0 -13
- package/dist/helpers/getSchema.d.ts.map +0 -1
- package/dist/helpers/getSchema.js +0 -15
- package/dist/helpers/getSchema.js.map +0 -1
- package/dist/helpers/getViewFromFluid.d.ts +0 -18
- package/dist/helpers/getViewFromFluid.d.ts.map +0 -1
- package/dist/helpers/getViewFromFluid.js +0 -47
- package/dist/helpers/getViewFromFluid.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -16
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -28
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/initializeState.d.ts +0 -22
- package/dist/helpers/initializeState.d.ts.map +0 -1
- package/dist/helpers/initializeState.js +0 -77
- package/dist/helpers/initializeState.js.map +0 -1
- package/dist/helpers/internalInterface.d.ts +0 -15
- package/dist/helpers/internalInterface.d.ts.map +0 -1
- package/dist/helpers/internalInterface.js +0 -7
- package/dist/helpers/internalInterface.js.map +0 -1
- package/dist/helpers/rootCallbackListener.d.ts +0 -24
- package/dist/helpers/rootCallbackListener.d.ts.map +0 -1
- package/dist/helpers/rootCallbackListener.js +0 -55
- package/dist/helpers/rootCallbackListener.js.map +0 -1
- package/dist/helpers/setComponentSchema.d.ts +0 -14
- package/dist/helpers/setComponentSchema.d.ts.map +0 -1
- package/dist/helpers/setComponentSchema.js +0 -18
- package/dist/helpers/setComponentSchema.js.map +0 -1
- package/dist/helpers/setFluidState.d.ts +0 -20
- package/dist/helpers/setFluidState.d.ts.map +0 -1
- package/dist/helpers/setFluidState.js +0 -94
- package/dist/helpers/setFluidState.js.map +0 -1
- package/dist/helpers/syncState.d.ts +0 -25
- package/dist/helpers/syncState.d.ts.map +0 -1
- package/dist/helpers/syncState.js +0 -98
- package/dist/helpers/syncState.js.map +0 -1
- package/dist/helpers/updateStateAndFluidObjectMap.d.ts +0 -29
- package/dist/helpers/updateStateAndFluidObjectMap.d.ts.map +0 -1
- package/dist/helpers/updateStateAndFluidObjectMap.js +0 -30
- package/dist/helpers/updateStateAndFluidObjectMap.js.map +0 -1
- package/dist/helpers/utils.d.ts +0 -12
- package/dist/helpers/utils.d.ts.map +0 -1
- package/dist/helpers/utils.js +0 -74
- package/dist/helpers/utils.js.map +0 -1
- package/dist/interface.d.ts +0 -444
- package/dist/interface.d.ts.map +0 -1
- package/dist/interface.js +0 -18
- package/dist/interface.js.map +0 -1
- package/dist/reactView.d.ts +0 -32
- package/dist/reactView.d.ts.map +0 -1
- package/dist/reactView.js +0 -79
- package/dist/reactView.js.map +0 -1
- package/dist/syncedDataObject.d.ts +0 -80
- package/dist/syncedDataObject.d.ts.map +0 -1
- package/dist/syncedDataObject.js +0 -249
- package/dist/syncedDataObject.js.map +0 -1
- package/dist/syncedObjects/array/fluidSyncedArray.d.ts +0 -11
- package/dist/syncedObjects/array/fluidSyncedArray.d.ts.map +0 -1
- package/dist/syncedObjects/array/fluidSyncedArray.js +0 -78
- package/dist/syncedObjects/array/fluidSyncedArray.js.map +0 -1
- package/dist/syncedObjects/array/index.d.ts +0 -7
- package/dist/syncedObjects/array/index.d.ts.map +0 -1
- package/dist/syncedObjects/array/index.js +0 -19
- package/dist/syncedObjects/array/index.js.map +0 -1
- package/dist/syncedObjects/array/interface.d.ts +0 -33
- package/dist/syncedObjects/array/interface.d.ts.map +0 -1
- package/dist/syncedObjects/array/interface.js +0 -3
- package/dist/syncedObjects/array/interface.js.map +0 -1
- package/dist/syncedObjects/array/syncedArray.d.ts +0 -30
- package/dist/syncedObjects/array/syncedArray.d.ts.map +0 -1
- package/dist/syncedObjects/array/syncedArray.js +0 -42
- package/dist/syncedObjects/array/syncedArray.js.map +0 -1
- package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts +0 -11
- package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts.map +0 -1
- package/dist/syncedObjects/counter/fluidSyncedCounter.js +0 -79
- package/dist/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
- package/dist/syncedObjects/counter/index.d.ts +0 -7
- package/dist/syncedObjects/counter/index.d.ts.map +0 -1
- package/dist/syncedObjects/counter/index.js +0 -19
- package/dist/syncedObjects/counter/index.js.map +0 -1
- package/dist/syncedObjects/counter/interface.d.ts +0 -32
- package/dist/syncedObjects/counter/interface.d.ts.map +0 -1
- package/dist/syncedObjects/counter/interface.js +0 -3
- package/dist/syncedObjects/counter/interface.js.map +0 -1
- package/dist/syncedObjects/counter/syncedCounter.d.ts +0 -29
- package/dist/syncedObjects/counter/syncedCounter.d.ts.map +0 -1
- package/dist/syncedObjects/counter/syncedCounter.js +0 -36
- package/dist/syncedObjects/counter/syncedCounter.js.map +0 -1
- package/dist/syncedObjects/index.d.ts +0 -9
- package/dist/syncedObjects/index.d.ts.map +0 -1
- package/dist/syncedObjects/index.js +0 -21
- package/dist/syncedObjects/index.js.map +0 -1
- package/dist/syncedObjects/object/index.d.ts +0 -7
- package/dist/syncedObjects/object/index.d.ts.map +0 -1
- package/dist/syncedObjects/object/index.js +0 -19
- package/dist/syncedObjects/object/index.js.map +0 -1
- package/dist/syncedObjects/object/interface.d.ts +0 -13
- package/dist/syncedObjects/object/interface.d.ts.map +0 -1
- package/dist/syncedObjects/object/interface.js +0 -7
- package/dist/syncedObjects/object/interface.js.map +0 -1
- package/dist/syncedObjects/object/syncedObject.d.ts +0 -22
- package/dist/syncedObjects/object/syncedObject.d.ts.map +0 -1
- package/dist/syncedObjects/object/syncedObject.js +0 -46
- package/dist/syncedObjects/object/syncedObject.js.map +0 -1
- package/dist/syncedObjects/string/index.d.ts +0 -7
- package/dist/syncedObjects/string/index.d.ts.map +0 -1
- package/dist/syncedObjects/string/index.js +0 -19
- package/dist/syncedObjects/string/index.js.map +0 -1
- package/dist/syncedObjects/string/interface.d.ts +0 -16
- package/dist/syncedObjects/string/interface.d.ts.map +0 -1
- package/dist/syncedObjects/string/interface.js +0 -7
- package/dist/syncedObjects/string/interface.js.map +0 -1
- package/dist/syncedObjects/string/syncedString.d.ts +0 -25
- package/dist/syncedObjects/string/syncedString.d.ts.map +0 -1
- package/dist/syncedObjects/string/syncedString.js +0 -53
- package/dist/syncedObjects/string/syncedString.js.map +0 -1
- package/dist/useReducerFluid.d.ts +0 -7
- package/dist/useReducerFluid.d.ts.map +0 -1
- package/dist/useReducerFluid.js +0 -219
- package/dist/useReducerFluid.js.map +0 -1
- package/dist/useStateFluid.d.ts +0 -10
- package/dist/useStateFluid.d.ts.map +0 -1
- package/dist/useStateFluid.js +0 -67
- package/dist/useStateFluid.js.map +0 -1
- package/lib/createContextFluid.js +0 -23
- package/lib/createContextFluid.js.map +0 -1
- package/lib/helpers/generateFluidObjectSchema.js +0 -71
- package/lib/helpers/generateFluidObjectSchema.js.map +0 -1
- package/lib/helpers/getFluidFromView.js +0 -26
- package/lib/helpers/getFluidFromView.js.map +0 -1
- package/lib/helpers/getFluidState.js +0 -43
- package/lib/helpers/getFluidState.js.map +0 -1
- package/lib/helpers/getSchema.js +0 -11
- package/lib/helpers/getSchema.js.map +0 -1
- package/lib/helpers/getViewFromFluid.js +0 -43
- package/lib/helpers/getViewFromFluid.js.map +0 -1
- package/lib/helpers/index.js +0 -16
- package/lib/helpers/index.js.map +0 -1
- package/lib/helpers/initializeState.js +0 -73
- package/lib/helpers/initializeState.js.map +0 -1
- package/lib/helpers/internalInterface.js +0 -6
- package/lib/helpers/internalInterface.js.map +0 -1
- package/lib/helpers/rootCallbackListener.js +0 -51
- package/lib/helpers/rootCallbackListener.js.map +0 -1
- package/lib/helpers/setComponentSchema.js +0 -14
- package/lib/helpers/setComponentSchema.js.map +0 -1
- package/lib/helpers/setFluidState.js +0 -90
- package/lib/helpers/setFluidState.js.map +0 -1
- package/lib/helpers/syncState.js +0 -94
- package/lib/helpers/syncState.js.map +0 -1
- package/lib/helpers/updateStateAndFluidObjectMap.js +0 -26
- package/lib/helpers/updateStateAndFluidObjectMap.js.map +0 -1
- package/lib/helpers/utils.js +0 -67
- package/lib/helpers/utils.js.map +0 -1
- package/lib/interface.js +0 -8
- package/lib/interface.js.map +0 -1
- package/lib/reactView.js +0 -56
- package/lib/reactView.js.map +0 -1
- package/lib/syncedDataObject.js +0 -245
- package/lib/syncedDataObject.js.map +0 -1
- package/lib/syncedObjects/array/fluidSyncedArray.js +0 -72
- package/lib/syncedObjects/array/fluidSyncedArray.js.map +0 -1
- package/lib/syncedObjects/array/index.js +0 -7
- package/lib/syncedObjects/array/index.js.map +0 -1
- package/lib/syncedObjects/array/interface.js +0 -2
- package/lib/syncedObjects/array/interface.js.map +0 -1
- package/lib/syncedObjects/array/syncedArray.js +0 -37
- package/lib/syncedObjects/array/syncedArray.js.map +0 -1
- package/lib/syncedObjects/counter/fluidSyncedCounter.js +0 -73
- package/lib/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
- package/lib/syncedObjects/counter/index.js +0 -7
- package/lib/syncedObjects/counter/index.js.map +0 -1
- package/lib/syncedObjects/counter/interface.js +0 -2
- package/lib/syncedObjects/counter/interface.js.map +0 -1
- package/lib/syncedObjects/counter/syncedCounter.js +0 -31
- package/lib/syncedObjects/counter/syncedCounter.js.map +0 -1
- package/lib/syncedObjects/index.js +0 -9
- package/lib/syncedObjects/index.js.map +0 -1
- package/lib/syncedObjects/object/index.js +0 -7
- package/lib/syncedObjects/object/index.js.map +0 -1
- package/lib/syncedObjects/object/interface.js +0 -6
- package/lib/syncedObjects/object/interface.js.map +0 -1
- package/lib/syncedObjects/object/syncedObject.js +0 -41
- package/lib/syncedObjects/object/syncedObject.js.map +0 -1
- package/lib/syncedObjects/string/index.js +0 -7
- package/lib/syncedObjects/string/index.js.map +0 -1
- package/lib/syncedObjects/string/interface.js +0 -6
- package/lib/syncedObjects/string/interface.js.map +0 -1
- package/lib/syncedObjects/string/syncedString.js +0 -48
- package/lib/syncedObjects/string/syncedString.js.map +0 -1
- package/lib/useReducerFluid.js +0 -196
- package/lib/useReducerFluid.js.map +0 -1
- package/lib/useStateFluid.js +0 -44
- package/lib/useStateFluid.js.map +0 -1
- package/src/createContextFluid.tsx +0 -33
- package/src/helpers/generateFluidObjectSchema.ts +0 -95
- package/src/helpers/getFluidFromView.ts +0 -38
- package/src/helpers/getFluidState.ts +0 -67
- package/src/helpers/getSchema.ts +0 -18
- package/src/helpers/getViewFromFluid.ts +0 -68
- package/src/helpers/index.tsx +0 -16
- package/src/helpers/initializeState.ts +0 -162
- package/src/helpers/internalInterface.ts +0 -16
- package/src/helpers/rootCallbackListener.ts +0 -104
- package/src/helpers/setComponentSchema.ts +0 -21
- package/src/helpers/setFluidState.ts +0 -116
- package/src/helpers/syncState.ts +0 -159
- package/src/helpers/updateStateAndFluidObjectMap.ts +0 -85
- package/src/helpers/utils.tsx +0 -109
- package/src/interface.ts +0 -617
- package/src/reactView.tsx +0 -108
- package/src/syncedDataObject.ts +0 -337
- package/src/syncedObjects/array/fluidSyncedArray.ts +0 -126
- package/src/syncedObjects/array/index.ts +0 -7
- package/src/syncedObjects/array/interface.ts +0 -45
- package/src/syncedObjects/array/syncedArray.ts +0 -65
- package/src/syncedObjects/counter/fluidSyncedCounter.ts +0 -122
- package/src/syncedObjects/counter/index.ts +0 -7
- package/src/syncedObjects/counter/interface.ts +0 -44
- package/src/syncedObjects/counter/syncedCounter.ts +0 -64
- package/src/syncedObjects/index.ts +0 -9
- package/src/syncedObjects/object/index.ts +0 -7
- package/src/syncedObjects/object/interface.ts +0 -14
- package/src/syncedObjects/object/syncedObject.ts +0 -55
- package/src/syncedObjects/string/index.ts +0 -7
- package/src/syncedObjects/string/interface.ts +0 -17
- package/src/syncedObjects/string/syncedString.ts +0 -61
- package/src/useReducerFluid.tsx +0 -436
- package/src/useStateFluid.tsx +0 -84
- package/tsconfig.esnext.json +0 -7
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.syncedStateCallbackListener = void 0;
|
|
8
|
-
const syncState_1 = require("./syncState");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const getViewFromFluid_1 = require("./getViewFromFluid");
|
|
11
|
-
const _1 = require(".");
|
|
12
|
-
/**
|
|
13
|
-
* The callback that is added to the "valueChanged" event on the Fluid object this
|
|
14
|
-
* is passed in to. This will trigger state updates when the synced state value is updated
|
|
15
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
16
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
17
|
-
* @param syncedState - The shared map this Fluid object's synced state is stored on
|
|
18
|
-
* @param runtime - The data store runtime
|
|
19
|
-
* @param state - The current view state
|
|
20
|
-
* @param setState - Callback to update the react view state
|
|
21
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
22
|
-
* respective converters
|
|
23
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
24
|
-
* respective converters
|
|
25
|
-
*/
|
|
26
|
-
const syncedStateCallbackListener = (fluidObjectMap, storedHandleMap, syncedStateId, syncedState, runtime, state, setState, fluidToView, viewToFluid) => (change, local) => {
|
|
27
|
-
const currentFluidState = _1.getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView);
|
|
28
|
-
if (currentFluidState === undefined) {
|
|
29
|
-
throw Error("Synced state update triggered before Fluid state was initialized");
|
|
30
|
-
}
|
|
31
|
-
const viewToFluidKeys = viewToFluid !== undefined
|
|
32
|
-
? Array.from(viewToFluid.values()).map((item) => item.fluidKey)
|
|
33
|
-
: [];
|
|
34
|
-
if (!local && change.key === `syncedState-${syncedStateId}`) {
|
|
35
|
-
// If the update is to the synced Fluid state, update both the Fluid and view states
|
|
36
|
-
syncState_1.syncState(true, syncedStateId, syncedState, runtime, state, setState, fluidObjectMap, fluidToView, viewToFluid);
|
|
37
|
-
}
|
|
38
|
-
else if (viewToFluid !== undefined &&
|
|
39
|
-
viewToFluidKeys.includes(change.key)) {
|
|
40
|
-
// If the update is to a child Fluid object, trigger only a view update as the child itself will
|
|
41
|
-
// update its Fluid update
|
|
42
|
-
const stateKey = utils_1.getByFluidKey(change.key, viewToFluid);
|
|
43
|
-
if (stateKey !== undefined) {
|
|
44
|
-
const newPartialState = getViewFromFluid_1.getViewFromFluid(syncedStateId, syncedState, change.key, fluidObjectMap, fluidToView, state, currentFluidState);
|
|
45
|
-
state[stateKey] = newPartialState[stateKey];
|
|
46
|
-
state.fluidObjectMap = fluidObjectMap;
|
|
47
|
-
setState(state, true, local);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
throw Error(`Unable to extract view state from synced state change key: ${change.key}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.syncedStateCallbackListener = syncedStateCallbackListener;
|
|
55
|
-
//# sourceMappingURL=rootCallbackListener.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rootC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GAAG,mCAAgB,CACpC,aAAa,EACb,WAAW,EACX,MAAM,CAAC,GAAe,EACtB,cAAc,EACd,WAAW,EACX,KAAK,EACL,iBAAiB,CACpB,CAAC;YACF,KAAK,CAAC,QAAkB,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;YACtD,KAAK,CAAC,cAAc,GAAG,cAAc,CAAC;YACtC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SAChC;aAAM;YACH,MAAM,KAAK,CACP,8DAA8D,MAAM,CAAC,GAAG,EAAE,CAC7E,CAAC;SACL;KACJ;AACL,CAAC,CAAC;AArEW,QAAA,2BAA2B,+BAqEtC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedMap, IValueChanged } from \"@fluidframework/map\";\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n FluidObjectMap,\n ViewToFluidMap,\n FluidToViewMap,\n IViewState,\n IFluidState,\n} from \"../interface\";\nimport { ISyncedState } from \"..\";\nimport { syncState } from \"./syncState\";\nimport { getByFluidKey } from \"./utils\";\nimport { getViewFromFluid } from \"./getViewFromFluid\";\nimport { getFluidState } from \".\";\n\n/**\n * The callback that is added to the \"valueChanged\" event on the Fluid object this\n * is passed in to. This will trigger state updates when the synced state value is updated\n * @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects\n * @param syncedStateId - Unique ID for this synced Fluid object's state\n * @param syncedState - The shared map this Fluid object's synced state is stored on\n * @param runtime - The data store runtime\n * @param state - The current view state\n * @param setState - Callback to update the react view state\n * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n * @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the\n * respective converters\n */\nexport const syncedStateCallbackListener = <\n SV extends IViewState,\n SF extends IFluidState\n>(\n fluidObjectMap: FluidObjectMap,\n storedHandleMap: ISharedMap,\n syncedStateId,\n syncedState: ISyncedState,\n runtime: IFluidDataStoreRuntime,\n state: SV,\n setState: (\n newState: SV,\n fromRootUpdate?: boolean,\n isLocal?: boolean\n ) => void,\n fluidToView: FluidToViewMap<SV, SF>,\n viewToFluid?: ViewToFluidMap<SV, SF>,\n) => (change: IValueChanged, local: boolean) => {\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\"Synced state update triggered before Fluid state was initialized\");\n }\n const viewToFluidKeys: string[] = viewToFluid !== undefined\n ? Array.from(viewToFluid.values()).map((item) => item.fluidKey as string)\n : [];\n if (!local && change.key === `syncedState-${syncedStateId}`) {\n // If the update is to the synced Fluid state, update both the Fluid and view states\n syncState(\n true,\n syncedStateId,\n syncedState,\n runtime,\n state,\n setState,\n fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n } else if (\n viewToFluid !== undefined &&\n viewToFluidKeys.includes(change.key)\n ) {\n // If the update is to a child Fluid object, trigger only a view update as the child itself will\n // update its Fluid update\n const stateKey = getByFluidKey(change.key, viewToFluid);\n if (stateKey !== undefined) {\n const newPartialState = getViewFromFluid(\n syncedStateId,\n syncedState,\n change.key as keyof SF,\n fluidObjectMap,\n fluidToView,\n state,\n currentFluidState,\n );\n state[stateKey as string] = newPartialState[stateKey];\n state.fluidObjectMap = fluidObjectMap;\n setState(state, true, local);\n } else {\n throw Error(\n `Unable to extract view state from synced state change key: ${change.key}`,\n );\n }\n }\n};\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { ISyncedState } from "..";
|
|
6
|
-
import { IFluidSchemaHandles } from "./internalInterface";
|
|
7
|
-
/**
|
|
8
|
-
* Store the schema on to the shared synced state
|
|
9
|
-
* @param syncedStateId - Unique ID to use for storing the synced state in the shared map
|
|
10
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
11
|
-
* @param schemaHandles - Handles for the schema SharedMaps
|
|
12
|
-
*/
|
|
13
|
-
export declare function setSchema(syncedStateId: string, syncedState: ISyncedState, schemaHandles: IFluidSchemaHandles): void;
|
|
14
|
-
//# sourceMappingURL=setComponentSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setComponentSchema.d.ts","sourceRoot":"","sources":["../../src/helpers/setComponentSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,SAAS,CACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,YAAY,EACzB,aAAa,EAAE,mBAAmB,GACnC,IAAI,CAEN"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.setSchema = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* Store the schema on to the shared synced state
|
|
10
|
-
* @param syncedStateId - Unique ID to use for storing the synced state in the shared map
|
|
11
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
12
|
-
* @param schemaHandles - Handles for the schema SharedMaps
|
|
13
|
-
*/
|
|
14
|
-
function setSchema(syncedStateId, syncedState, schemaHandles) {
|
|
15
|
-
syncedState.set(`schema-${syncedStateId}`, schemaHandles);
|
|
16
|
-
}
|
|
17
|
-
exports.setSchema = setSchema;
|
|
18
|
-
//# sourceMappingURL=setComponentSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setComponentSchema.js","sourceRoot":"","sources":["../../src/helpers/setComponentSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH;;;;;GAKG;AACH,SAAgB,SAAS,CACrB,aAAqB,EACrB,WAAyB,EACzB,aAAkC;IAElC,WAAW,CAAC,GAAG,CAAC,UAAU,aAAa,EAAE,EAAE,aAAa,CAAC,CAAC;AAC9D,CAAC;AAND,8BAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISyncedState } from \"..\";\nimport { IFluidSchemaHandles } from \"./internalInterface\";\n\n/**\n * Store the schema on to the shared synced state\n * @param syncedStateId - Unique ID to use for storing the synced state in the shared map\n * @param syncedState - The shared map that will be used to store the synced state\n * @param schemaHandles - Handles for the schema SharedMaps\n */\nexport function setSchema(\n syncedStateId: string,\n syncedState: ISyncedState,\n schemaHandles: IFluidSchemaHandles,\n): void {\n syncedState.set(`schema-${syncedStateId}`, schemaHandles);\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
6
|
-
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
-
import { FluidObjectMap, IViewConverter, IFluidConverter, ISyncedState } from "../interface";
|
|
8
|
-
/**
|
|
9
|
-
* Store the Fluid state onto the shared synced state
|
|
10
|
-
* @param syncedStateId - Unique ID to use for storing the Fluid object's synced state in the map
|
|
11
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
12
|
-
* @param runtime - The data store runtime
|
|
13
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
14
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
15
|
-
* respective converters
|
|
16
|
-
* @param newFluidState - The Fluid state to store on to the syncedState,
|
|
17
|
-
* after converting Fluid objects to their handles
|
|
18
|
-
*/
|
|
19
|
-
export declare function setFluidState<SV, SF>(syncedStateId: string, syncedState: ISyncedState, runtime: IFluidDataStoreRuntime, fluidObjectMap: FluidObjectMap, fluidToView: Map<keyof SF, IViewConverter<SV, SF>>, newViewState: SV, newFluidState?: SF, viewToFluid?: Map<keyof SV, IFluidConverter<SV, SF>>): IFluidHandle;
|
|
20
|
-
//# sourceMappingURL=setFluidState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setFluidState.d.ts","sourceRoot":"","sources":["../../src/helpers/setFluidState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EACH,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,EACf,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,YAAY,EACzB,OAAO,EAAE,sBAAsB,EAC/B,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAClD,YAAY,EAAE,EAAE,EAChB,aAAa,CAAC,EAAE,EAAE,EAClB,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GACrD,YAAY,CAgFd"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.setFluidState = void 0;
|
|
8
|
-
const map_1 = require("@fluidframework/map");
|
|
9
|
-
/**
|
|
10
|
-
* Store the Fluid state onto the shared synced state
|
|
11
|
-
* @param syncedStateId - Unique ID to use for storing the Fluid object's synced state in the map
|
|
12
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
13
|
-
* @param runtime - The data store runtime
|
|
14
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
15
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
16
|
-
* respective converters
|
|
17
|
-
* @param newFluidState - The Fluid state to store on to the syncedState,
|
|
18
|
-
* after converting Fluid objects to their handles
|
|
19
|
-
*/
|
|
20
|
-
function setFluidState(syncedStateId, syncedState, runtime, fluidObjectMap, fluidToView, newViewState, newFluidState, viewToFluid) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
22
|
-
const storedStateHandle = syncedState.get(`syncedState-${syncedStateId}`);
|
|
23
|
-
let storedState;
|
|
24
|
-
if (storedStateHandle) {
|
|
25
|
-
storedState = (_a = fluidObjectMap.get(storedStateHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
26
|
-
}
|
|
27
|
-
if (storedStateHandle === undefined || storedState === undefined) {
|
|
28
|
-
const newState = map_1.SharedMap.create(runtime);
|
|
29
|
-
fluidObjectMap.set(newState.handle.absolutePath, {
|
|
30
|
-
fluidObject: newState,
|
|
31
|
-
isRuntimeMap: true,
|
|
32
|
-
});
|
|
33
|
-
storedState = newState;
|
|
34
|
-
}
|
|
35
|
-
if (storedState === undefined) {
|
|
36
|
-
throw Error("Failed to fetch synced state from root");
|
|
37
|
-
}
|
|
38
|
-
for (const key of fluidToView.keys()) {
|
|
39
|
-
const fluidKey = key;
|
|
40
|
-
const syncedStateKey = (_b = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _b === void 0 ? void 0 : _b.rootKey;
|
|
41
|
-
const createCallback = (_c = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _c === void 0 ? void 0 : _c.sharedObjectCreate;
|
|
42
|
-
if (createCallback !== undefined) {
|
|
43
|
-
if (storedState.get(fluidKey) === undefined) {
|
|
44
|
-
const sharedObject = createCallback(runtime);
|
|
45
|
-
fluidObjectMap.set(sharedObject.handle.absolutePath, {
|
|
46
|
-
fluidObject: sharedObject,
|
|
47
|
-
listenedEvents: (_e = (_d = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _d === void 0 ? void 0 : _d.listenedEvents) !== null && _e !== void 0 ? _e : ["valueChanged"],
|
|
48
|
-
});
|
|
49
|
-
storedState.set(fluidKey, sharedObject.handle);
|
|
50
|
-
if (syncedStateKey !== undefined) {
|
|
51
|
-
syncedState.set(syncedStateKey, sharedObject.handle);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
storedState.set(fluidKey, storedState.get(fluidKey));
|
|
56
|
-
if (syncedStateKey !== undefined) {
|
|
57
|
-
syncedState.set(syncedStateKey, syncedState.get(syncedStateKey));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else if (syncedStateKey !== undefined) {
|
|
62
|
-
const value = newFluidState !== undefined
|
|
63
|
-
? newFluidState[fluidKey]
|
|
64
|
-
: syncedState.get(syncedStateKey);
|
|
65
|
-
syncedState.set(syncedStateKey, value);
|
|
66
|
-
storedState.set(fluidKey, value);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const value = newFluidState !== undefined
|
|
70
|
-
? newFluidState[fluidKey]
|
|
71
|
-
: storedState.get(fluidKey);
|
|
72
|
-
storedState.set(fluidKey, value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (viewToFluid !== undefined && newFluidState !== undefined) {
|
|
76
|
-
for (const key of viewToFluid.keys()) {
|
|
77
|
-
const viewKey = key;
|
|
78
|
-
const fluidConverter = (_f = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey)) === null || _f === void 0 ? void 0 : _f.fluidConverter;
|
|
79
|
-
const fluidKey = (_g = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey)) === null || _g === void 0 ? void 0 : _g.fluidKey;
|
|
80
|
-
if (fluidConverter !== undefined && fluidKey !== undefined) {
|
|
81
|
-
const value = fluidConverter(newViewState, newFluidState);
|
|
82
|
-
// Write this value to the stored state if it doesn't match the name of a view value
|
|
83
|
-
if (((_h = fluidToView.get(fluidKey)) === null || _h === void 0 ? void 0 : _h.sharedObjectCreate) ===
|
|
84
|
-
undefined) {
|
|
85
|
-
storedState.set(viewKey, value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
syncedState.set(`syncedState-${syncedStateId}`, storedState.handle);
|
|
91
|
-
return storedState.handle;
|
|
92
|
-
}
|
|
93
|
-
exports.setFluidState = setFluidState;
|
|
94
|
-
//# sourceMappingURL=setFluidState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setFluidState.js","sourceRoot":"","sources":["../../src/helpers/setFluidState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAA4D;AAU5D;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CACzB,aAAqB,EACrB,WAAyB,EACzB,OAA+B,EAC/B,cAA8B,EAC9B,WAAkD,EAClD,YAAgB,EAChB,aAAkB,EAClB,WAAoD;;IAEpD,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,CACrC,eAAe,aAAa,EAAE,CACjC,CAAC;IACF,IAAI,WAAmC,CAAC;IACxC,IAAI,iBAAiB,EAAE;QACnB,WAAW,GAAG,MAAA,cAAc,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,0CAC1D,WAAyB,CAAC;KACnC;IACD,IAAI,iBAAiB,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E;gBACxD,MAAM,KAAK,GAAG,cAAc,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;gBAC1D,oFAAoF;gBACpF,IACI,OAAA,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,0CAAE,kBAAkB;oBAC7C,SAAS,EACX;oBACE,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;iBACnC;aACJ;SACJ;KACJ;IACD,WAAW,CAAC,GAAG,CAAC,eAAe,aAAa,EAAE,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC,MAAM,CAAC;AAC9B,CAAC;AAzFD,sCAyFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedMap, SharedMap } from \"@fluidframework/map\";\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n FluidObjectMap,\n IViewConverter,\n IFluidConverter,\n ISyncedState,\n} from \"../interface\";\n\n/**\n * Store the Fluid state onto the shared synced state\n * @param syncedStateId - Unique ID to use for storing the Fluid object's synced state in the map\n * @param syncedState - The shared map that will be used to store the synced state\n * @param runtime - The data store runtime\n * @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects\n * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n * @param newFluidState - The Fluid state to store on to the syncedState,\n * after converting Fluid objects to their handles\n */\nexport function setFluidState<SV, SF>(\n syncedStateId: string,\n syncedState: ISyncedState,\n runtime: IFluidDataStoreRuntime,\n fluidObjectMap: FluidObjectMap,\n fluidToView: Map<keyof SF, IViewConverter<SV, SF>>,\n newViewState: SV,\n newFluidState?: SF,\n viewToFluid?: Map<keyof SV, IFluidConverter<SV, SF>>,\n): IFluidHandle {\n const storedStateHandle = syncedState.get<IFluidHandle>(\n `syncedState-${syncedStateId}`,\n );\n let storedState: ISharedMap | undefined;\n if (storedStateHandle) {\n storedState = fluidObjectMap.get(storedStateHandle.absolutePath)\n ?.fluidObject as ISharedMap;\n }\n if (storedStateHandle === undefined || storedState === undefined) {\n const newState = SharedMap.create(runtime);\n fluidObjectMap.set(newState.handle.absolutePath, {\n fluidObject: newState,\n isRuntimeMap: true,\n });\n storedState = newState;\n }\n if (storedState === undefined) {\n throw Error(\"Failed to fetch synced state from root\");\n }\n for (const key of fluidToView.keys()) {\n const fluidKey = key as string;\n const syncedStateKey = fluidToView?.get(fluidKey as keyof SF)?.rootKey;\n const createCallback = fluidToView?.get(fluidKey as keyof SF)\n ?.sharedObjectCreate;\n if (createCallback !== undefined) {\n if (storedState.get(fluidKey) === undefined) {\n const sharedObject = createCallback(runtime);\n fluidObjectMap.set(sharedObject.handle.absolutePath, {\n fluidObject: sharedObject,\n listenedEvents: fluidToView?.get(fluidKey as keyof SF)\n ?.listenedEvents ?? [\"valueChanged\"],\n });\n storedState.set(fluidKey, sharedObject.handle);\n if (syncedStateKey !== undefined) {\n syncedState.set(syncedStateKey, sharedObject.handle);\n }\n } else {\n storedState.set(fluidKey, storedState.get(fluidKey));\n if (syncedStateKey !== undefined) {\n syncedState.set(\n syncedStateKey,\n syncedState.get(syncedStateKey),\n );\n }\n }\n } else if (syncedStateKey !== undefined) {\n const value = newFluidState !== undefined\n ? newFluidState[fluidKey]\n : syncedState.get(syncedStateKey);\n syncedState.set(syncedStateKey, value);\n storedState.set(fluidKey, value);\n } else {\n const value = newFluidState !== undefined\n ? newFluidState[fluidKey]\n : storedState.get(fluidKey);\n storedState.set(fluidKey, value);\n }\n }\n if (viewToFluid !== undefined && newFluidState !== undefined) {\n for (const key of viewToFluid.keys()) {\n const viewKey = key as string;\n const fluidConverter = viewToFluid?.get(viewKey as keyof SV)\n ?.fluidConverter;\n const fluidKey = viewToFluid?.get(viewKey as keyof SV)\n ?.fluidKey;\n if (fluidConverter !== undefined && fluidKey !== undefined) {\n const value = fluidConverter(newViewState, newFluidState);\n // Write this value to the stored state if it doesn't match the name of a view value\n if (\n fluidToView.get(fluidKey)?.sharedObjectCreate ===\n undefined\n ) {\n storedState.set(viewKey, value);\n }\n }\n }\n }\n syncedState.set(`syncedState-${syncedStateId}`, storedState.handle);\n return storedState.handle;\n}\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
6
|
-
import { FluidObjectMap, IFluidState, IViewState, ViewToFluidMap, FluidToViewMap, ISyncedState } from "../interface";
|
|
7
|
-
/**
|
|
8
|
-
* Function to combine both the view and Fluid states so that they are in sync. If the update
|
|
9
|
-
* is from a local update, the new Fluid state created from converting the new local view state
|
|
10
|
-
* is used to update the synced Fluid state, which in turn will update the local state on other clients.
|
|
11
|
-
* If it is an update triggered from a remote change on the synced state, the new Fluid state from the synced state
|
|
12
|
-
* is used to overwrite the local synced state and the new local view is created accordingly.
|
|
13
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
14
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
15
|
-
* @param syncedState - The shared map this Fluid object synced state is stored on
|
|
16
|
-
* @param viewState - The current view state
|
|
17
|
-
* @param setState - Callback to update the react view state
|
|
18
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
19
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
20
|
-
* respective converters
|
|
21
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
22
|
-
* respective converters
|
|
23
|
-
*/
|
|
24
|
-
export declare function syncState<SV extends IViewState, SF extends IFluidState>(isSyncedStateUpdate: boolean, syncedStateId: string, syncedState: ISyncedState, runtime: IFluidDataStoreRuntime, viewState: SV, setState: (newState: SV, isSyncedStateUpdate?: boolean, isLocal?: boolean) => void, fluidObjectMap: FluidObjectMap, fluidToView: FluidToViewMap<SV, SF>, viewToFluid?: ViewToFluidMap<SV, SF>): void;
|
|
25
|
-
//# sourceMappingURL=syncState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncState.d.ts","sourceRoot":"","sources":["../../src/helpers/syncState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,OAAO,EACH,cAAc,EACd,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACf,MAAM,cAAc,CAAC;AAOtB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACrB,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,WAAW,EAEtB,mBAAmB,EAAE,OAAO,EAC5B,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,YAAY,EACzB,OAAO,EAAE,sBAAsB,EAC/B,SAAS,EAAE,EAAE,EACb,QAAQ,EAAE,CACN,QAAQ,EAAE,EAAE,EACZ,mBAAmB,CAAC,EAAE,OAAO,EAC7B,OAAO,CAAC,EAAE,OAAO,KAChB,IAAI,EACT,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,EACnC,WAAW,CAAC,EAAE,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,QAwGvC"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.syncState = void 0;
|
|
8
|
-
const getFluidFromView_1 = require("./getFluidFromView");
|
|
9
|
-
const getViewFromFluid_1 = require("./getViewFromFluid");
|
|
10
|
-
const getFluidState_1 = require("./getFluidState");
|
|
11
|
-
const setFluidState_1 = require("./setFluidState");
|
|
12
|
-
const getSchema_1 = require("./getSchema");
|
|
13
|
-
/**
|
|
14
|
-
* Function to combine both the view and Fluid states so that they are in sync. If the update
|
|
15
|
-
* is from a local update, the new Fluid state created from converting the new local view state
|
|
16
|
-
* is used to update the synced Fluid state, which in turn will update the local state on other clients.
|
|
17
|
-
* If it is an update triggered from a remote change on the synced state, the new Fluid state from the synced state
|
|
18
|
-
* is used to overwrite the local synced state and the new local view is created accordingly.
|
|
19
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
20
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
21
|
-
* @param syncedState - The shared map this Fluid object synced state is stored on
|
|
22
|
-
* @param viewState - The current view state
|
|
23
|
-
* @param setState - Callback to update the react view state
|
|
24
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
25
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
26
|
-
* respective converters
|
|
27
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
28
|
-
* respective converters
|
|
29
|
-
*/
|
|
30
|
-
function syncState(isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid) {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
// Use the provided Fluid state if it is available, or use the one fetched from the synced state
|
|
33
|
-
const currentFluidState = getFluidState_1.getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView);
|
|
34
|
-
if (currentFluidState === undefined) {
|
|
35
|
-
throw Error("Attempted to sync view and Fluid states before Fluid state was initialized");
|
|
36
|
-
}
|
|
37
|
-
// Fetch the schema
|
|
38
|
-
const schemaHandles = getSchema_1.getSchema(syncedStateId, syncedState);
|
|
39
|
-
if (schemaHandles === undefined) {
|
|
40
|
-
throw Error("No schema found stored on the root");
|
|
41
|
-
}
|
|
42
|
-
const { viewMatchingMapHandle, fluidMatchingMapHandle, } = schemaHandles;
|
|
43
|
-
const viewMatchingMap = (_a = fluidObjectMap.get(viewMatchingMapHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
44
|
-
const fluidMatchingMap = (_b = fluidObjectMap.get(fluidMatchingMapHandle.absolutePath)) === null || _b === void 0 ? void 0 : _b.fluidObject;
|
|
45
|
-
if (viewMatchingMap === undefined || fluidMatchingMap === undefined) {
|
|
46
|
-
throw Error("Failed to fetch shared map DDSes from the schema handles");
|
|
47
|
-
}
|
|
48
|
-
// Create the combined root state by combining the current root state and the new
|
|
49
|
-
// view state after it has been converted
|
|
50
|
-
let combinedFluidState = Object.assign({}, currentFluidState);
|
|
51
|
-
Object.entries(viewState).forEach(([viewKey, viewValue]) => {
|
|
52
|
-
const needsConverter = viewMatchingMap.get(viewKey);
|
|
53
|
-
let partialRootState = {};
|
|
54
|
-
if (needsConverter !== undefined) {
|
|
55
|
-
partialRootState = getFluidFromView_1.getFluidFromView(viewState, viewKey, currentFluidState, viewToFluid);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
partialRootState[viewKey] = viewState[viewKey];
|
|
59
|
-
}
|
|
60
|
-
// If it is from a synced state update, the values fetched from the synced state at the beginning
|
|
61
|
-
// overwrite those created here. Otherwise, the new values overwrite those in the synced state
|
|
62
|
-
if (isSyncedStateUpdate) {
|
|
63
|
-
combinedFluidState = Object.assign(Object.assign({}, partialRootState), combinedFluidState);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
combinedFluidState = Object.assign(Object.assign({}, combinedFluidState), partialRootState);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
// Create the combined view state by combining the current view with the new Fluid state
|
|
70
|
-
// after it has been converted
|
|
71
|
-
let combinedViewState = Object.assign(Object.assign({}, viewState), { fluidObjectMap });
|
|
72
|
-
Object.entries(currentFluidState).forEach(([fluidKey, fluidValue]) => {
|
|
73
|
-
const needsConverter = fluidMatchingMap.get(fluidKey);
|
|
74
|
-
let partialViewState = {};
|
|
75
|
-
if (needsConverter !== undefined) {
|
|
76
|
-
partialViewState = getViewFromFluid_1.getViewFromFluid(syncedStateId, syncedState, fluidKey, fluidObjectMap, fluidToView, combinedViewState, combinedFluidState);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
partialViewState[fluidKey] = currentFluidState[fluidKey];
|
|
80
|
-
}
|
|
81
|
-
// If it is from a synced state update, the values converted from the synced state overwrite those
|
|
82
|
-
// created here. Otherwise, the new view values overwrite those from the synced state.
|
|
83
|
-
if (isSyncedStateUpdate) {
|
|
84
|
-
combinedViewState = Object.assign(Object.assign({}, combinedViewState), partialViewState);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
combinedViewState = Object.assign(Object.assign({}, partialViewState), combinedViewState);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
// If it is a local update, broadcast it by setting it on the root and updating locally
|
|
91
|
-
// Otherwise, only update locally as the root update has already been broadcasted
|
|
92
|
-
if (!isSyncedStateUpdate) {
|
|
93
|
-
setFluidState_1.setFluidState(syncedStateId, syncedState, runtime, fluidObjectMap, fluidToView, combinedViewState, combinedFluidState, viewToFluid);
|
|
94
|
-
}
|
|
95
|
-
setState(combinedViewState, isSyncedStateUpdate, true);
|
|
96
|
-
}
|
|
97
|
-
exports.syncState = syncState;
|
|
98
|
-
//# sourceMappingURL=syncState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncState.js","sourceRoot":"","sources":["../../src/helpers/syncState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,yDAAsD;AACtD,yDAAsD;AACtD,mDAAgD;AAChD,mDAAgD;AAChD,2CAAwC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,SAAS,CAIrB,mBAA4B,EAC5B,aAAqB,EACrB,WAAyB,EACzB,OAA+B,EAC/B,SAAa,EACb,QAIS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KACL;IACD,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAxHD,8BAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport { ISharedMap } from \"@fluidframework/map\";\nimport {\n FluidObjectMap,\n IFluidState,\n IViewState,\n ViewToFluidMap,\n FluidToViewMap,\n ISyncedState,\n} from \"../interface\";\nimport { getFluidFromView } from \"./getFluidFromView\";\nimport { getViewFromFluid } from \"./getViewFromFluid\";\nimport { getFluidState } from \"./getFluidState\";\nimport { setFluidState } from \"./setFluidState\";\nimport { getSchema } from \"./getSchema\";\n\n/**\n * Function to combine both the view and Fluid states so that they are in sync. If the update\n * is from a local update, the new Fluid state created from converting the new local view state\n * is used to update the synced Fluid state, which in turn will update the local state on other clients.\n * If it is an update triggered from a remote change on the synced state, the new Fluid state from the synced state\n * is used to overwrite the local synced state and the new local view is created accordingly.\n * @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state\n * @param syncedStateId - Unique ID for this synced Fluid object's state\n * @param syncedState - The shared map this Fluid object synced state is stored on\n * @param viewState - The current view state\n * @param setState - Callback to update the react view state\n * @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects\n * @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the\n * respective converters\n * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n */\nexport function syncState<\n SV extends IViewState,\n SF extends IFluidState\n>(\n isSyncedStateUpdate: boolean,\n syncedStateId: string,\n syncedState: ISyncedState,\n runtime: IFluidDataStoreRuntime,\n viewState: SV,\n setState: (\n newState: SV,\n isSyncedStateUpdate?: boolean,\n isLocal?: boolean\n ) => void,\n fluidObjectMap: FluidObjectMap,\n fluidToView: FluidToViewMap<SV, SF>,\n viewToFluid?: ViewToFluidMap<SV, SF>,\n) {\n // Use the provided Fluid state if it is available, or use the one fetched from the synced state\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\n \"Attempted to sync view and Fluid states before Fluid state was initialized\",\n );\n }\n // Fetch the schema\n const schemaHandles = getSchema(\n syncedStateId,\n syncedState,\n );\n if (schemaHandles === undefined) {\n throw Error(\"No schema found stored on the root\");\n }\n const {\n viewMatchingMapHandle,\n fluidMatchingMapHandle,\n } = schemaHandles;\n\n const viewMatchingMap = fluidObjectMap.get(viewMatchingMapHandle.absolutePath)\n ?.fluidObject as ISharedMap;\n const fluidMatchingMap = fluidObjectMap.get(fluidMatchingMapHandle.absolutePath)\n ?.fluidObject as ISharedMap;\n\n if (viewMatchingMap === undefined || fluidMatchingMap === undefined) {\n throw Error(\"Failed to fetch shared map DDSes from the schema handles\");\n }\n\n // Create the combined root state by combining the current root state and the new\n // view state after it has been converted\n let combinedFluidState = { ...currentFluidState };\n Object.entries(viewState).forEach(([viewKey, viewValue]) => {\n const needsConverter = viewMatchingMap.get(viewKey);\n let partialRootState = {};\n if (needsConverter !== undefined) {\n partialRootState = getFluidFromView(\n viewState,\n viewKey as keyof SV,\n currentFluidState,\n viewToFluid,\n );\n } else {\n partialRootState[viewKey] = viewState[viewKey];\n }\n // If it is from a synced state update, the values fetched from the synced state at the beginning\n // overwrite those created here. Otherwise, the new values overwrite those in the synced state\n if (isSyncedStateUpdate) {\n combinedFluidState = { ...partialRootState, ...combinedFluidState };\n } else {\n combinedFluidState = { ...combinedFluidState, ...partialRootState };\n }\n });\n\n // Create the combined view state by combining the current view with the new Fluid state\n // after it has been converted\n let combinedViewState = { ...viewState, ...{ fluidObjectMap } };\n Object.entries(currentFluidState).forEach(([fluidKey, fluidValue]) => {\n const needsConverter = fluidMatchingMap.get(fluidKey);\n let partialViewState = {};\n if (needsConverter !== undefined) {\n partialViewState = getViewFromFluid(\n syncedStateId,\n syncedState,\n fluidKey as keyof SF,\n fluidObjectMap,\n fluidToView,\n combinedViewState,\n combinedFluidState,\n );\n } else {\n partialViewState[fluidKey] = currentFluidState[fluidKey];\n }\n // If it is from a synced state update, the values converted from the synced state overwrite those\n // created here. Otherwise, the new view values overwrite those from the synced state.\n if (isSyncedStateUpdate) {\n combinedViewState = { ...combinedViewState, ...partialViewState };\n } else {\n combinedViewState = { ...partialViewState, ...combinedViewState };\n }\n });\n\n // If it is a local update, broadcast it by setting it on the root and updating locally\n // Otherwise, only update locally as the root update has already been broadcasted\n if (!isSyncedStateUpdate) {\n setFluidState(\n syncedStateId,\n syncedState,\n runtime,\n fluidObjectMap,\n fluidToView,\n combinedViewState,\n combinedFluidState,\n viewToFluid,\n );\n }\n setState(combinedViewState, isSyncedStateUpdate, true);\n}\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IDirectoryValueChanged, SharedMap } from "@fluidframework/map";
|
|
6
|
-
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
-
import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
8
|
-
import { FluidObjectMap, IFluidState, IViewState, ViewToFluidMap, FluidToViewMap } from "../interface";
|
|
9
|
-
import { ISyncedState } from "..";
|
|
10
|
-
/**
|
|
11
|
-
* Add listeners too all the new handles passed in, store their respective Fluid objects
|
|
12
|
-
* on the fluidObjectMap, and then update both the local and synced state
|
|
13
|
-
* @param newHandleList - List of IFluidHandles for new Fluid objects that need to be added to the map
|
|
14
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
15
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
16
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
17
|
-
* @param syncedState - The shared map this Fluid object's synced state is stored on
|
|
18
|
-
* @param runtime - The data store runtime
|
|
19
|
-
* @param viewState - The current view state
|
|
20
|
-
* @param setState - Callback to update the react view state
|
|
21
|
-
* @param syncedStateCallback - The callback that will be triggered when the synced state value for the Fluid objects
|
|
22
|
-
* passed in changes
|
|
23
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
24
|
-
* respective converters
|
|
25
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
26
|
-
* respective converters
|
|
27
|
-
*/
|
|
28
|
-
export declare const updateStateAndFluidObjectMap: <SV extends IViewState, SF extends IFluidState>(newHandleList: IFluidHandle[], fluidObjectMap: FluidObjectMap, storedHandleMap: SharedMap, isSyncedStateUpdate: boolean, syncedStateId: string, syncedState: ISyncedState, runtime: IFluidDataStoreRuntime, viewState: SV, setState: (newState: SV, isSyncedStateUpdate?: boolean | undefined) => void, syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void, fluidToView: FluidToViewMap<SV, SF>, viewToFluid?: ViewToFluidMap<SV, SF> | undefined) => Promise<void>;
|
|
29
|
-
//# sourceMappingURL=updateStateAndFluidObjectMap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateStateAndFluidObjectMap.d.ts","sourceRoot":"","sources":["../../src/helpers/updateStateAndFluidObjectMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EACH,cAAc,EACd,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAIlC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,4BAA4B,iEAItB,YAAY,EAAE,mDAEZ,SAAS,uBACL,OAAO,iBACb,MAAM,eACR,YAAY,WAChB,sBAAsB,wFAE4B,IAAI,gCACjC,sBAAsB,SAAS,OAAO,KAAK,IAAI,yGAkC5E,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.updateStateAndFluidObjectMap = void 0;
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const syncState_1 = require("./syncState");
|
|
10
|
-
/**
|
|
11
|
-
* Add listeners too all the new handles passed in, store their respective Fluid objects
|
|
12
|
-
* on the fluidObjectMap, and then update both the local and synced state
|
|
13
|
-
* @param newHandleList - List of IFluidHandles for new Fluid objects that need to be added to the map
|
|
14
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
15
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
16
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
17
|
-
* @param syncedState - The shared map this Fluid object's synced state is stored on
|
|
18
|
-
* @param runtime - The data store runtime
|
|
19
|
-
* @param viewState - The current view state
|
|
20
|
-
* @param setState - Callback to update the react view state
|
|
21
|
-
* @param syncedStateCallback - The callback that will be triggered when the synced state value for the Fluid objects
|
|
22
|
-
* passed in changes
|
|
23
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
24
|
-
* respective converters
|
|
25
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
26
|
-
* respective converters
|
|
27
|
-
*/
|
|
28
|
-
const updateStateAndFluidObjectMap = async (newHandleList, fluidObjectMap, storedHandleMap, isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, syncedStateCallback, fluidToView, viewToFluid) => utils_1.asyncForEach(newHandleList, utils_1.addFluidObject, fluidObjectMap, syncedStateCallback, () => syncState_1.syncState(true, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid), storedHandleMap).then(() => syncState_1.syncState(isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid));
|
|
29
|
-
exports.updateStateAndFluidObjectMap = updateStateAndFluidObjectMap;
|
|
30
|
-
//# sourceMappingURL=updateStateAndFluidObjectMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateStateAndFluidObjectMap.js","sourceRoot":"","sources":["../../src/helpers/updateStateAndFluidObjectMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH,mCAAuD;AACvD,2CAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,4BAA4B,GAAG,KAAK,EAI7C,aAA6B,EAC7B,cAA8B,EAC9B,eAA0B,EAC1B,mBAA4B,EAC5B,aAAqB,EACrB,WAAyB,EACzB,OAA+B,EAC/B,SAAa,EACb,QAA+D,EAC/D,mBAA6E,EAC7E,WAAmC,EACnC,WAAoC,EACtC,EAAE,CACA,oBAAY,CACR,aAAa,EACb,sBAAc,EACd,cAAc,EACd,mBAAmB,EACnB,GAAG,EAAE,CACD,qBAAS,CACL,IAAI,EACJ,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACX,WAAW,CACd,EACL,eAAe,CAClB,CAAC,IAAI,CAAC,GAAG,EAAE,CACR,qBAAS,CACL,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACX,WAAW,CACd,CACJ,CAAC;AA/CO,QAAA,4BAA4B,gCA+CnC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDirectoryValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n FluidObjectMap,\n IFluidState,\n IViewState,\n ViewToFluidMap,\n FluidToViewMap,\n} from \"../interface\";\nimport { ISyncedState } from \"..\";\nimport { addFluidObject, asyncForEach } from \"./utils\";\nimport { syncState } from \"./syncState\";\n\n/**\n * Add listeners too all the new handles passed in, store their respective Fluid objects\n * on the fluidObjectMap, and then update both the local and synced state\n * @param newHandleList - List of IFluidHandles for new Fluid objects that need to be added to the map\n * @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects\n * @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state\n * @param syncedStateId - Unique ID for this synced Fluid object's state\n * @param syncedState - The shared map this Fluid object's synced state is stored on\n * @param runtime - The data store runtime\n * @param viewState - The current view state\n * @param setState - Callback to update the react view state\n * @param syncedStateCallback - The callback that will be triggered when the synced state value for the Fluid objects\n * passed in changes\n * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n * @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the\n * respective converters\n */\nexport const updateStateAndFluidObjectMap = async <\n SV extends IViewState,\n SF extends IFluidState\n>(\n newHandleList: IFluidHandle[],\n fluidObjectMap: FluidObjectMap,\n storedHandleMap: SharedMap,\n isSyncedStateUpdate: boolean,\n syncedStateId: string,\n syncedState: ISyncedState,\n runtime: IFluidDataStoreRuntime,\n viewState: SV,\n setState: (newState: SV, isSyncedStateUpdate?: boolean) => void,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n fluidToView: FluidToViewMap<SV, SF>,\n viewToFluid?: ViewToFluidMap<SV, SF>,\n) =>\n asyncForEach(\n newHandleList,\n addFluidObject,\n fluidObjectMap,\n syncedStateCallback,\n () =>\n syncState(\n true,\n syncedStateId,\n syncedState,\n runtime,\n viewState,\n setState,\n fluidObjectMap,\n fluidToView,\n viewToFluid,\n ),\n storedHandleMap,\n ).then(() =>\n syncState(\n isSyncedStateUpdate,\n syncedStateId,\n syncedState,\n runtime,\n viewState,\n setState,\n fluidObjectMap,\n fluidToView,\n viewToFluid,\n ),\n );\n"]}
|
package/dist/helpers/utils.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
6
|
-
import { IDirectoryValueChanged, SharedMap } from "@fluidframework/map";
|
|
7
|
-
import { FluidObjectMap, IFluidState, IViewState, IFluidConverter } from "../interface";
|
|
8
|
-
export declare function getByFluidKey<SV extends IViewState, SF extends IFluidState>(searchValue: string, map: Map<keyof SV, IFluidConverter<SV, SF>>): keyof SV | undefined;
|
|
9
|
-
export declare function asyncForEach(array: IFluidHandle[], callback: (handle: IFluidHandle, fluidObjectMap: FluidObjectMap, syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void, refreshView: () => void, storedHandleMap: SharedMap) => Promise<void>, fluidObjectMap: FluidObjectMap, syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void, refreshView: () => void, storedHandleMap: SharedMap): Promise<void>;
|
|
10
|
-
export declare const addFluidObject: <SV extends IViewState, SF extends IFluidState>(handle: IFluidHandle, fluidObjectMap: FluidObjectMap, syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void, refreshView: () => void, storedHandleMap: SharedMap) => Promise<void>;
|
|
11
|
-
export declare function isEquivalent(a: any, b: any): boolean;
|
|
12
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/helpers/utils.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EACH,cAAc,EACd,WAAW,EACX,UAAU,EACV,eAAe,EAClB,MAAM,cAAc,CAAC;AAGtB,wBAAgB,aAAa,CACzB,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,WAAW,EACxB,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,wBAMjE;AAED,wBAAsB,YAAY,CAC9B,KAAK,EAAE,YAAY,EAAE,EACrB,QAAQ,EAAE,CACN,MAAM,EAAE,YAAY,EACpB,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,EAC7E,WAAW,EAAE,MAAM,IAAI,EACvB,eAAe,EAAE,SAAS,KACzB,OAAO,CAAC,IAAI,CAAC,EAClB,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,EAC7E,WAAW,EAAE,MAAM,IAAI,EACvB,eAAe,EAAE,SAAS,GAC3B,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,eAAO,MAAM,cAAc,0DAIf,YAAY,gEAEU,sBAAsB,SAAS,OAAO,KAAK,IAAI,eAChE,MAAM,IAAI,mBACN,SAAS,KAC3B,QAAQ,IAAI,CAgCd,CAAC;AAEF,wBAAgB,YAAY,CAAC,CAAC,KAAA,EAAE,CAAC,KAAA,WAehC"}
|
package/dist/helpers/utils.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.isEquivalent = exports.addFluidObject = exports.asyncForEach = exports.getByFluidKey = void 0;
|
|
8
|
-
function getByFluidKey(searchValue, map) {
|
|
9
|
-
for (const [key, value] of map.entries()) {
|
|
10
|
-
if (value.fluidKey === searchValue) {
|
|
11
|
-
return key;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.getByFluidKey = getByFluidKey;
|
|
16
|
-
async function asyncForEach(array, callback, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap) {
|
|
17
|
-
const promises = [];
|
|
18
|
-
for (const value of array) {
|
|
19
|
-
promises.push(callback(value, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap));
|
|
20
|
-
}
|
|
21
|
-
await Promise.all(promises);
|
|
22
|
-
}
|
|
23
|
-
exports.asyncForEach = asyncForEach;
|
|
24
|
-
const addFluidObject = async (handle, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap) => {
|
|
25
|
-
const maybeValue = fluidObjectMap.get(handle.absolutePath);
|
|
26
|
-
let value = {
|
|
27
|
-
isListened: false,
|
|
28
|
-
isRuntimeMap: false,
|
|
29
|
-
};
|
|
30
|
-
if (maybeValue === undefined) {
|
|
31
|
-
fluidObjectMap.set(handle.absolutePath, value);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
value = maybeValue;
|
|
35
|
-
}
|
|
36
|
-
value.isListened = false;
|
|
37
|
-
fluidObjectMap.set(handle.absolutePath, value);
|
|
38
|
-
if (!storedHandleMap.has(handle.absolutePath)) {
|
|
39
|
-
storedHandleMap.set(handle.absolutePath, handle);
|
|
40
|
-
}
|
|
41
|
-
return handle.get().then((fluidObject) => {
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
43
|
-
if (value.isRuntimeMap) {
|
|
44
|
-
fluidObject.on("valueChanged", syncedStateCallback);
|
|
45
|
-
}
|
|
46
|
-
else if (value.listenedEvents !== undefined) {
|
|
47
|
-
for (const event of value.listenedEvents) {
|
|
48
|
-
fluidObject.on(event, refreshView);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
value.fluidObject = fluidObject;
|
|
52
|
-
value.isListened = true;
|
|
53
|
-
fluidObjectMap.set(handle.absolutePath, value);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
exports.addFluidObject = addFluidObject;
|
|
57
|
-
function isEquivalent(a, b) {
|
|
58
|
-
if (a === undefined || b === undefined) {
|
|
59
|
-
return a === b;
|
|
60
|
-
}
|
|
61
|
-
const aKeys = Object.getOwnPropertyNames(a);
|
|
62
|
-
const bKeys = Object.getOwnPropertyNames(b);
|
|
63
|
-
if (aKeys.length !== bKeys.length) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
for (const i of aKeys) {
|
|
67
|
-
if (a[i] !== b[i]) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
exports.isEquivalent = isEquivalent;
|
|
74
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/helpers/utils.tsx"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH,SAAgB,aAAa,CAG3B,WAAmB,EAAE,GAA2C;IAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE;QACtC,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,EAAE;YAChC,OAAO,GAAG,CAAC;SACd;KACJ;AACL,CAAC;AATD,sCASC;AAEM,KAAK,UAAU,YAAY,CAC9B,KAAqB,EACrB,QAMkB,EAClB,cAA8B,EAC9B,mBAA6E,EAC7E,WAAuB,EACvB,eAA0B;IAE1B,MAAM,QAAQ,GAAoB,EAAE,CAAC;I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c,EAAE;gBACrC,WAA4B,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;aACxD;SACJ;QACD,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;QAChC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;QACxB,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAzCW,QAAA,cAAc,kBAyCzB;AAEF,SAAgB,YAAY,CAAC,CAAC,EAAE,CAAC;IAC7B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE;QACpC,OAAO,CAAC,KAAK,CAAC,CAAC;KAClB;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAC5C,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE;QAC/B,OAAO,KAAK,CAAC;KAChB;IACD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACnB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACf,OAAO,KAAK,CAAC;SAChB;KACJ;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAfD,oCAeC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IDirectoryValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport {\n FluidObjectMap,\n IFluidState,\n IViewState,\n IFluidConverter,\n} from \"../interface\";\nimport { IFluidObjectMapItem } from \"..\";\n\nexport function getByFluidKey<\n SV extends IViewState,\n SF extends IFluidState\n>(searchValue: string, map: Map<keyof SV, IFluidConverter<SV, SF>>) {\n for (const [key, value] of map.entries()) {\n if (value.fluidKey === searchValue) {\n return key;\n }\n }\n}\n\nexport async function asyncForEach(\n array: IFluidHandle[],\n callback: (\n handle: IFluidHandle,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n ) => Promise<void>,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const value of array) {\n promises.push(\n callback(value, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap),\n );\n }\n await Promise.all(promises);\n}\n\nexport const addFluidObject = async <\n SV extends IViewState,\n SF extends IFluidState\n>(\n handle: IFluidHandle,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n): Promise<void> => {\n const maybeValue: IFluidObjectMapItem | undefined = fluidObjectMap.get(handle.absolutePath);\n let value: IFluidObjectMapItem = {\n isListened: false,\n isRuntimeMap: false,\n };\n if (maybeValue === undefined) {\n fluidObjectMap.set(\n handle.absolutePath,\n value,\n );\n } else {\n value = maybeValue;\n }\n value.isListened = false;\n fluidObjectMap.set(handle.absolutePath, value);\n if (!storedHandleMap.has(handle.absolutePath)) {\n storedHandleMap.set(handle.absolutePath, handle);\n }\n return handle.get().then((fluidObject) => {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (value.isRuntimeMap) {\n (fluidObject as SharedMap).on(\"valueChanged\", syncedStateCallback);\n } else if (value.listenedEvents !== undefined) {\n for (const event of value.listenedEvents) {\n (fluidObject as SharedObject).on(event, refreshView);\n }\n }\n value.fluidObject = fluidObject;\n value.isListened = true;\n fluidObjectMap.set(handle.absolutePath, value);\n });\n};\n\nexport function isEquivalent(a, b) {\n if (a === undefined || b === undefined) {\n return a === b;\n }\n const aKeys = Object.getOwnPropertyNames(a);\n const bKeys = Object.getOwnPropertyNames(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const i of aKeys) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n"]}
|