@fluidframework/react 0.41.4 → 2.63.0-358419

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.
Files changed (342) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/.mocharc.cjs +15 -0
  3. package/CHANGELOG.md +282 -0
  4. package/README.md +122 -273
  5. package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
  6. package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
  7. package/api-extractor/api-extractor-lint-beta.cjs.json +5 -0
  8. package/api-extractor/api-extractor-lint-beta.esm.json +5 -0
  9. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  10. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  11. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  12. package/api-extractor-lint.json +4 -0
  13. package/api-extractor.json +2 -2
  14. package/api-report/react.alpha.api.md +114 -0
  15. package/api-report/react.beta.api.md +7 -0
  16. package/api-report/react.public.api.md +7 -0
  17. package/biome.jsonc +4 -0
  18. package/dist/alpha.d.ts +45 -0
  19. package/dist/beta.d.ts +15 -0
  20. package/dist/index.d.ts +11 -7
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +19 -17
  23. package/dist/index.js.map +1 -1
  24. package/dist/package.json +4 -0
  25. package/dist/propNode.d.ts +114 -0
  26. package/dist/propNode.d.ts.map +1 -0
  27. package/dist/propNode.js +43 -0
  28. package/dist/propNode.js.map +1 -0
  29. package/dist/public.d.ts +15 -0
  30. package/dist/reactSharedTreeView.d.ts +119 -0
  31. package/dist/reactSharedTreeView.d.ts.map +1 -0
  32. package/dist/reactSharedTreeView.js +206 -0
  33. package/dist/reactSharedTreeView.js.map +1 -0
  34. package/dist/simpleIdentifier.d.ts +19 -0
  35. package/dist/simpleIdentifier.d.ts.map +1 -0
  36. package/dist/simpleIdentifier.js +33 -0
  37. package/dist/simpleIdentifier.js.map +1 -0
  38. package/dist/useObservation.d.ts +83 -0
  39. package/dist/useObservation.d.ts.map +1 -0
  40. package/dist/useObservation.js +295 -0
  41. package/dist/useObservation.js.map +1 -0
  42. package/dist/useTree.d.ts +80 -0
  43. package/dist/useTree.d.ts.map +1 -0
  44. package/dist/useTree.js +137 -0
  45. package/dist/useTree.js.map +1 -0
  46. package/lib/alpha.d.ts +45 -0
  47. package/lib/beta.d.ts +15 -0
  48. package/lib/index.d.ts +16 -0
  49. package/lib/index.d.ts.map +1 -0
  50. package/lib/index.js +4 -7
  51. package/lib/index.js.map +1 -1
  52. package/lib/package.json +4 -0
  53. package/lib/propNode.d.ts +114 -0
  54. package/lib/propNode.d.ts.map +1 -0
  55. package/lib/propNode.js +36 -0
  56. package/lib/propNode.js.map +1 -0
  57. package/lib/public.d.ts +15 -0
  58. package/lib/reactSharedTreeView.d.ts +119 -0
  59. package/lib/reactSharedTreeView.d.ts.map +1 -0
  60. package/lib/reactSharedTreeView.js +176 -0
  61. package/lib/reactSharedTreeView.js.map +1 -0
  62. package/lib/simpleIdentifier.d.ts +19 -0
  63. package/lib/simpleIdentifier.d.ts.map +1 -0
  64. package/lib/simpleIdentifier.js +29 -0
  65. package/lib/simpleIdentifier.js.map +1 -0
  66. package/lib/test/propNode.spec.js +120 -0
  67. package/lib/test/propNode.spec.js.map +1 -0
  68. package/lib/test/reactSharedTreeView.spec.js +71 -0
  69. package/lib/test/reactSharedTreeView.spec.js.map +1 -0
  70. package/lib/test/simpleIdentifier.spec.js +18 -0
  71. package/lib/test/simpleIdentifier.spec.js.map +1 -0
  72. package/lib/test/useObservation.spec.js +162 -0
  73. package/lib/test/useObservation.spec.js.map +1 -0
  74. package/lib/test/useTree.spec.js +165 -0
  75. package/lib/test/useTree.spec.js.map +1 -0
  76. package/lib/tsdoc-metadata.json +11 -0
  77. package/lib/useObservation.d.ts +83 -0
  78. package/lib/useObservation.d.ts.map +1 -0
  79. package/lib/useObservation.js +266 -0
  80. package/lib/useObservation.js.map +1 -0
  81. package/lib/useTree.d.ts +80 -0
  82. package/lib/useTree.d.ts.map +1 -0
  83. package/lib/useTree.js +105 -0
  84. package/lib/useTree.js.map +1 -0
  85. package/package.json +150 -51
  86. package/react.test-files.tar +0 -0
  87. package/src/index.ts +42 -7
  88. package/src/propNode.ts +164 -0
  89. package/src/reactSharedTreeView.tsx +327 -0
  90. package/src/simpleIdentifier.ts +31 -0
  91. package/src/useObservation.ts +376 -0
  92. package/src/useTree.ts +147 -0
  93. package/tsconfig.cjs.json +7 -0
  94. package/tsconfig.json +12 -15
  95. package/tsdoc.json +4 -0
  96. package/.eslintrc.js +0 -11
  97. package/dist/createContextFluid.d.ts +0 -7
  98. package/dist/createContextFluid.d.ts.map +0 -1
  99. package/dist/createContextFluid.js +0 -46
  100. package/dist/createContextFluid.js.map +0 -1
  101. package/dist/helpers/generateFluidObjectSchema.d.ts +0 -16
  102. package/dist/helpers/generateFluidObjectSchema.d.ts.map +0 -1
  103. package/dist/helpers/generateFluidObjectSchema.js +0 -75
  104. package/dist/helpers/generateFluidObjectSchema.js.map +0 -1
  105. package/dist/helpers/getFluidFromView.d.ts +0 -15
  106. package/dist/helpers/getFluidFromView.d.ts.map +0 -1
  107. package/dist/helpers/getFluidFromView.js +0 -30
  108. package/dist/helpers/getFluidFromView.js.map +0 -1
  109. package/dist/helpers/getFluidState.d.ts +0 -15
  110. package/dist/helpers/getFluidState.d.ts.map +0 -1
  111. package/dist/helpers/getFluidState.js +0 -47
  112. package/dist/helpers/getFluidState.js.map +0 -1
  113. package/dist/helpers/getSchema.d.ts +0 -13
  114. package/dist/helpers/getSchema.d.ts.map +0 -1
  115. package/dist/helpers/getSchema.js +0 -15
  116. package/dist/helpers/getSchema.js.map +0 -1
  117. package/dist/helpers/getViewFromFluid.d.ts +0 -18
  118. package/dist/helpers/getViewFromFluid.d.ts.map +0 -1
  119. package/dist/helpers/getViewFromFluid.js +0 -47
  120. package/dist/helpers/getViewFromFluid.js.map +0 -1
  121. package/dist/helpers/index.d.ts +0 -16
  122. package/dist/helpers/index.d.ts.map +0 -1
  123. package/dist/helpers/index.js +0 -28
  124. package/dist/helpers/index.js.map +0 -1
  125. package/dist/helpers/initializeState.d.ts +0 -22
  126. package/dist/helpers/initializeState.d.ts.map +0 -1
  127. package/dist/helpers/initializeState.js +0 -77
  128. package/dist/helpers/initializeState.js.map +0 -1
  129. package/dist/helpers/internalInterface.d.ts +0 -15
  130. package/dist/helpers/internalInterface.d.ts.map +0 -1
  131. package/dist/helpers/internalInterface.js +0 -7
  132. package/dist/helpers/internalInterface.js.map +0 -1
  133. package/dist/helpers/rootCallbackListener.d.ts +0 -24
  134. package/dist/helpers/rootCallbackListener.d.ts.map +0 -1
  135. package/dist/helpers/rootCallbackListener.js +0 -55
  136. package/dist/helpers/rootCallbackListener.js.map +0 -1
  137. package/dist/helpers/setComponentSchema.d.ts +0 -14
  138. package/dist/helpers/setComponentSchema.d.ts.map +0 -1
  139. package/dist/helpers/setComponentSchema.js +0 -18
  140. package/dist/helpers/setComponentSchema.js.map +0 -1
  141. package/dist/helpers/setFluidState.d.ts +0 -20
  142. package/dist/helpers/setFluidState.d.ts.map +0 -1
  143. package/dist/helpers/setFluidState.js +0 -94
  144. package/dist/helpers/setFluidState.js.map +0 -1
  145. package/dist/helpers/syncState.d.ts +0 -25
  146. package/dist/helpers/syncState.d.ts.map +0 -1
  147. package/dist/helpers/syncState.js +0 -98
  148. package/dist/helpers/syncState.js.map +0 -1
  149. package/dist/helpers/updateStateAndFluidObjectMap.d.ts +0 -29
  150. package/dist/helpers/updateStateAndFluidObjectMap.d.ts.map +0 -1
  151. package/dist/helpers/updateStateAndFluidObjectMap.js +0 -30
  152. package/dist/helpers/updateStateAndFluidObjectMap.js.map +0 -1
  153. package/dist/helpers/utils.d.ts +0 -12
  154. package/dist/helpers/utils.d.ts.map +0 -1
  155. package/dist/helpers/utils.js +0 -74
  156. package/dist/helpers/utils.js.map +0 -1
  157. package/dist/interface.d.ts +0 -444
  158. package/dist/interface.d.ts.map +0 -1
  159. package/dist/interface.js +0 -18
  160. package/dist/interface.js.map +0 -1
  161. package/dist/reactView.d.ts +0 -32
  162. package/dist/reactView.d.ts.map +0 -1
  163. package/dist/reactView.js +0 -79
  164. package/dist/reactView.js.map +0 -1
  165. package/dist/syncedDataObject.d.ts +0 -80
  166. package/dist/syncedDataObject.d.ts.map +0 -1
  167. package/dist/syncedDataObject.js +0 -249
  168. package/dist/syncedDataObject.js.map +0 -1
  169. package/dist/syncedObjects/array/fluidSyncedArray.d.ts +0 -11
  170. package/dist/syncedObjects/array/fluidSyncedArray.d.ts.map +0 -1
  171. package/dist/syncedObjects/array/fluidSyncedArray.js +0 -78
  172. package/dist/syncedObjects/array/fluidSyncedArray.js.map +0 -1
  173. package/dist/syncedObjects/array/index.d.ts +0 -7
  174. package/dist/syncedObjects/array/index.d.ts.map +0 -1
  175. package/dist/syncedObjects/array/index.js +0 -19
  176. package/dist/syncedObjects/array/index.js.map +0 -1
  177. package/dist/syncedObjects/array/interface.d.ts +0 -33
  178. package/dist/syncedObjects/array/interface.d.ts.map +0 -1
  179. package/dist/syncedObjects/array/interface.js +0 -3
  180. package/dist/syncedObjects/array/interface.js.map +0 -1
  181. package/dist/syncedObjects/array/syncedArray.d.ts +0 -30
  182. package/dist/syncedObjects/array/syncedArray.d.ts.map +0 -1
  183. package/dist/syncedObjects/array/syncedArray.js +0 -42
  184. package/dist/syncedObjects/array/syncedArray.js.map +0 -1
  185. package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts +0 -11
  186. package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts.map +0 -1
  187. package/dist/syncedObjects/counter/fluidSyncedCounter.js +0 -79
  188. package/dist/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
  189. package/dist/syncedObjects/counter/index.d.ts +0 -7
  190. package/dist/syncedObjects/counter/index.d.ts.map +0 -1
  191. package/dist/syncedObjects/counter/index.js +0 -19
  192. package/dist/syncedObjects/counter/index.js.map +0 -1
  193. package/dist/syncedObjects/counter/interface.d.ts +0 -32
  194. package/dist/syncedObjects/counter/interface.d.ts.map +0 -1
  195. package/dist/syncedObjects/counter/interface.js +0 -3
  196. package/dist/syncedObjects/counter/interface.js.map +0 -1
  197. package/dist/syncedObjects/counter/syncedCounter.d.ts +0 -29
  198. package/dist/syncedObjects/counter/syncedCounter.d.ts.map +0 -1
  199. package/dist/syncedObjects/counter/syncedCounter.js +0 -36
  200. package/dist/syncedObjects/counter/syncedCounter.js.map +0 -1
  201. package/dist/syncedObjects/index.d.ts +0 -9
  202. package/dist/syncedObjects/index.d.ts.map +0 -1
  203. package/dist/syncedObjects/index.js +0 -21
  204. package/dist/syncedObjects/index.js.map +0 -1
  205. package/dist/syncedObjects/object/index.d.ts +0 -7
  206. package/dist/syncedObjects/object/index.d.ts.map +0 -1
  207. package/dist/syncedObjects/object/index.js +0 -19
  208. package/dist/syncedObjects/object/index.js.map +0 -1
  209. package/dist/syncedObjects/object/interface.d.ts +0 -13
  210. package/dist/syncedObjects/object/interface.d.ts.map +0 -1
  211. package/dist/syncedObjects/object/interface.js +0 -7
  212. package/dist/syncedObjects/object/interface.js.map +0 -1
  213. package/dist/syncedObjects/object/syncedObject.d.ts +0 -22
  214. package/dist/syncedObjects/object/syncedObject.d.ts.map +0 -1
  215. package/dist/syncedObjects/object/syncedObject.js +0 -46
  216. package/dist/syncedObjects/object/syncedObject.js.map +0 -1
  217. package/dist/syncedObjects/string/index.d.ts +0 -7
  218. package/dist/syncedObjects/string/index.d.ts.map +0 -1
  219. package/dist/syncedObjects/string/index.js +0 -19
  220. package/dist/syncedObjects/string/index.js.map +0 -1
  221. package/dist/syncedObjects/string/interface.d.ts +0 -16
  222. package/dist/syncedObjects/string/interface.d.ts.map +0 -1
  223. package/dist/syncedObjects/string/interface.js +0 -7
  224. package/dist/syncedObjects/string/interface.js.map +0 -1
  225. package/dist/syncedObjects/string/syncedString.d.ts +0 -25
  226. package/dist/syncedObjects/string/syncedString.d.ts.map +0 -1
  227. package/dist/syncedObjects/string/syncedString.js +0 -53
  228. package/dist/syncedObjects/string/syncedString.js.map +0 -1
  229. package/dist/useReducerFluid.d.ts +0 -7
  230. package/dist/useReducerFluid.d.ts.map +0 -1
  231. package/dist/useReducerFluid.js +0 -219
  232. package/dist/useReducerFluid.js.map +0 -1
  233. package/dist/useStateFluid.d.ts +0 -10
  234. package/dist/useStateFluid.d.ts.map +0 -1
  235. package/dist/useStateFluid.js +0 -67
  236. package/dist/useStateFluid.js.map +0 -1
  237. package/lib/createContextFluid.js +0 -23
  238. package/lib/createContextFluid.js.map +0 -1
  239. package/lib/helpers/generateFluidObjectSchema.js +0 -71
  240. package/lib/helpers/generateFluidObjectSchema.js.map +0 -1
  241. package/lib/helpers/getFluidFromView.js +0 -26
  242. package/lib/helpers/getFluidFromView.js.map +0 -1
  243. package/lib/helpers/getFluidState.js +0 -43
  244. package/lib/helpers/getFluidState.js.map +0 -1
  245. package/lib/helpers/getSchema.js +0 -11
  246. package/lib/helpers/getSchema.js.map +0 -1
  247. package/lib/helpers/getViewFromFluid.js +0 -43
  248. package/lib/helpers/getViewFromFluid.js.map +0 -1
  249. package/lib/helpers/index.js +0 -16
  250. package/lib/helpers/index.js.map +0 -1
  251. package/lib/helpers/initializeState.js +0 -73
  252. package/lib/helpers/initializeState.js.map +0 -1
  253. package/lib/helpers/internalInterface.js +0 -6
  254. package/lib/helpers/internalInterface.js.map +0 -1
  255. package/lib/helpers/rootCallbackListener.js +0 -51
  256. package/lib/helpers/rootCallbackListener.js.map +0 -1
  257. package/lib/helpers/setComponentSchema.js +0 -14
  258. package/lib/helpers/setComponentSchema.js.map +0 -1
  259. package/lib/helpers/setFluidState.js +0 -90
  260. package/lib/helpers/setFluidState.js.map +0 -1
  261. package/lib/helpers/syncState.js +0 -94
  262. package/lib/helpers/syncState.js.map +0 -1
  263. package/lib/helpers/updateStateAndFluidObjectMap.js +0 -26
  264. package/lib/helpers/updateStateAndFluidObjectMap.js.map +0 -1
  265. package/lib/helpers/utils.js +0 -67
  266. package/lib/helpers/utils.js.map +0 -1
  267. package/lib/interface.js +0 -8
  268. package/lib/interface.js.map +0 -1
  269. package/lib/reactView.js +0 -56
  270. package/lib/reactView.js.map +0 -1
  271. package/lib/syncedDataObject.js +0 -245
  272. package/lib/syncedDataObject.js.map +0 -1
  273. package/lib/syncedObjects/array/fluidSyncedArray.js +0 -72
  274. package/lib/syncedObjects/array/fluidSyncedArray.js.map +0 -1
  275. package/lib/syncedObjects/array/index.js +0 -7
  276. package/lib/syncedObjects/array/index.js.map +0 -1
  277. package/lib/syncedObjects/array/interface.js +0 -2
  278. package/lib/syncedObjects/array/interface.js.map +0 -1
  279. package/lib/syncedObjects/array/syncedArray.js +0 -37
  280. package/lib/syncedObjects/array/syncedArray.js.map +0 -1
  281. package/lib/syncedObjects/counter/fluidSyncedCounter.js +0 -73
  282. package/lib/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
  283. package/lib/syncedObjects/counter/index.js +0 -7
  284. package/lib/syncedObjects/counter/index.js.map +0 -1
  285. package/lib/syncedObjects/counter/interface.js +0 -2
  286. package/lib/syncedObjects/counter/interface.js.map +0 -1
  287. package/lib/syncedObjects/counter/syncedCounter.js +0 -31
  288. package/lib/syncedObjects/counter/syncedCounter.js.map +0 -1
  289. package/lib/syncedObjects/index.js +0 -9
  290. package/lib/syncedObjects/index.js.map +0 -1
  291. package/lib/syncedObjects/object/index.js +0 -7
  292. package/lib/syncedObjects/object/index.js.map +0 -1
  293. package/lib/syncedObjects/object/interface.js +0 -6
  294. package/lib/syncedObjects/object/interface.js.map +0 -1
  295. package/lib/syncedObjects/object/syncedObject.js +0 -41
  296. package/lib/syncedObjects/object/syncedObject.js.map +0 -1
  297. package/lib/syncedObjects/string/index.js +0 -7
  298. package/lib/syncedObjects/string/index.js.map +0 -1
  299. package/lib/syncedObjects/string/interface.js +0 -6
  300. package/lib/syncedObjects/string/interface.js.map +0 -1
  301. package/lib/syncedObjects/string/syncedString.js +0 -48
  302. package/lib/syncedObjects/string/syncedString.js.map +0 -1
  303. package/lib/useReducerFluid.js +0 -196
  304. package/lib/useReducerFluid.js.map +0 -1
  305. package/lib/useStateFluid.js +0 -44
  306. package/lib/useStateFluid.js.map +0 -1
  307. package/src/createContextFluid.tsx +0 -33
  308. package/src/helpers/generateFluidObjectSchema.ts +0 -95
  309. package/src/helpers/getFluidFromView.ts +0 -38
  310. package/src/helpers/getFluidState.ts +0 -67
  311. package/src/helpers/getSchema.ts +0 -18
  312. package/src/helpers/getViewFromFluid.ts +0 -68
  313. package/src/helpers/index.tsx +0 -16
  314. package/src/helpers/initializeState.ts +0 -162
  315. package/src/helpers/internalInterface.ts +0 -16
  316. package/src/helpers/rootCallbackListener.ts +0 -104
  317. package/src/helpers/setComponentSchema.ts +0 -21
  318. package/src/helpers/setFluidState.ts +0 -116
  319. package/src/helpers/syncState.ts +0 -159
  320. package/src/helpers/updateStateAndFluidObjectMap.ts +0 -85
  321. package/src/helpers/utils.tsx +0 -109
  322. package/src/interface.ts +0 -617
  323. package/src/reactView.tsx +0 -108
  324. package/src/syncedDataObject.ts +0 -337
  325. package/src/syncedObjects/array/fluidSyncedArray.ts +0 -126
  326. package/src/syncedObjects/array/index.ts +0 -7
  327. package/src/syncedObjects/array/interface.ts +0 -45
  328. package/src/syncedObjects/array/syncedArray.ts +0 -65
  329. package/src/syncedObjects/counter/fluidSyncedCounter.ts +0 -122
  330. package/src/syncedObjects/counter/index.ts +0 -7
  331. package/src/syncedObjects/counter/interface.ts +0 -44
  332. package/src/syncedObjects/counter/syncedCounter.ts +0 -64
  333. package/src/syncedObjects/index.ts +0 -9
  334. package/src/syncedObjects/object/index.ts +0 -7
  335. package/src/syncedObjects/object/interface.ts +0 -14
  336. package/src/syncedObjects/object/syncedObject.ts +0 -55
  337. package/src/syncedObjects/string/index.ts +0 -7
  338. package/src/syncedObjects/string/interface.ts +0 -17
  339. package/src/syncedObjects/string/syncedString.ts +0 -61
  340. package/src/useReducerFluid.tsx +0 -436
  341. package/src/useStateFluid.tsx +0 -84
  342. package/tsconfig.esnext.json +0 -7
