@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFluidFromView.js","sourceRoot":"","sources":["../../src/helpers/getFluidFromView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAI5B,KAAS,EACT,OAAiB,EACjB,UAAc,EACd,WAAoD;;IAEpD,MAAM,cAAc,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,OAAO,2CAAG,cAAc,CAAC;IACjE,IAAI,cAAc,KAAK,SAAS,EAAE;QAC9B,+DAA+D;QAC/D,OAAO,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;KAC5C;SAAM;QACH,MAAM,iBAAiB,GAAgB,EAAE,CAAC;QAC1C,iBAAiB,CAAC,OAAiB,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO,iBAAiB,CAAC;KAC5B;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidConverter,\n IViewState,\n IFluidState,\n} from \"../interface\";\n\n/**\n * Return a partial Fluid state containing the view state key identified converted into its\n * corresponding Fluid state value in the partial Fluid state returned\n * @param state - The current view state\n * @param viewKey - The view state key that needs to converted to its Fluid state\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 function getFluidFromView<\n SV extends IViewState,\n SF extends IFluidState\n>(\n state: SV,\n viewKey: keyof SV,\n fluidState: SF,\n viewToFluid?: Map<keyof SV, IFluidConverter<SV, SF>>,\n): Partial<SF> {\n const fluidConverter = viewToFluid?.get(viewKey)?.fluidConverter;\n if (fluidConverter !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return fluidConverter(state, fluidState);\n } else {\n const partialFluidState: Partial<SF> = {};\n partialFluidState[viewKey as string] = state[viewKey];\n return partialFluidState;\n }\n}\n"]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Return the Fluid state from the syncedState with all handles converted into Fluid objects
|
|
7
|
-
* @param syncedStateId - Unique ID for the synced state of this view
|
|
8
|
-
* @param syncedState - Shared map the synced state is stored on
|
|
9
|
-
* @param fluidObjectMap - Map of Fluid handle paths to their respective Fluid objects
|
|
10
|
-
* @param fluidToView - Map of the Fluid state keys contains the optional syncedState key parameter,
|
|
11
|
-
* in case the Fluid value is stored in the syncedState under a different key
|
|
12
|
-
*/
|
|
13
|
-
export function getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView) {
|
|
14
|
-
var _a, _b, _c, _d;
|
|
15
|
-
const fluidObjectStateHandle = syncedState.get(`syncedState-${syncedStateId}`);
|
|
16
|
-
if (fluidObjectStateHandle === undefined) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const fluidObjectState = (_a = fluidObjectMap.get(fluidObjectStateHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
20
|
-
if (fluidObjectState === undefined) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const fluidState = {};
|
|
24
|
-
for (const fluidKey of fluidObjectState.keys()) {
|
|
25
|
-
const createCallback = (_b = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _b === void 0 ? void 0 : _b.sharedObjectCreate;
|
|
26
|
-
let value = fluidObjectState.get(fluidKey);
|
|
27
|
-
if (value !== undefined && createCallback !== undefined) {
|
|
28
|
-
const possibleFluidObjectId = (_d = (_c = value) === null || _c === void 0 ? void 0 : _c.IFluidHandle) === null || _d === void 0 ? void 0 : _d.absolutePath;
|
|
29
|
-
if (possibleFluidObjectId !== undefined) {
|
|
30
|
-
value = (fluidObjectMap.get(possibleFluidObjectId));
|
|
31
|
-
fluidState[fluidKey] = value === null || value === void 0 ? void 0 : value.fluidObject;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
fluidState[fluidKey] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
fluidState[fluidKey] = value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return fluidState;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=getFluidState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFluidState.js","sourceRoot":"","sources":["../../src/helpers/getFluidState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAIzB,aAAqB,EACrB,WAAyB,EACzB,cAA8B,EAC9B,WAAmD;;IAEnD,MAAM,sBAAsB,GAAG,WAAW,CAAC,GAAG,CAC1C,eAAe,aAAa,EAAE,CACjC,CAAC;IACF,IAAI,sBAAsB,KAAK,SAAS,EAAE;QACtC,OAAO;KACV;IACD,MAAM,gBAAgB,GAAG,MAAA,cAAc,CAAC,GAAG,CAAC,sBAAsB,CAAC,YAAY,CAAC,0CAC1E,WAAwB,CAAC;IAC/B,IAAI,gBAAgB,KAAK,SAAS,EAAE;QAChC,OAAO;KACV;IACD,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,KAAK,MAAM,QAAQ,IAAI,gBAAgB,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,cAAc,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,QAAoB,2CACtD,kBAAkB,CAAC;QACzB,IAAI,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,SAAS,IAAI,cAAc,KAAK,SAAS,EAAE;YACrD,MAAM,qBAAqB,eAAI,KAAsB,0CAC/C,YAAY,0CAAE,YAAY,CAAC;YACjC,IAAI,qBAAqB,KAAK,SAAS,EAAE;gBACrC,KAAK,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAwB,CAAC;gBAC3E,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;aAC7C;iBAAM;gBACH,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;aAChC;SACJ;aAAM;YACH,UAAU,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;SAChC;KACJ;IACD,OAAO,UAAgB,CAAC;AAC5B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidObject,\n IFluidHandle,\n} from \"@fluidframework/core-interfaces\";\nimport { ISharedMap, SharedMap } from \"@fluidframework/map\";\nimport {\n IViewConverter,\n FluidObjectMap,\n IViewState,\n IFluidState,\n ISyncedState,\n IFluidObjectMapItem,\n} from \"..\";\n\n/**\n * Return the Fluid state from the syncedState with all handles converted into Fluid objects\n * @param syncedStateId - Unique ID for the synced state of this view\n * @param syncedState - Shared map the synced state is stored on\n * @param fluidObjectMap - Map of Fluid handle paths to their respective Fluid objects\n * @param fluidToView - Map of the Fluid state keys contains the optional syncedState key parameter,\n * in case the Fluid value is stored in the syncedState under a different key\n */\nexport function getFluidState<\n SV extends IViewState,\n SF extends IFluidState\n>(\n syncedStateId: string,\n syncedState: ISyncedState,\n fluidObjectMap: FluidObjectMap,\n fluidToView?: Map<keyof SF, IViewConverter<SV, SF>>,\n): SF | undefined {\n const fluidObjectStateHandle = syncedState.get<IFluidHandle<ISharedMap>>(\n `syncedState-${syncedStateId}`,\n );\n if (fluidObjectStateHandle === undefined) {\n return;\n }\n const fluidObjectState = fluidObjectMap.get(fluidObjectStateHandle.absolutePath)\n ?.fluidObject as SharedMap;\n if (fluidObjectState === undefined) {\n return;\n }\n const fluidState = {};\n for (const fluidKey of fluidObjectState.keys()) {\n const createCallback = fluidToView?.get(fluidKey as keyof SF)\n ?.sharedObjectCreate;\n let value = fluidObjectState.get(fluidKey);\n if (value !== undefined && createCallback !== undefined) {\n const possibleFluidObjectId = (value as IFluidObject)\n ?.IFluidHandle?.absolutePath;\n if (possibleFluidObjectId !== undefined) {\n value = (fluidObjectMap.get(possibleFluidObjectId)) as IFluidObjectMapItem;\n fluidState[fluidKey] = value?.fluidObject;\n } else {\n fluidState[fluidKey] = value;\n }\n } else {\n fluidState[fluidKey] = value;\n }\n }\n return fluidState as SF;\n}\n"]}
|
package/lib/helpers/getSchema.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns the schema stored on the synced state for this Fluid object
|
|
7
|
-
* @param syncedStateId - Unique ID for this synced data object's state
|
|
8
|
-
* @param syncedState - The shared map this Fluid shared state is stored on
|
|
9
|
-
*/
|
|
10
|
-
export const getSchema = (syncedStateId, syncedState) => syncedState.get(`schema-${syncedStateId}`);
|
|
11
|
-
//# sourceMappingURL=getSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSchema.js","sourceRoot":"","sources":["../../src/helpers/getSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACrB,aAAqB,EACrB,WAAyB,EACM,EAAE,CACjC,WAAW,CAAC,GAAG,CAAsB,UAAU,aAAa,EAAE,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISyncedState } from \"../interface\";\nimport { IFluidSchemaHandles } from \"./internalInterface\";\n\n/**\n * Returns the schema stored on the synced state for this Fluid object\n * @param syncedStateId - Unique ID for this synced data object's state\n * @param syncedState - The shared map this Fluid shared state is stored on\n */\nexport const getSchema = (\n syncedStateId: string,\n syncedState: ISyncedState,\n): IFluidSchemaHandles | undefined =>\n syncedState.get<IFluidSchemaHandles>(`schema-${syncedStateId}`);\n"]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { getFluidState } from "./getFluidState";
|
|
6
|
-
/**
|
|
7
|
-
* Return a partial view state containing the Fluid state key identified converted into its
|
|
8
|
-
* corresponding view state value in the partial view state returned
|
|
9
|
-
* @param syncedStateId - Unique ID for the synced state of this view
|
|
10
|
-
* @param syncedState - The shared map this shared state is stored on
|
|
11
|
-
* @param fluidKey - The key of the value within the Fluid state that we want converted
|
|
12
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
13
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
14
|
-
* respective converters
|
|
15
|
-
* @param combinedFluidState - Optional param containing the combined Fluid state so far to fetch from
|
|
16
|
-
*/
|
|
17
|
-
export function getViewFromFluid(syncedStateId, syncedState, fluidKey, fluidObjectMap, fluidToView, viewState, combinedFluidState) {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
const fluidObjectState = getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView);
|
|
20
|
-
if (fluidObjectState === undefined) {
|
|
21
|
-
throw Error("Attempted to fetch view from Fluid state before it was initialized");
|
|
22
|
-
}
|
|
23
|
-
let value = fluidObjectState[fluidKey];
|
|
24
|
-
if (combinedFluidState !== undefined) {
|
|
25
|
-
value = (_a = combinedFluidState[fluidKey]) !== null && _a !== void 0 ? _a : value;
|
|
26
|
-
}
|
|
27
|
-
const viewConverter = (_b = fluidToView.get(fluidKey)) === null || _b === void 0 ? void 0 : _b.viewConverter;
|
|
28
|
-
if (viewConverter !== undefined) {
|
|
29
|
-
const partialFluidState = {};
|
|
30
|
-
partialFluidState[fluidKey] = value;
|
|
31
|
-
return viewConverter(viewState, partialFluidState, fluidObjectMap);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const partialViewState = {};
|
|
35
|
-
const valueAsIFluidHandle = value.IFluidHandle;
|
|
36
|
-
const convertedValue = valueAsIFluidHandle !== undefined
|
|
37
|
-
? fluidObjectMap.get(valueAsIFluidHandle.absolutePath)
|
|
38
|
-
: value;
|
|
39
|
-
partialViewState[fluidKey] = convertedValue;
|
|
40
|
-
return partialViewState;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=getViewFromFluid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getViewFromFluid.js","sourceRoot":"","sources":["../../src/helpers/getViewFromFluid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAI5B,aAAqB,EACrB,WAAyB,EACzB,QAAkB,EAClB,cAA8B,EAC9B,WAAkD,EAClD,SAAa,EACb,kBAAgC;;IAEhC,MAAM,gBAAgB,GAAG,aAAa,CAClC,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,CACd,CAAC;IACF,IAAI,gBAAgB,KAAK,SAAS,EAAE;QAChC,MAAM,KAAK,CACP,oEAAoE,CACvE,CAAC;KACL;IACD,IAAI,KAAK,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,kBAAkB,KAAK,SAAS,EAAE;QAClC,KAAK,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,KAAK,CAAC;KACjD;IACD,MAAM,aAAa,SAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,0CAAE,aAAa,CAAC;IAC/D,IAAI,aAAa,KAAK,SAAS,EAAE;QAC7B,MAAM,iBAAiB,GAAgB,EAAE,CAAC;QAC1C,iBAAiB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QACpC,OAAO,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;KACtE;SAAM;QACH,MAAM,gBAAgB,GAAgB,EAAE,CAAC;QACzC,MAAM,mBAAmB,GAAI,KAAsB,CAAC,YAAY,CAAC;QACjE,MAAM,cAAc,GAAG,mBAAmB,KAAK,SAAS;YACpD,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,mBAAmB,CAAC,YAAY,CAAC;YACtD,CAAC,CAAC,KAAK,CAAC;QACZ,gBAAgB,CAAC,QAAkB,CAAC,GAAG,cAAc,CAAC;QACtD,OAAO,gBAAgB,CAAC;KAC3B;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidObject } from \"@fluidframework/core-interfaces\";\nimport {\n FluidObjectMap,\n IViewConverter,\n IViewState,\n IFluidState,\n ISyncedState,\n} from \"../interface\";\nimport { getFluidState } from \"./getFluidState\";\n\n/**\n * Return a partial view state containing the Fluid state key identified converted into its\n * corresponding view state value in the partial view state returned\n * @param syncedStateId - Unique ID for the synced state of this view\n * @param syncedState - The shared map this shared state is stored on\n * @param fluidKey - The key of the value within the Fluid state that we want converted\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 combinedFluidState - Optional param containing the combined Fluid state so far to fetch from\n */\nexport function getViewFromFluid<\n SV extends IViewState,\n SF extends IFluidState\n>(\n syncedStateId: string,\n syncedState: ISyncedState,\n fluidKey: keyof SF,\n fluidObjectMap: FluidObjectMap,\n fluidToView: Map<keyof SF, IViewConverter<SV, SF>>,\n viewState: SV,\n combinedFluidState?: Partial<SF>,\n): Partial<SV> {\n const fluidObjectState = getFluidState(\n syncedStateId,\n syncedState,\n fluidObjectMap,\n fluidToView,\n );\n if (fluidObjectState === undefined) {\n throw Error(\n \"Attempted to fetch view from Fluid state before it was initialized\",\n );\n }\n let value = fluidObjectState[fluidKey];\n if (combinedFluidState !== undefined) {\n value = combinedFluidState[fluidKey] ?? value;\n }\n const viewConverter = fluidToView.get(fluidKey)?.viewConverter;\n if (viewConverter !== undefined) {\n const partialFluidState: Partial<SF> = {};\n partialFluidState[fluidKey] = value;\n return viewConverter(viewState, partialFluidState, fluidObjectMap);\n } else {\n const partialViewState: Partial<SV> = {};\n const valueAsIFluidHandle = (value as IFluidObject).IFluidHandle;\n const convertedValue = valueAsIFluidHandle !== undefined\n ? fluidObjectMap.get(valueAsIFluidHandle.absolutePath)\n : value;\n partialViewState[fluidKey as string] = convertedValue;\n return partialViewState;\n }\n}\n"]}
|
package/lib/helpers/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
export * from "./getFluidFromView";
|
|
6
|
-
export * from "./getViewFromFluid";
|
|
7
|
-
export * from "./rootCallbackListener";
|
|
8
|
-
export * from "./syncState";
|
|
9
|
-
export * from "./updateStateAndFluidObjectMap";
|
|
10
|
-
export * from "./generateFluidObjectSchema";
|
|
11
|
-
export * from "./getFluidState";
|
|
12
|
-
export * from "./setFluidState";
|
|
13
|
-
export * from "./getSchema";
|
|
14
|
-
export * from "./setComponentSchema";
|
|
15
|
-
export * from "./initializeState";
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
package/lib/helpers/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./getFluidFromView\";\nexport * from \"./getViewFromFluid\";\nexport * from \"./rootCallbackListener\";\nexport * from \"./syncState\";\nexport * from \"./updateStateAndFluidObjectMap\";\nexport * from \"./generateFluidObjectSchema\";\nexport * from \"./getFluidState\";\nexport * from \"./setFluidState\";\nexport * from \"./getSchema\";\nexport * from \"./setComponentSchema\";\nexport * from \"./initializeState\";\n"]}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { syncedStateCallbackListener, updateStateAndFluidObjectMap, getSchema, getFluidState, } from ".";
|
|
6
|
-
/**
|
|
7
|
-
* Fetch the synced state for this view from the SyncedDataObject sharedState and add
|
|
8
|
-
* listeners for all state updates
|
|
9
|
-
* @param syncedStateId - Unique ID for this synced data object's state
|
|
10
|
-
* @param syncedState - The synced data object's shared state map
|
|
11
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
12
|
-
* respective converters
|
|
13
|
-
* @param dataProps - Contains the runtime and fluidObjectMap to create and store DDSes
|
|
14
|
-
* @param state - Current view state
|
|
15
|
-
* @param setState - Callback to update view state
|
|
16
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
17
|
-
* respective converters
|
|
18
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
19
|
-
* respective converters
|
|
20
|
-
*/
|
|
21
|
-
export async function initializeState(syncedStateId, syncedState, dataProps, state, setState, fluidToView, viewToFluid) {
|
|
22
|
-
var _a;
|
|
23
|
-
const schemaHandles = getSchema(syncedStateId, syncedState);
|
|
24
|
-
if ((schemaHandles === null || schemaHandles === void 0 ? void 0 : schemaHandles.storedHandleMapHandle.absolutePath) === undefined) {
|
|
25
|
-
throw Error(`Schema not initialized prior to render for ${syncedStateId}`);
|
|
26
|
-
}
|
|
27
|
-
const storedHandleMap = (_a = dataProps.fluidObjectMap.get(schemaHandles === null || schemaHandles === void 0 ? void 0 : schemaHandles.storedHandleMapHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
28
|
-
if (storedHandleMap === undefined) {
|
|
29
|
-
throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);
|
|
30
|
-
}
|
|
31
|
-
const unlistenedHandles = [];
|
|
32
|
-
for (const handle of storedHandleMap.values()) {
|
|
33
|
-
unlistenedHandles.push(handle);
|
|
34
|
-
}
|
|
35
|
-
const currentFluidState = getFluidState(syncedStateId, syncedState, dataProps.fluidObjectMap, fluidToView);
|
|
36
|
-
if (currentFluidState === undefined) {
|
|
37
|
-
throw Error("Synced state update triggered before Fluid state was initialized");
|
|
38
|
-
}
|
|
39
|
-
for (const fluidStateKey of fluidToView.keys()) {
|
|
40
|
-
const value = fluidToView.get(fluidStateKey);
|
|
41
|
-
if (value === undefined) {
|
|
42
|
-
throw Error("Cannot find fluidToView value");
|
|
43
|
-
}
|
|
44
|
-
if (value.sharedObjectCreate !== undefined) {
|
|
45
|
-
const fluidObject = currentFluidState[fluidStateKey];
|
|
46
|
-
unlistenedHandles.push(fluidObject.handle);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
state.isInitialized = true;
|
|
50
|
-
state.syncedStateId = syncedStateId;
|
|
51
|
-
// Define the synced state callback listener that will be responsible for triggering state updates on synced state
|
|
52
|
-
// value changes
|
|
53
|
-
const syncedStateCallback = (change, local) => {
|
|
54
|
-
const callback = syncedStateCallbackListener(dataProps.fluidObjectMap, storedHandleMap, syncedStateId, syncedState, dataProps.runtime, state, setState, fluidToView, viewToFluid);
|
|
55
|
-
return callback(change, local);
|
|
56
|
-
};
|
|
57
|
-
// Add the callback to the fluidObject's own synced state
|
|
58
|
-
syncedState.addValueChangedListener(syncedStateCallback);
|
|
59
|
-
storedHandleMap.on("valueChanged", (change, local) => {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
const handle = storedHandleMap.get(change.key);
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
63
|
-
if (handle !== undefined && !((_a = state.fluidObjectMap) === null || _a === void 0 ? void 0 : _a.has(handle.absolutePath))) {
|
|
64
|
-
(_b = state.fluidObjectMap) === null || _b === void 0 ? void 0 : _b.set(handle.absolutePath, {
|
|
65
|
-
isListened: false,
|
|
66
|
-
});
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
68
|
-
updateStateAndFluidObjectMap([handle], dataProps.fluidObjectMap, storedHandleMap, true, syncedStateId, syncedState, dataProps.runtime, state, setState, syncedStateCallback, fluidToView, viewToFluid);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return updateStateAndFluidObjectMap(unlistenedHandles, dataProps.fluidObjectMap, storedHandleMap, true, syncedStateId, syncedState, dataProps.runtime, state, setState, syncedStateCallback, fluidToView, viewToFluid);
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=initializeState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializeState.js","sourceRoot":"","sources":["../../src/helpers/initializeState.ts"],"names":[],"mappings":"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","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 {\n IValueChanged,\n SharedMap,\n} from \"@fluidframework/map\";\nimport {\n IFluidDataProps,\n FluidToViewMap,\n ViewToFluidMap,\n IViewState,\n IFluidState,\n ISyncedState,\n} from \"../interface\";\nimport {\n syncedStateCallbackListener,\n updateStateAndFluidObjectMap,\n getSchema,\n getFluidState,\n} from \".\";\n\n/**\n * Fetch the synced state for this view from the SyncedDataObject sharedState and add\n * listeners for all state updates\n * @param syncedStateId - Unique ID for this synced data object's state\n * @param syncedState - The synced data object's shared state map\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 dataProps - Contains the runtime and fluidObjectMap to create and store DDSes\n * @param state - Current view state\n * @param setState - Callback to update view state\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 async function initializeState<\n SV extends IViewState,\n SF extends IFluidState\n>(\n syncedStateId: string,\n syncedState: ISyncedState,\n dataProps: IFluidDataProps,\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): Promise<void> {\n const schemaHandles = getSchema(\n syncedStateId,\n syncedState,\n );\n if (schemaHandles?.storedHandleMapHandle.absolutePath === undefined) {\n throw Error(`Schema not initialized prior to render for ${syncedStateId}`);\n }\n const storedHandleMap = dataProps.fluidObjectMap.get(\n schemaHandles?.storedHandleMapHandle.absolutePath,\n )?.fluidObject as SharedMap;\n if (storedHandleMap === undefined) {\n throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);\n }\n const unlistenedHandles: IFluidHandle[] = [];\n for (const handle of storedHandleMap.values()) {\n unlistenedHandles.push(handle);\n }\n\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\"Synced state update triggered before Fluid state was initialized\");\n }\n\n for (const fluidStateKey of fluidToView.keys()) {\n const value = fluidToView.get(fluidStateKey);\n if (value === undefined) {\n throw Error(\"Cannot find fluidToView value\");\n }\n if (value.sharedObjectCreate !== undefined) {\n const fluidObject = currentFluidState[fluidStateKey] as any;\n unlistenedHandles.push(fluidObject.handle);\n }\n }\n\n state.isInitialized = true;\n state.syncedStateId = syncedStateId;\n // Define the synced state callback listener that will be responsible for triggering state updates on synced state\n // value changes\n const syncedStateCallback = (\n change: IValueChanged,\n local: boolean,\n ) => {\n const callback = syncedStateCallbackListener(\n dataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n dataProps.runtime,\n state,\n setState,\n fluidToView,\n viewToFluid,\n );\n return callback(change, local);\n };\n\n // Add the callback to the fluidObject's own synced state\n syncedState.addValueChangedListener(syncedStateCallback);\n storedHandleMap.on(\"valueChanged\", (\n change: IValueChanged,\n local: boolean,\n ) => {\n const handle = storedHandleMap.get<IFluidHandle>(change.key);\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (handle !== undefined && !state.fluidObjectMap?.has(handle.absolutePath)) {\n state.fluidObjectMap?.set(handle.absolutePath, {\n isListened: false,\n });\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap<SV, SF>(\n [handle],\n dataProps.fluidObjectMap,\n storedHandleMap,\n true,\n syncedStateId,\n syncedState,\n dataProps.runtime,\n state,\n setState,\n syncedStateCallback,\n fluidToView,\n viewToFluid,\n );\n }\n });\n\n return updateStateAndFluidObjectMap<SV, SF>(\n unlistenedHandles,\n dataProps.fluidObjectMap,\n storedHandleMap,\n true,\n syncedStateId,\n syncedState,\n dataProps.runtime,\n state,\n setState,\n syncedStateCallback,\n fluidToView,\n viewToFluid,\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internalInterface.js","sourceRoot":"","sources":["../../src/helpers/internalInterface.ts"],"names":[],"mappings":"AAAA;;;GAGG","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 { ISharedMap } from \"@fluidframework/map\";\n\n/**\n * The respective handles for the Fluid schema params listed above\n */\nexport interface IFluidSchemaHandles {\n viewMatchingMapHandle: IFluidHandle<ISharedMap>;\n fluidMatchingMapHandle: IFluidHandle<ISharedMap>;\n storedHandleMapHandle: IFluidHandle<ISharedMap>;\n}\n"]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { syncState } from "./syncState";
|
|
6
|
-
import { getByFluidKey } from "./utils";
|
|
7
|
-
import { getViewFromFluid } from "./getViewFromFluid";
|
|
8
|
-
import { getFluidState } from ".";
|
|
9
|
-
/**
|
|
10
|
-
* The callback that is added to the "valueChanged" event on the Fluid object this
|
|
11
|
-
* is passed in to. This will trigger state updates when the synced state value is updated
|
|
12
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
13
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
14
|
-
* @param syncedState - The shared map this Fluid object's synced state is stored on
|
|
15
|
-
* @param runtime - The data store runtime
|
|
16
|
-
* @param state - The current view state
|
|
17
|
-
* @param setState - Callback to update the react view state
|
|
18
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
19
|
-
* respective converters
|
|
20
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
21
|
-
* respective converters
|
|
22
|
-
*/
|
|
23
|
-
export const syncedStateCallbackListener = (fluidObjectMap, storedHandleMap, syncedStateId, syncedState, runtime, state, setState, fluidToView, viewToFluid) => (change, local) => {
|
|
24
|
-
const currentFluidState = getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView);
|
|
25
|
-
if (currentFluidState === undefined) {
|
|
26
|
-
throw Error("Synced state update triggered before Fluid state was initialized");
|
|
27
|
-
}
|
|
28
|
-
const viewToFluidKeys = viewToFluid !== undefined
|
|
29
|
-
? Array.from(viewToFluid.values()).map((item) => item.fluidKey)
|
|
30
|
-
: [];
|
|
31
|
-
if (!local && change.key === `syncedState-${syncedStateId}`) {
|
|
32
|
-
// If the update is to the synced Fluid state, update both the Fluid and view states
|
|
33
|
-
syncState(true, syncedStateId, syncedState, runtime, state, setState, fluidObjectMap, fluidToView, viewToFluid);
|
|
34
|
-
}
|
|
35
|
-
else if (viewToFluid !== undefined &&
|
|
36
|
-
viewToFluidKeys.includes(change.key)) {
|
|
37
|
-
// If the update is to a child Fluid object, trigger only a view update as the child itself will
|
|
38
|
-
// update its Fluid update
|
|
39
|
-
const stateKey = getByFluidKey(change.key, viewToFluid);
|
|
40
|
-
if (stateKey !== undefined) {
|
|
41
|
-
const newPartialState = getViewFromFluid(syncedStateId, syncedState, change.key, fluidObjectMap, fluidToView, state, currentFluidState);
|
|
42
|
-
state[stateKey] = newPartialState[stateKey];
|
|
43
|
-
state.fluidObjectMap = fluidObjectMap;
|
|
44
|
-
setState(state, true, local);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw Error(`Unable to extract view state from synced state change key: ${change.key}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=rootCallbackListener.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rootCallbackListener.js","sourceRoot":"","sources":["../../src/helpers/rootCallbackListener.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAIvC,cAA8B,EAC9B,eAA2B,EAC3B,aAAa,EACb,WAAyB,EACzB,OAA+B,EAC/B,KAAS,EACT,QAIS,EACT,WAAmC,EACnC,WAAoC,EACtC,EAAE,CAAC,CAAC,MAAqB,EAAE,KAAc,EAAE,EAAE;IAC3C,MAAM,iBAAiB,GAAG,aAAa,CACnC,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,CACd,CAAC;IACF,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACjC,MAAM,KAAK,CAAC,kEAAkE,CAAC,CAAC;KACnF;IACD,MAAM,eAAe,GAAa,WAAW,KAAK,SAAS;QACvD,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAkB,CAAC;QACzE,CAAC,CAAC,EAAE,CAAC;IACT,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,GAAG,KAAK,eAAe,aAAa,EAAE,EAAE;QACzD,oFAAoF;QACpF,SAAS,CACL,IAAI,EACJ,aAAa,EACb,WAAW,EACX,OAAO,EACP,KAAK,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,WAAW,CACd,CAAC;KACL;SAAM,IACH,WAAW,KAAK,SAAS;QACzB,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EACtC;QACE,gGAAgG;QAChG,0BAA0B;QAC1B,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACxD,IAAI,QAAQ,KAAK,SAAS,EAAE;YACxB,MAAM,eAAe,GAAG,gBAAgB,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","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
|
-
/**
|
|
6
|
-
* Store the schema on to the shared synced state
|
|
7
|
-
* @param syncedStateId - Unique ID to use for storing the synced state in the shared map
|
|
8
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
9
|
-
* @param schemaHandles - Handles for the schema SharedMaps
|
|
10
|
-
*/
|
|
11
|
-
export function setSchema(syncedStateId, syncedState, schemaHandles) {
|
|
12
|
-
syncedState.set(`schema-${syncedStateId}`, schemaHandles);
|
|
13
|
-
}
|
|
14
|
-
//# 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,MAAM,UAAU,SAAS,CACrB,aAAqB,EACrB,WAAyB,EACzB,aAAkC;IAElC,WAAW,CAAC,GAAG,CAAC,UAAU,aAAa,EAAE,EAAE,aAAa,CAAC,CAAC;AAC9D,CAAC","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,90 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { SharedMap } from "@fluidframework/map";
|
|
6
|
-
/**
|
|
7
|
-
* Store the Fluid state onto the shared synced state
|
|
8
|
-
* @param syncedStateId - Unique ID to use for storing the Fluid object's synced state in the map
|
|
9
|
-
* @param syncedState - The shared map that will be used to store the synced state
|
|
10
|
-
* @param runtime - The data store runtime
|
|
11
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
12
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
13
|
-
* respective converters
|
|
14
|
-
* @param newFluidState - The Fluid state to store on to the syncedState,
|
|
15
|
-
* after converting Fluid objects to their handles
|
|
16
|
-
*/
|
|
17
|
-
export function setFluidState(syncedStateId, syncedState, runtime, fluidObjectMap, fluidToView, newViewState, newFluidState, viewToFluid) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
19
|
-
const storedStateHandle = syncedState.get(`syncedState-${syncedStateId}`);
|
|
20
|
-
let storedState;
|
|
21
|
-
if (storedStateHandle) {
|
|
22
|
-
storedState = (_a = fluidObjectMap.get(storedStateHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
23
|
-
}
|
|
24
|
-
if (storedStateHandle === undefined || storedState === undefined) {
|
|
25
|
-
const newState = SharedMap.create(runtime);
|
|
26
|
-
fluidObjectMap.set(newState.handle.absolutePath, {
|
|
27
|
-
fluidObject: newState,
|
|
28
|
-
isRuntimeMap: true,
|
|
29
|
-
});
|
|
30
|
-
storedState = newState;
|
|
31
|
-
}
|
|
32
|
-
if (storedState === undefined) {
|
|
33
|
-
throw Error("Failed to fetch synced state from root");
|
|
34
|
-
}
|
|
35
|
-
for (const key of fluidToView.keys()) {
|
|
36
|
-
const fluidKey = key;
|
|
37
|
-
const syncedStateKey = (_b = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _b === void 0 ? void 0 : _b.rootKey;
|
|
38
|
-
const createCallback = (_c = fluidToView === null || fluidToView === void 0 ? void 0 : fluidToView.get(fluidKey)) === null || _c === void 0 ? void 0 : _c.sharedObjectCreate;
|
|
39
|
-
if (createCallback !== undefined) {
|
|
40
|
-
if (storedState.get(fluidKey) === undefined) {
|
|
41
|
-
const sharedObject = createCallback(runtime);
|
|
42
|
-
fluidObjectMap.set(sharedObject.handle.absolutePath, {
|
|
43
|
-
fluidObject: sharedObject,
|
|
44
|
-
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"],
|
|
45
|
-
});
|
|
46
|
-
storedState.set(fluidKey, sharedObject.handle);
|
|
47
|
-
if (syncedStateKey !== undefined) {
|
|
48
|
-
syncedState.set(syncedStateKey, sharedObject.handle);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
storedState.set(fluidKey, storedState.get(fluidKey));
|
|
53
|
-
if (syncedStateKey !== undefined) {
|
|
54
|
-
syncedState.set(syncedStateKey, syncedState.get(syncedStateKey));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (syncedStateKey !== undefined) {
|
|
59
|
-
const value = newFluidState !== undefined
|
|
60
|
-
? newFluidState[fluidKey]
|
|
61
|
-
: syncedState.get(syncedStateKey);
|
|
62
|
-
syncedState.set(syncedStateKey, value);
|
|
63
|
-
storedState.set(fluidKey, value);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const value = newFluidState !== undefined
|
|
67
|
-
? newFluidState[fluidKey]
|
|
68
|
-
: storedState.get(fluidKey);
|
|
69
|
-
storedState.set(fluidKey, value);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (viewToFluid !== undefined && newFluidState !== undefined) {
|
|
73
|
-
for (const key of viewToFluid.keys()) {
|
|
74
|
-
const viewKey = key;
|
|
75
|
-
const fluidConverter = (_f = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey)) === null || _f === void 0 ? void 0 : _f.fluidConverter;
|
|
76
|
-
const fluidKey = (_g = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey)) === null || _g === void 0 ? void 0 : _g.fluidKey;
|
|
77
|
-
if (fluidConverter !== undefined && fluidKey !== undefined) {
|
|
78
|
-
const value = fluidConverter(newViewState, newFluidState);
|
|
79
|
-
// Write this value to the stored state if it doesn't match the name of a view value
|
|
80
|
-
if (((_h = fluidToView.get(fluidKey)) === null || _h === void 0 ? void 0 : _h.sharedObjectCreate) ===
|
|
81
|
-
undefined) {
|
|
82
|
-
storedState.set(viewKey, value);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
syncedState.set(`syncedState-${syncedStateId}`, storedState.handle);
|
|
88
|
-
return storedState.handle;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=setFluidState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setFluidState.js","sourceRoot":"","sources":["../../src/helpers/setFluidState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAc,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAU5D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,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,KAAK,SAAS,IAAI,WAAW,KAAK,SAAS,EAAE;QAC9D,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7C,WAAW,EAAE,QAAQ;YACrB,YAAY,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,WAAW,GAAG,QAAQ,CAAC;KAC1B;IACD,IAAI,WAAW,KAAK,SAAS,EAAE;QAC3B,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAC;KACzD;IACD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,GAAa,CAAC;QAC/B,MAAM,cAAc,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,QAAoB,2CAAG,OAAO,CAAC;QACvE,MAAM,cAAc,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,QAAoB,2CACtD,kBAAkB,CAAC;QACzB,IAAI,cAAc,KAAK,SAAS,EAAE;YAC9B,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE;gBACzC,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;gBAC7C,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE;oBACjD,WAAW,EAAE,YAAY;oBACzB,cAAc,cAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,QAAoB,2CAC/C,cAAc,mCAAI,CAAC,cAAc,CAAC;iBAC3C,CAAC,CAAC;gBACH,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;gBAC/C,IAAI,cAAc,KAAK,SAAS,EAAE;oBAC9B,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;iBACxD;aACJ;iBAAM;gBACH,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACrD,IAAI,cAAc,KAAK,SAAS,EAAE;oBAC9B,WAAW,CAAC,GAAG,CACX,cAAc,EACd,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAClC,CAAC;iBACL;aACJ;SACJ;aAAM,IAAI,cAAc,KAAK,SAAS,EAAE;YACrC,MAAM,KAAK,GAAG,aAAa,KAAK,SAAS;gBACrC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;gBACzB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACtC,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACvC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;SACpC;aAAM;YACH,MAAM,KAAK,GAAG,aAAa,KAAK,SAAS;gBACrC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;gBACzB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;SACpC;KACJ;IACD,IAAI,WAAW,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,EAAE;QAC1D,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE;YAClC,MAAM,OAAO,GAAG,GAAa,CAAC;YAC9B,MAAM,cAAc,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,OAAmB,2CACrD,cAAc,CAAC;YACrB,MAAM,QAAQ,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,OAAmB,2CAC/C,QAAQ,CAAC;YACf,IAAI,cAAc,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE;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","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"]}
|
package/lib/helpers/syncState.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { getFluidFromView } from "./getFluidFromView";
|
|
6
|
-
import { getViewFromFluid } from "./getViewFromFluid";
|
|
7
|
-
import { getFluidState } from "./getFluidState";
|
|
8
|
-
import { setFluidState } from "./setFluidState";
|
|
9
|
-
import { getSchema } from "./getSchema";
|
|
10
|
-
/**
|
|
11
|
-
* Function to combine both the view and Fluid states so that they are in sync. If the update
|
|
12
|
-
* is from a local update, the new Fluid state created from converting the new local view state
|
|
13
|
-
* is used to update the synced Fluid state, which in turn will update the local state on other clients.
|
|
14
|
-
* If it is an update triggered from a remote change on the synced state, the new Fluid state from the synced state
|
|
15
|
-
* is used to overwrite the local synced state and the new local view is created accordingly.
|
|
16
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
17
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
18
|
-
* @param syncedState - The shared map this Fluid object synced state is stored on
|
|
19
|
-
* @param viewState - The current view state
|
|
20
|
-
* @param setState - Callback to update the react view state
|
|
21
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
22
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
23
|
-
* respective converters
|
|
24
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
25
|
-
* respective converters
|
|
26
|
-
*/
|
|
27
|
-
export function syncState(isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid) {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
// Use the provided Fluid state if it is available, or use the one fetched from the synced state
|
|
30
|
-
const currentFluidState = getFluidState(syncedStateId, syncedState, fluidObjectMap, fluidToView);
|
|
31
|
-
if (currentFluidState === undefined) {
|
|
32
|
-
throw Error("Attempted to sync view and Fluid states before Fluid state was initialized");
|
|
33
|
-
}
|
|
34
|
-
// Fetch the schema
|
|
35
|
-
const schemaHandles = getSchema(syncedStateId, syncedState);
|
|
36
|
-
if (schemaHandles === undefined) {
|
|
37
|
-
throw Error("No schema found stored on the root");
|
|
38
|
-
}
|
|
39
|
-
const { viewMatchingMapHandle, fluidMatchingMapHandle, } = schemaHandles;
|
|
40
|
-
const viewMatchingMap = (_a = fluidObjectMap.get(viewMatchingMapHandle.absolutePath)) === null || _a === void 0 ? void 0 : _a.fluidObject;
|
|
41
|
-
const fluidMatchingMap = (_b = fluidObjectMap.get(fluidMatchingMapHandle.absolutePath)) === null || _b === void 0 ? void 0 : _b.fluidObject;
|
|
42
|
-
if (viewMatchingMap === undefined || fluidMatchingMap === undefined) {
|
|
43
|
-
throw Error("Failed to fetch shared map DDSes from the schema handles");
|
|
44
|
-
}
|
|
45
|
-
// Create the combined root state by combining the current root state and the new
|
|
46
|
-
// view state after it has been converted
|
|
47
|
-
let combinedFluidState = Object.assign({}, currentFluidState);
|
|
48
|
-
Object.entries(viewState).forEach(([viewKey, viewValue]) => {
|
|
49
|
-
const needsConverter = viewMatchingMap.get(viewKey);
|
|
50
|
-
let partialRootState = {};
|
|
51
|
-
if (needsConverter !== undefined) {
|
|
52
|
-
partialRootState = getFluidFromView(viewState, viewKey, currentFluidState, viewToFluid);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
partialRootState[viewKey] = viewState[viewKey];
|
|
56
|
-
}
|
|
57
|
-
// If it is from a synced state update, the values fetched from the synced state at the beginning
|
|
58
|
-
// overwrite those created here. Otherwise, the new values overwrite those in the synced state
|
|
59
|
-
if (isSyncedStateUpdate) {
|
|
60
|
-
combinedFluidState = Object.assign(Object.assign({}, partialRootState), combinedFluidState);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
combinedFluidState = Object.assign(Object.assign({}, combinedFluidState), partialRootState);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
// Create the combined view state by combining the current view with the new Fluid state
|
|
67
|
-
// after it has been converted
|
|
68
|
-
let combinedViewState = Object.assign(Object.assign({}, viewState), { fluidObjectMap });
|
|
69
|
-
Object.entries(currentFluidState).forEach(([fluidKey, fluidValue]) => {
|
|
70
|
-
const needsConverter = fluidMatchingMap.get(fluidKey);
|
|
71
|
-
let partialViewState = {};
|
|
72
|
-
if (needsConverter !== undefined) {
|
|
73
|
-
partialViewState = getViewFromFluid(syncedStateId, syncedState, fluidKey, fluidObjectMap, fluidToView, combinedViewState, combinedFluidState);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
partialViewState[fluidKey] = currentFluidState[fluidKey];
|
|
77
|
-
}
|
|
78
|
-
// If it is from a synced state update, the values converted from the synced state overwrite those
|
|
79
|
-
// created here. Otherwise, the new view values overwrite those from the synced state.
|
|
80
|
-
if (isSyncedStateUpdate) {
|
|
81
|
-
combinedViewState = Object.assign(Object.assign({}, combinedViewState), partialViewState);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
combinedViewState = Object.assign(Object.assign({}, partialViewState), combinedViewState);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
// If it is a local update, broadcast it by setting it on the root and updating locally
|
|
88
|
-
// Otherwise, only update locally as the root update has already been broadcasted
|
|
89
|
-
if (!isSyncedStateUpdate) {
|
|
90
|
-
setFluidState(syncedStateId, syncedState, runtime, fluidObjectMap, fluidToView, combinedViewState, combinedFluidState, viewToFluid);
|
|
91
|
-
}
|
|
92
|
-
setState(combinedViewState, isSyncedStateUpdate, true);
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=syncState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncState.js","sourceRoot":"","sources":["../../src/helpers/syncState.ts"],"names":[],"mappings":"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","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,26 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { addFluidObject, asyncForEach } from "./utils";
|
|
6
|
-
import { syncState } from "./syncState";
|
|
7
|
-
/**
|
|
8
|
-
* Add listeners too all the new handles passed in, store their respective Fluid objects
|
|
9
|
-
* on the fluidObjectMap, and then update both the local and synced state
|
|
10
|
-
* @param newHandleList - List of IFluidHandles for new Fluid objects that need to be added to the map
|
|
11
|
-
* @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
|
|
12
|
-
* @param isSyncedStateUpdate - Is the update from a local state update or from one triggered by the synced state
|
|
13
|
-
* @param syncedStateId - Unique ID for this synced Fluid object's state
|
|
14
|
-
* @param syncedState - The shared map this Fluid object's synced state is stored on
|
|
15
|
-
* @param runtime - The data store runtime
|
|
16
|
-
* @param viewState - The current view state
|
|
17
|
-
* @param setState - Callback to update the react view state
|
|
18
|
-
* @param syncedStateCallback - The callback that will be triggered when the synced state value for the Fluid objects
|
|
19
|
-
* passed in changes
|
|
20
|
-
* @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
|
|
21
|
-
* respective converters
|
|
22
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
23
|
-
* respective converters
|
|
24
|
-
*/
|
|
25
|
-
export const updateStateAndFluidObjectMap = async (newHandleList, fluidObjectMap, storedHandleMap, isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, syncedStateCallback, fluidToView, viewToFluid) => asyncForEach(newHandleList, addFluidObject, fluidObjectMap, syncedStateCallback, () => syncState(true, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid), storedHandleMap).then(() => syncState(isSyncedStateUpdate, syncedStateId, syncedState, runtime, viewState, setState, fluidObjectMap, fluidToView, viewToFluid));
|
|
26
|
-
//# sourceMappingURL=updateStateAndFluidObjectMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateStateAndFluidObjectMap.js","sourceRoot":"","sources":["../../src/helpers/updateStateAndFluidObjectMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,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,YAAY,CACR,aAAa,EACb,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,GAAG,EAAE,CACD,SAAS,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,SAAS,CACL,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACX,WAAW,CACd,CACJ,CAAC","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"]}
|