@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
package/src/useReducerFluid.tsx
DELETED
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
8
|
-
import { SharedMap } from "@fluidframework/map";
|
|
9
|
-
import {
|
|
10
|
-
IViewState,
|
|
11
|
-
IFluidReducerProps,
|
|
12
|
-
IFluidDataProps,
|
|
13
|
-
instanceOfStateUpdateFunction,
|
|
14
|
-
instanceOfAsyncStateUpdateFunction,
|
|
15
|
-
instanceOfSelectorFunction,
|
|
16
|
-
instanceOfFluidObjectSelectorFunction,
|
|
17
|
-
instanceOfEffectFunction,
|
|
18
|
-
instanceOfAsyncEffectFunction,
|
|
19
|
-
IStateUpdateResult,
|
|
20
|
-
IFluidState,
|
|
21
|
-
IFluidReducer,
|
|
22
|
-
IFluidSelector,
|
|
23
|
-
ICombinedState,
|
|
24
|
-
ISyncedStateConfig,
|
|
25
|
-
} from "./interface";
|
|
26
|
-
import { useStateFluid } from "./useStateFluid";
|
|
27
|
-
import {
|
|
28
|
-
updateStateAndFluidObjectMap,
|
|
29
|
-
syncedStateCallbackListener,
|
|
30
|
-
getFluidState,
|
|
31
|
-
syncState,
|
|
32
|
-
getSchema,
|
|
33
|
-
} from "./helpers";
|
|
34
|
-
|
|
35
|
-
export function useReducerFluid<
|
|
36
|
-
SV extends IViewState,
|
|
37
|
-
SF extends IFluidState,
|
|
38
|
-
A extends IFluidReducer<SV, SF, C>,
|
|
39
|
-
B extends IFluidSelector<SV, SF, C>,
|
|
40
|
-
C extends IFluidDataProps
|
|
41
|
-
>(
|
|
42
|
-
props: IFluidReducerProps<SV, SF, A, B, C>,
|
|
43
|
-
initialViewState: SV,
|
|
44
|
-
): [ICombinedState<SV, SF, C>, A, B] {
|
|
45
|
-
const {
|
|
46
|
-
syncedStateId,
|
|
47
|
-
reducer,
|
|
48
|
-
selector,
|
|
49
|
-
syncedDataObject,
|
|
50
|
-
} = props;
|
|
51
|
-
const config = syncedDataObject.getConfig(syncedStateId);
|
|
52
|
-
if (config === undefined) {
|
|
53
|
-
throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
|
|
54
|
-
}
|
|
55
|
-
const dataProps = props.dataProps ?? syncedDataObject.dataProps as C;
|
|
56
|
-
// Get our combined synced state and setState callbacks from the useStateFluid function
|
|
57
|
-
const [viewState, setState] = useStateFluid<SV, SF>({
|
|
58
|
-
syncedStateId,
|
|
59
|
-
syncedDataObject,
|
|
60
|
-
dataProps,
|
|
61
|
-
}, initialViewState);
|
|
62
|
-
const syncedState = syncedDataObject.syncedState;
|
|
63
|
-
const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;
|
|
64
|
-
|
|
65
|
-
const schemaHandles = getSchema(
|
|
66
|
-
syncedStateId,
|
|
67
|
-
syncedState,
|
|
68
|
-
);
|
|
69
|
-
if (schemaHandles?.storedHandleMapHandle.absolutePath === undefined) {
|
|
70
|
-
throw Error(`Component schema not initialized prior to render for ${syncedStateId}`);
|
|
71
|
-
}
|
|
72
|
-
const storedHandleMap = dataProps.fluidObjectMap.get(
|
|
73
|
-
schemaHandles?.storedHandleMapHandle.absolutePath,
|
|
74
|
-
)?.fluidObject as SharedMap;
|
|
75
|
-
if (storedHandleMap === undefined) {
|
|
76
|
-
throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Dispatch is an in-memory object that will load the reducer actions provided by the user
|
|
80
|
-
// and add updates to the view and Fluid state based off of the type of function and
|
|
81
|
-
// state values that were updated. Think of it as prepping the data in the first
|
|
82
|
-
// stage of dynamic programming. The dispatch functions are copies of the user-defined functions
|
|
83
|
-
// but with the updates to synced state also handled
|
|
84
|
-
const dispatch = React.useCallback(
|
|
85
|
-
(
|
|
86
|
-
type: keyof A,
|
|
87
|
-
dispatchState?: ICombinedState<SV, SF, C>,
|
|
88
|
-
...args: any
|
|
89
|
-
) => {
|
|
90
|
-
// Retrieve the current state that is stored on the synced state for this Fluid object ID
|
|
91
|
-
const currentFluidState = getFluidState(
|
|
92
|
-
syncedStateId,
|
|
93
|
-
syncedState,
|
|
94
|
-
dataProps.fluidObjectMap,
|
|
95
|
-
fluidToView,
|
|
96
|
-
);
|
|
97
|
-
if (currentFluidState === undefined) {
|
|
98
|
-
throw Error(
|
|
99
|
-
"Attempted to dispatch function before fluid state was initialized",
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
const combinedDispatchFluidState: SF = {
|
|
103
|
-
...currentFluidState,
|
|
104
|
-
...dispatchState?.fluidState,
|
|
105
|
-
};
|
|
106
|
-
const combinedDispatchViewState: SV = {
|
|
107
|
-
...viewState,
|
|
108
|
-
...dispatchState?.viewState,
|
|
109
|
-
};
|
|
110
|
-
const combinedDispatchDataProps: C = {
|
|
111
|
-
...dataProps,
|
|
112
|
-
...dispatchState?.dataProps,
|
|
113
|
-
};
|
|
114
|
-
const combinedDispatchState = {
|
|
115
|
-
fluidState: combinedDispatchFluidState,
|
|
116
|
-
viewState: combinedDispatchViewState,
|
|
117
|
-
dataProps: combinedDispatchDataProps,
|
|
118
|
-
};
|
|
119
|
-
const action = reducer[type];
|
|
120
|
-
if (action !== undefined) {
|
|
121
|
-
if (instanceOfStateUpdateFunction<SV, SF, C>(action)) {
|
|
122
|
-
// If its a synchronous state update function, call it and inspect the result
|
|
123
|
-
// for new Fluid object handles
|
|
124
|
-
const result = (action.function as any)(
|
|
125
|
-
combinedDispatchState,
|
|
126
|
-
...args,
|
|
127
|
-
);
|
|
128
|
-
if (result.newComponentHandles !== undefined) {
|
|
129
|
-
// Fetch any new Fluid objects and add a listener to their synced state.
|
|
130
|
-
// Then update the view state.
|
|
131
|
-
const callback = syncedStateCallbackListener(
|
|
132
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
133
|
-
storedHandleMap,
|
|
134
|
-
syncedStateId,
|
|
135
|
-
syncedState,
|
|
136
|
-
combinedDispatchDataProps.runtime,
|
|
137
|
-
result.state.viewState,
|
|
138
|
-
setState,
|
|
139
|
-
fluidToView,
|
|
140
|
-
viewToFluid,
|
|
141
|
-
);
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
143
|
-
updateStateAndFluidObjectMap(
|
|
144
|
-
result.newComponentHandles,
|
|
145
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
146
|
-
storedHandleMap,
|
|
147
|
-
false,
|
|
148
|
-
syncedStateId,
|
|
149
|
-
syncedState,
|
|
150
|
-
combinedDispatchDataProps.runtime,
|
|
151
|
-
result.state.viewState,
|
|
152
|
-
setState,
|
|
153
|
-
callback,
|
|
154
|
-
fluidToView,
|
|
155
|
-
viewToFluid,
|
|
156
|
-
);
|
|
157
|
-
} else {
|
|
158
|
-
// Update the state directly
|
|
159
|
-
syncState(
|
|
160
|
-
false,
|
|
161
|
-
syncedStateId,
|
|
162
|
-
syncedState,
|
|
163
|
-
combinedDispatchDataProps.runtime,
|
|
164
|
-
result.state.viewState,
|
|
165
|
-
setState,
|
|
166
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
167
|
-
fluidToView,
|
|
168
|
-
viewToFluid,
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
} else if (instanceOfAsyncStateUpdateFunction<SV, SF, C>(action)) {
|
|
172
|
-
// In the case of an async function, the function promise is treated as a Thenable
|
|
173
|
-
// and the returned result is inspected after the function has completed
|
|
174
|
-
(action.asyncFunction as any)(
|
|
175
|
-
combinedDispatchState,
|
|
176
|
-
...args,
|
|
177
|
-
).then((result: IStateUpdateResult<SV, SF, C>) => {
|
|
178
|
-
const callback = syncedStateCallbackListener(
|
|
179
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
180
|
-
storedHandleMap,
|
|
181
|
-
syncedStateId,
|
|
182
|
-
syncedState,
|
|
183
|
-
combinedDispatchDataProps.runtime,
|
|
184
|
-
result.state.viewState,
|
|
185
|
-
setState,
|
|
186
|
-
fluidToView,
|
|
187
|
-
viewToFluid,
|
|
188
|
-
);
|
|
189
|
-
if (result.newFluidHandles !== undefined) {
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
191
|
-
updateStateAndFluidObjectMap(
|
|
192
|
-
result.newFluidHandles,
|
|
193
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
194
|
-
storedHandleMap,
|
|
195
|
-
false,
|
|
196
|
-
syncedStateId,
|
|
197
|
-
syncedState,
|
|
198
|
-
combinedDispatchDataProps.runtime,
|
|
199
|
-
result.state.viewState,
|
|
200
|
-
setState,
|
|
201
|
-
callback,
|
|
202
|
-
fluidToView,
|
|
203
|
-
viewToFluid,
|
|
204
|
-
);
|
|
205
|
-
} else {
|
|
206
|
-
syncState(
|
|
207
|
-
false,
|
|
208
|
-
syncedStateId,
|
|
209
|
-
syncedState,
|
|
210
|
-
combinedDispatchDataProps.runtime,
|
|
211
|
-
result.state.viewState,
|
|
212
|
-
setState,
|
|
213
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
214
|
-
fluidToView,
|
|
215
|
-
viewToFluid,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
} else if (instanceOfAsyncEffectFunction<SV, SF, C>(action)) {
|
|
220
|
-
(action.asyncFunction as any)(
|
|
221
|
-
combinedDispatchState,
|
|
222
|
-
...args,
|
|
223
|
-
).then(() =>
|
|
224
|
-
syncState(
|
|
225
|
-
false,
|
|
226
|
-
syncedStateId,
|
|
227
|
-
syncedState,
|
|
228
|
-
combinedDispatchDataProps.runtime,
|
|
229
|
-
combinedDispatchState.viewState,
|
|
230
|
-
setState,
|
|
231
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
232
|
-
fluidToView,
|
|
233
|
-
viewToFluid,
|
|
234
|
-
),
|
|
235
|
-
);
|
|
236
|
-
} else if (instanceOfEffectFunction<SV, SF, C>(action)) {
|
|
237
|
-
(action.function as any)(combinedDispatchState, ...args);
|
|
238
|
-
syncState(
|
|
239
|
-
false,
|
|
240
|
-
syncedStateId,
|
|
241
|
-
syncedState,
|
|
242
|
-
combinedDispatchDataProps.runtime,
|
|
243
|
-
combinedDispatchState.viewState,
|
|
244
|
-
setState,
|
|
245
|
-
combinedDispatchDataProps.fluidObjectMap,
|
|
246
|
-
fluidToView,
|
|
247
|
-
viewToFluid,
|
|
248
|
-
);
|
|
249
|
-
} else {
|
|
250
|
-
throw new Error(
|
|
251
|
-
`Action with key ${action} does not match an expected reducer action interface`,
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Action with key ${action} does not
|
|
257
|
-
exist in the reducers provided`,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
[reducer, viewState, setState, dataProps],
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
// The combinedReducer is then created using the dispatch functions we created above.
|
|
265
|
-
// This allows us to preserve the reducer interface while injecting Fluid-specific logic
|
|
266
|
-
// into the updating of the state. This is the second phase of DP, using the earlier created
|
|
267
|
-
// in-memory object to access the function the user is trying to use in constant time and then,
|
|
268
|
-
// subsequently performing it, taking the updated state, and applying it both locally and remotely
|
|
269
|
-
const combinedReducer = {};
|
|
270
|
-
Object.entries(reducer).forEach(([functionName, functionItem], i) => {
|
|
271
|
-
if ((functionItem as any).asyncFunction !== undefined) {
|
|
272
|
-
combinedReducer[functionName] = {
|
|
273
|
-
asyncFunction: (
|
|
274
|
-
dispatchState: ICombinedState<SV, SF, C>,
|
|
275
|
-
...args: any
|
|
276
|
-
) => dispatch(functionName, dispatchState, ...args),
|
|
277
|
-
};
|
|
278
|
-
} else {
|
|
279
|
-
combinedReducer[functionName] = {
|
|
280
|
-
function: (
|
|
281
|
-
dispatchState: ICombinedState<SV, SF, C>,
|
|
282
|
-
...args: any
|
|
283
|
-
) => dispatch(functionName, dispatchState, ...args),
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// Fetch is an in-memory object similar to dispatch, but now made for selector actions.
|
|
289
|
-
// Selectors are NOT used for updating the state but instead to be able to access
|
|
290
|
-
// and add other Fluid Fluid objects using the handle provided. If the handle provided is not available
|
|
291
|
-
// in our Fluid object map, it will be dynamically updated and setState will be called again
|
|
292
|
-
// with the updated Fluid object map available for use.
|
|
293
|
-
// Alternatively, if you would like to pre-load Fluid objects before React is initialized,
|
|
294
|
-
// you can do so and provide them in dataProps.
|
|
295
|
-
// Fetch can also be used to retrieve data from these Fluid objects as they will also be available as a parameter.
|
|
296
|
-
const fetch = React.useCallback(
|
|
297
|
-
(
|
|
298
|
-
type: keyof B,
|
|
299
|
-
fetchState?: ICombinedState<SV, SF, C>,
|
|
300
|
-
handle?: IFluidHandle,
|
|
301
|
-
) => {
|
|
302
|
-
// Retrieve the current state that is stored on the syncedState for this Fluid object ID
|
|
303
|
-
const currentFluidState = getFluidState(
|
|
304
|
-
syncedStateId,
|
|
305
|
-
syncedState,
|
|
306
|
-
dataProps.fluidObjectMap,
|
|
307
|
-
fluidToView,
|
|
308
|
-
);
|
|
309
|
-
if (currentFluidState === undefined) {
|
|
310
|
-
throw Error(
|
|
311
|
-
"Attempted to dispatch function before fluid state was initialized",
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
const combinedFetchFluidState: SF = {
|
|
315
|
-
...currentFluidState,
|
|
316
|
-
...fetchState?.fluidState,
|
|
317
|
-
};
|
|
318
|
-
const combinedFetchViewState: SV = {
|
|
319
|
-
...viewState,
|
|
320
|
-
...fetchState?.viewState,
|
|
321
|
-
};
|
|
322
|
-
const combinedFetchDataProps: C = {
|
|
323
|
-
...dataProps,
|
|
324
|
-
...fetchState?.dataProps,
|
|
325
|
-
};
|
|
326
|
-
const combinedFetchState = {
|
|
327
|
-
fluidState: combinedFetchFluidState,
|
|
328
|
-
viewState: combinedFetchViewState,
|
|
329
|
-
dataProps: combinedFetchDataProps,
|
|
330
|
-
};
|
|
331
|
-
const action = selector[type];
|
|
332
|
-
if (action !== undefined) {
|
|
333
|
-
if (instanceOfSelectorFunction<SV, SF, C>(action)) {
|
|
334
|
-
// Add any new handles that were returned by the selector to our list
|
|
335
|
-
// to be loaded to the fluid Fluid object map
|
|
336
|
-
let newHandles: IFluidHandle[] = [];
|
|
337
|
-
if (
|
|
338
|
-
handle !== undefined &&
|
|
339
|
-
instanceOfFluidObjectSelectorFunction<SV, SF, C>(action) &&
|
|
340
|
-
combinedFetchDataProps.fluidObjectMap.get(
|
|
341
|
-
handle.absolutePath,
|
|
342
|
-
) === undefined
|
|
343
|
-
) {
|
|
344
|
-
newHandles.push(handle);
|
|
345
|
-
}
|
|
346
|
-
const actionResult = (action.function as any)(
|
|
347
|
-
combinedFetchState,
|
|
348
|
-
handle,
|
|
349
|
-
);
|
|
350
|
-
if (
|
|
351
|
-
actionResult !== undefined &&
|
|
352
|
-
actionResult.newComponentHandles !== undefined
|
|
353
|
-
) {
|
|
354
|
-
newHandles = newHandles.concat(
|
|
355
|
-
actionResult.newComponentHandles,
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
// If there are handles, start a call to update the Fluid object map and then call the set state
|
|
359
|
-
// callback when it has finished to provide the updated map in the state
|
|
360
|
-
if (newHandles.length > 0) {
|
|
361
|
-
const callback = syncedStateCallbackListener(
|
|
362
|
-
combinedFetchDataProps.fluidObjectMap,
|
|
363
|
-
storedHandleMap,
|
|
364
|
-
syncedStateId,
|
|
365
|
-
syncedState,
|
|
366
|
-
combinedFetchDataProps.runtime,
|
|
367
|
-
combinedFetchState.viewState,
|
|
368
|
-
setState,
|
|
369
|
-
fluidToView,
|
|
370
|
-
viewToFluid,
|
|
371
|
-
);
|
|
372
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
373
|
-
updateStateAndFluidObjectMap(
|
|
374
|
-
newHandles,
|
|
375
|
-
combinedFetchDataProps.fluidObjectMap,
|
|
376
|
-
storedHandleMap,
|
|
377
|
-
true,
|
|
378
|
-
syncedStateId,
|
|
379
|
-
syncedState,
|
|
380
|
-
combinedFetchDataProps.runtime,
|
|
381
|
-
combinedFetchState.viewState,
|
|
382
|
-
setState,
|
|
383
|
-
callback,
|
|
384
|
-
fluidToView,
|
|
385
|
-
viewToFluid,
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
// Always return the result immediately
|
|
389
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
390
|
-
return actionResult;
|
|
391
|
-
} else {
|
|
392
|
-
throw new Error(
|
|
393
|
-
`Action with key ${action} does not match an expected selector action interface`,
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
} else {
|
|
397
|
-
throw new Error(
|
|
398
|
-
`Action with key ${action} does not
|
|
399
|
-
exist in the selectors provided`,
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
[selector, viewState, setState, dataProps],
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
// The combined selector is then similarly created with the Fluid-specific logic of adding any new Fluid objects
|
|
407
|
-
// to our Fluid object map interjected into the setState logic
|
|
408
|
-
const combinedSelector = {};
|
|
409
|
-
Object.entries(selector).forEach(([functionName, functionItem], i) => {
|
|
410
|
-
combinedSelector[functionName] = {
|
|
411
|
-
function: (
|
|
412
|
-
fetchState: ICombinedState<SV, SF, C>,
|
|
413
|
-
handle?: IFluidHandle,
|
|
414
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
415
|
-
) => fetch(functionName, fetchState, handle),
|
|
416
|
-
};
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
// Retrieve the current state that is stored on the syncedState for this Fluid object ID
|
|
420
|
-
const fluidState = getFluidState(
|
|
421
|
-
syncedStateId,
|
|
422
|
-
syncedState,
|
|
423
|
-
dataProps.fluidObjectMap,
|
|
424
|
-
fluidToView,
|
|
425
|
-
);
|
|
426
|
-
|
|
427
|
-
return [
|
|
428
|
-
{
|
|
429
|
-
viewState,
|
|
430
|
-
fluidState,
|
|
431
|
-
dataProps,
|
|
432
|
-
},
|
|
433
|
-
combinedReducer as A,
|
|
434
|
-
combinedSelector as B,
|
|
435
|
-
];
|
|
436
|
-
}
|
package/src/useStateFluid.tsx
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import {
|
|
8
|
-
IViewState,
|
|
9
|
-
IFluidProps,
|
|
10
|
-
IFluidState,
|
|
11
|
-
ISyncedStateConfig,
|
|
12
|
-
} from "./interface";
|
|
13
|
-
import { initializeState, syncState } from "./helpers";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A wrapper around the useState React hook that combines local and Fluid state updates
|
|
17
|
-
*/
|
|
18
|
-
export function useStateFluid<
|
|
19
|
-
SV extends IViewState,
|
|
20
|
-
SF extends IFluidState
|
|
21
|
-
>(
|
|
22
|
-
props: IFluidProps<SV, SF>, initialViewState: SV,
|
|
23
|
-
): [SV, (newState: SV, isSyncedStateUpdate?: boolean) => void] {
|
|
24
|
-
const {
|
|
25
|
-
syncedStateId,
|
|
26
|
-
syncedDataObject,
|
|
27
|
-
} = props;
|
|
28
|
-
const config = syncedDataObject.getConfig(syncedStateId);
|
|
29
|
-
if (config === undefined) {
|
|
30
|
-
throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
|
|
31
|
-
}
|
|
32
|
-
const syncedState = syncedDataObject.syncedState;
|
|
33
|
-
const dataProps = props.dataProps ?? syncedDataObject.dataProps;
|
|
34
|
-
const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;
|
|
35
|
-
// Establish the react state and setState functions using the initialViewState passed in
|
|
36
|
-
const [reactState, reactSetState] = React.useState<SV>(initialViewState);
|
|
37
|
-
|
|
38
|
-
// If this is the first time this function is being called in this session
|
|
39
|
-
// It's okay to disable eslint here as the state will be updated with the initialized values
|
|
40
|
-
// after the async call has finished
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
42
|
-
if (!reactState.isInitialized) {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
44
|
-
initializeState<SV, SF>(
|
|
45
|
-
syncedStateId,
|
|
46
|
-
syncedState,
|
|
47
|
-
dataProps,
|
|
48
|
-
reactState,
|
|
49
|
-
reactSetState,
|
|
50
|
-
fluidToView,
|
|
51
|
-
viewToFluid,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Create the fluidSetState function as a callback that in turn calls either our combined state
|
|
56
|
-
// update to both the local and Fluid state or just the local state respectively based off of
|
|
57
|
-
// if the state update is coming locally, i.e. not from the root
|
|
58
|
-
const fluidSetState = React.useCallback(
|
|
59
|
-
(newState: Partial<SV>, fromRootUpdate = false, isLocal: boolean = false) => {
|
|
60
|
-
const newCombinedState = {
|
|
61
|
-
...reactState,
|
|
62
|
-
...newState,
|
|
63
|
-
isInitialized: true,
|
|
64
|
-
};
|
|
65
|
-
if (isLocal) {
|
|
66
|
-
reactSetState(newCombinedState);
|
|
67
|
-
} else {
|
|
68
|
-
syncState(
|
|
69
|
-
fromRootUpdate,
|
|
70
|
-
syncedStateId,
|
|
71
|
-
syncedState,
|
|
72
|
-
dataProps.runtime,
|
|
73
|
-
newCombinedState,
|
|
74
|
-
reactSetState,
|
|
75
|
-
dataProps.fluidObjectMap,
|
|
76
|
-
fluidToView,
|
|
77
|
-
viewToFluid,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[syncedState, viewToFluid, reactState, reactSetState, dataProps],
|
|
82
|
-
);
|
|
83
|
-
return [reactState, fluidSetState];
|
|
84
|
-
}
|