@@ -1,122 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { SharedCounter } from "@fluidframework/counter";
7
- import {
8
- IViewState,
9
- IFluidState,
10
- ICombinedState,
11
- IFluidDataProps,
12
- useReducerFluid,
13
- SyncedDataObject,
14
- } from "../..";
15
- import { IFluidSyncedCounterReducer } from "./interface";
16
-
17
- export function setFluidSyncedCounterConfig<
18
- SV extends IViewState,
19
- SF extends IFluidState
20
- >(
21
- syncedDataObject: SyncedDataObject,
22
- syncedStateId: string,
23
- viewKey: keyof SV,
24
- fluidKey: keyof SF,
25
- defaultViewState: SV,
26
- sharedObjectCreate = SharedCounter.create,
27
- ) {
28
- syncedDataObject.setFluidConfig<SV, SF>(syncedStateId, {
29
- syncedStateId,
30
- fluidToView: new Map([
31
- [
32
- fluidKey,
33
- {
34
- type: SharedCounter.name,
35
- viewKey,
36
- viewConverter: (viewState, fluidState) => {
37
- if (fluidState[fluidKey] === undefined) {
38
- throw Error("Fluid state was not initialized");
39
- }
40
- viewState[viewKey] = (fluidState[
41
- fluidKey
42
- ] as any).value;
43
- return viewState;
44
- },
45
- sharedObjectCreate,
46
- listenedEvents: ["incremented"],
47
- },
48
- ],
49
- ]),
50
- viewToFluid: new Map([
51
- [
52
- viewKey,
53
- {
54
- type: "number",
55
- fluidKey,
56
- fluidConverter: (viewState, fluidState) => {
57
- if (fluidState[fluidKey] === undefined) {
58
- throw Error("Fluid state was not initialized");
59
- }
60
- viewState[viewKey] = (fluidState[
61
- fluidKey
62
- ] as any).value;
63
- return fluidState;
64
- },
65
- },
66
- ],
67
- ]),
68
- defaultViewState,
69
- });
70
- }
71
-
72
- export function generateSyncedCounterReducer<
73
- SV extends IViewState,
74
- SF extends IFluidState
75
- >(viewKey: keyof SV, fluidKey: keyof SF): IFluidSyncedCounterReducer<SV, SF> {
76
- const syncedCounterReducer = {
77
- increment: {
78
- function: (state, step: number) => {
79
- if (state?.fluidState?.[fluidKey] === undefined) {
80
- throw Error(
81
- "State was not initialized prior to dispatch call",
82
- );
83
- }
84
- const counter = state.fluidState[fluidKey];
85
- counter.increment(step);
86
- state.viewState[viewKey] = counter.value;
87
- return { state };
88
- },
89
- },
90
- };
91
- return syncedCounterReducer;
92
- }
93
-
94
- export function useSyncedCounterReducerFluid<
95
- SV extends IViewState,
96
- SF extends IFluidState
97
- >(
98
- syncedDataObject: SyncedDataObject,
99
- syncedStateId: string,
100
- viewKey: keyof SV,
101
- fluidKey: keyof SF,
102
- defaultViewState: SV,
103
- // eslint-disable-next-line @typescript-eslint/ban-types
104
- ): [ICombinedState<SV, SF, IFluidDataProps>, IFluidSyncedCounterReducer<SV, SF>, {}] {
105
- const syncedCounterReducer = generateSyncedCounterReducer(viewKey, fluidKey);
106
- return useReducerFluid<
107
- SV,
108
- SF,
109
- IFluidSyncedCounterReducer<SV, SF>,
110
- // eslint-disable-next-line @typescript-eslint/ban-types
111
- {},
112
- IFluidDataProps
113
- >(
114
- {
115
- syncedDataObject,
116
- syncedStateId,
117
- reducer: syncedCounterReducer,
118
- selector: {},
119
- },
120
- defaultViewState,
121
- );
122
- }
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export * from "./syncedCounter";
7
- export * from "./interface";
@@ -1,44 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ISharedCounter } from "@fluidframework/counter";
6
- import {
7
- IViewState,
8
- IFluidState,
9
- IFluidReducer,
10
- IFluidDataProps,
11
- FluidStateUpdateFunction,
12
- } from "../..";
13
-
14
- /**
15
- * The state interface exposed to the view for the synced counter
16
- */
17
- export interface ISyncedCounterViewState extends IViewState {
18
- value: number;
19
- }
20
-
21
- /**
22
- * The state interface for the Fluid data source that powers the synced counter
23
- */
24
- export interface ISyncedCounterFluidState extends IFluidState {
25
- counter: ISharedCounter;
26
- }
27
-
28
- /**
29
- * The reducer interface for incrementing the synced counter
30
- */
31
- export interface ISyncedCounterReducer {
32
- increment: (step: number) => void;
33
- }
34
-
35
- /**
36
- * The underlying reducer interface passed to the useReducerFluid hook to bind the view and Fluid
37
- * state definitions together
38
- */
39
- export interface IFluidSyncedCounterReducer<
40
- SV extends IViewState,
41
- SF extends IFluidState
42
- > extends IFluidReducer<SV, SF, IFluidDataProps> {
43
- increment: FluidStateUpdateFunction<SV, SF, IFluidDataProps>;
44
- }
@@ -1,64 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
6
- import { SharedCounter } from "@fluidframework/counter";
7
- import { SyncedDataObject } from "../..";
8
- import { ISyncedCounterViewState, ISyncedCounterFluidState, ISyncedCounterReducer } from "./interface";
9
- import { setFluidSyncedCounterConfig, useSyncedCounterReducerFluid } from "./fluidSyncedCounter";
10
-
11
- /**
12
- * Function to set the config for a synced counter on a syncedDataObject's SharedMap synced state. This
13
- * will initialize and provide a SharedCount for the view to use. This SharedString provided is automatically
14
- * bound to the state update of the functional view useSyncedCounter is called in.
15
- * @param syncedDataObject - The Fluid data object on which the synced state config is being set
16
- * @param syncedStateId - The ID of the view state that this config schema is being set for
17
- * @param defaultValue - The default number the view value will be set to prior to the Fluid counter initializing
18
- * @param sharedObjectCreate - The creation function for the SharedCounter. This can be set to pre-increment the counter
19
- */
20
- export function setSyncedCounterConfig(
21
- syncedDataObject: SyncedDataObject,
22
- syncedStateId: string,
23
- defaultValue: number = 0,
24
- sharedObjectCreate: (runtime: IFluidDataStoreRuntime) => SharedCounter = SharedCounter.create,
25
- ) {
26
- setFluidSyncedCounterConfig<ISyncedCounterViewState, ISyncedCounterFluidState>(
27
- syncedDataObject,
28
- syncedStateId,
29
- "value",
30
- "counter",
31
- { value: defaultValue },
32
- sharedObjectCreate,
33
- );
34
- }
35
-
36
- /**
37
- * Function to use the synced counter state powered by a SharedCounter that has been prepared for this view
38
- * @param syncedDataObject - The Fluid data object that holds the synced state config for this view
39
- * @param syncedStateId - The ID of this view state
40
- * @returns [
41
- * the number that the SharedCounter has been incremented to,
42
- * the reducer to modify the SharedCounter by incrementing it
43
- * ]
44
- */
45
- export function useSyncedCounter(
46
- syncedDataObject: SyncedDataObject,
47
- syncedStateId: string,
48
- defaultValue: number = 0,
49
- ): [number, ISyncedCounterReducer] {
50
- type viewState = ISyncedCounterViewState;
51
- type fluidState = ISyncedCounterFluidState;
52
- const [state, fluidReducer] = useSyncedCounterReducerFluid<viewState, fluidState>(
53
- syncedDataObject,
54
- syncedStateId,
55
- "value",
56
- "counter",
57
- { value: defaultValue },
58
- );
59
- const reducer: ISyncedCounterReducer = {
60
- increment: (step: number) => fluidReducer.increment.function(state, step),
61
- };
62
-
63
- return [state.viewState.value, reducer];
64
- }
@@ -1,9 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export * from "./array";
7
- export * from "./counter";
8
- export * from "./string";
9
- export * from "./object";
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export * from "./syncedObject";
7
- export * from "./interface";
@@ -1,14 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IFluidReactState } from "../..";
7
-
8
- /**
9
- * The synced state definition that will fill the value parameter with the type T object that will be
10
- * defined in the synced state config
11
- */
12
- export interface ISyncedMapState<T> extends IFluidReactState {
13
- value: T;
14
- }
@@ -1,55 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { SyncedDataObject } from "../..";
7
- import { useStateFluid } from "../../useStateFluid";
8
- import { ISyncedMapState } from "./interface";
9
-
10
- /**
11
- * Function to set the config for any type T object on a syncedDataObject's SharedMap synced state
12
- * @param syncedDataObject - The Fluid data object on which the synced state config is being set
13
- * @param syncedStateId - The ID of the view state that this config schema is being set for
14
- * @param defaultValue - The default value of type T that the state will be initialized with prior to
15
- * Fluid initialization
16
- */
17
- export function setSyncedObjectConfig<T>(
18
- syncedDataObject: SyncedDataObject,
19
- syncedStateId: string,
20
- defaultValue: T,
21
- ) {
22
- syncedDataObject.setConfig<ISyncedMapState<T>>(syncedStateId, {
23
- syncedStateId,
24
- fluidToView: new Map([
25
- [
26
- "value", {
27
- type: "any",
28
- viewKey: "value",
29
- },
30
- ],
31
- ]),
32
- defaultViewState: { value: defaultValue },
33
- });
34
- }
35
-
36
- /**
37
- * Function to use the synced state of type T that has been prepared for this view
38
- * @param syncedDataObject - The Fluid data object that holds the synced state config for this view
39
- * @param syncedStateId - The ID of this view state
40
- * @param defaultValue - The default value of type T that the view state will be initialized with
41
- * @returns [the initialized synced state of type T, a synced setState call for the state]
42
- */
43
- export function useSyncedObject<T>(
44
- syncedDataObject: SyncedDataObject,
45
- syncedStateId: string,
46
- defaultValue: T,
47
- ): [T, (newState: T) => void] {
48
- const [state, setState] = useStateFluid<ISyncedMapState<T>, ISyncedMapState<T>>(
49
- {
50
- syncedDataObject,
51
- syncedStateId,
52
- }, { value: defaultValue },
53
- );
54
- return [state.value, (newState: T) => setState({ value: newState })];
55
- }
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export * from "./syncedString";
7
- export * from "./interface";
@@ -1,17 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { SharedString } from "@fluidframework/sequence";
7
- import { IFluidReactState } from "../..";
8
-
9
- /**
10
- * The state definition for a synced string
11
- * TODO: Add a proper SharedString to string mapping but, for now, you can pass the pre-initialized SharedString
12
- * directly into the CollaborativeInput provided by the react-inputs package from within
13
- * the React functional view useSyncedString is called in
14
- */
15
- export interface ISyncedStringState extends IFluidReactState {
16
- value?: SharedString;
17
- }
@@ -1,61 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { SharedString } from "@fluidframework/sequence";
7
- import { SyncedDataObject } from "../..";
8
- import { useStateFluid } from "../../useStateFluid";
9
- import { ISyncedStringState } from "./interface";
10
-
11
- /**
12
- * Function to set the config for a synced string on a syncedDataObject's SharedMap synced state. This
13
- * will initialize and provide a SharedString for the view to use. This SharedString provided is automatically
14
- * bound to the state update of the functional view useSyncedString is called in. It can also easily be placed
15
- * in a CollaborativeInput within a React view.
16
- * @param syncedDataObject - The Fluid data object on which the synced state config is being set
17
- * @param syncedStateId - The ID of the view state that this config schema is being set for
18
- * @param defaultValue - The default string that the SharedString will be initialized as
19
- */
20
- export function setSyncedStringConfig(
21
- syncedDataObject: SyncedDataObject,
22
- syncedStateId: string,
23
- defaultValue: string,
24
- ) {
25
- syncedDataObject.setConfig<ISyncedStringState>(syncedStateId, {
26
- syncedStateId,
27
- fluidToView: new Map([
28
- [
29
- "value", {
30
- type: SharedString.name,
31
- viewKey: "value",
32
- sharedObjectCreate: (runtime) => {
33
- const url = SharedString.create(runtime);
34
- url.insertText(0, defaultValue);
35
- return url;
36
- },
37
- },
38
- ],
39
- ]) as any,
40
- defaultViewState: {},
41
- });
42
- }
43
-
44
- /**
45
- * Function to use the SharedString state that has been prepared for this view
46
- * @param syncedDataObject - The Fluid data object that holds the synced state config for this view
47
- * @param syncedStateId - The ID of this view state
48
- * @returns [the initialized SharedString, a synced setState call for the SharedString]
49
- */
50
- export function useSyncedString(
51
- syncedDataObject: SyncedDataObject,
52
- syncedStateId: string,
53
- ): [SharedString | undefined, (newState: ISyncedStringState) => void] {
54
- const [state, setState] = useStateFluid<ISyncedStringState, ISyncedStringState>(
55
- {
56
- syncedDataObject,
57
- syncedStateId,
58
- }, {},
59
- );
60
- return [state.value, setState];
61
- }