@fluidframework/react 0.41.3 → 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.
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,67 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export function getByFluidKey(searchValue, map) {
6
- for (const [key, value] of map.entries()) {
7
- if (value.fluidKey === searchValue) {
8
- return key;
9
- }
10
- }
11
- }
12
- export async function asyncForEach(array, callback, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap) {
13
- const promises = [];
14
- for (const value of array) {
15
- promises.push(callback(value, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap));
16
- }
17
- await Promise.all(promises);
18
- }
19
- export const addFluidObject = async (handle, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap) => {
20
- const maybeValue = fluidObjectMap.get(handle.absolutePath);
21
- let value = {
22
- isListened: false,
23
- isRuntimeMap: false,
24
- };
25
- if (maybeValue === undefined) {
26
- fluidObjectMap.set(handle.absolutePath, value);
27
- }
28
- else {
29
- value = maybeValue;
30
- }
31
- value.isListened = false;
32
- fluidObjectMap.set(handle.absolutePath, value);
33
- if (!storedHandleMap.has(handle.absolutePath)) {
34
- storedHandleMap.set(handle.absolutePath, handle);
35
- }
36
- return handle.get().then((fluidObject) => {
37
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
38
- if (value.isRuntimeMap) {
39
- fluidObject.on("valueChanged", syncedStateCallback);
40
- }
41
- else if (value.listenedEvents !== undefined) {
42
- for (const event of value.listenedEvents) {
43
- fluidObject.on(event, refreshView);
44
- }
45
- }
46
- value.fluidObject = fluidObject;
47
- value.isListened = true;
48
- fluidObjectMap.set(handle.absolutePath, value);
49
- });
50
- };
51
- export function isEquivalent(a, b) {
52
- if (a === undefined || b === undefined) {
53
- return a === b;
54
- }
55
- const aKeys = Object.getOwnPropertyNames(a);
56
- const bKeys = Object.getOwnPropertyNames(b);
57
- if (aKeys.length !== bKeys.length) {
58
- return false;
59
- }
60
- for (const i of aKeys) {
61
- if (a[i] !== b[i]) {
62
- return false;
63
- }
64
- }
65
- return true;
66
- }
67
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/helpers/utils.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,MAAM,UAAU,aAAa,CAG3B,WAAmB,EAAE,GAA2C;IAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE;QACtC,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,EAAE;YAChC,OAAO,GAAG,CAAC;SACd;KACJ;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,KAAqB,EACrB,QAMkB,EAClB,cAA8B,EAC9B,mBAA6E,EAC7E,WAAuB,EACvB,eAA0B;IAE1B,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;QACvB,QAAQ,CAAC,IAAI,CACT,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,WAAW,EAAE,eAAe,CAAC,CACrF,CAAC;KACL;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAI/B,MAAoB,EACpB,cAA8B,EAC9B,mBAA6E,EAC7E,WAAuB,EACvB,eAA0B,EACb,EAAE;IACf,MAAM,UAAU,GAAoC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5F,IAAI,KAAK,GAAwB;QAC7B,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACtB,CAAC;IACF,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,cAAc,CAAC,GAAG,CACd,MAAM,CAAC,YAAY,EACnB,KAAK,CACR,CAAC;KACL;SAAM;QACH,KAAK,GAAG,UAAU,CAAC;KACtB;IACD,KAAK,CAAC,UA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K,EAAE;QACnB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACf,OAAO,KAAK,CAAC;SAChB;KACJ;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IDirectoryValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport {\n FluidObjectMap,\n IFluidState,\n IViewState,\n IFluidConverter,\n} from \"../interface\";\nimport { IFluidObjectMapItem } from \"..\";\n\nexport function getByFluidKey<\n SV extends IViewState,\n SF extends IFluidState\n>(searchValue: string, map: Map<keyof SV, IFluidConverter<SV, SF>>) {\n for (const [key, value] of map.entries()) {\n if (value.fluidKey === searchValue) {\n return key;\n }\n }\n}\n\nexport async function asyncForEach(\n array: IFluidHandle[],\n callback: (\n handle: IFluidHandle,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n ) => Promise<void>,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const value of array) {\n promises.push(\n callback(value, fluidObjectMap, syncedStateCallback, refreshView, storedHandleMap),\n );\n }\n await Promise.all(promises);\n}\n\nexport const addFluidObject = async <\n SV extends IViewState,\n SF extends IFluidState\n>(\n handle: IFluidHandle,\n fluidObjectMap: FluidObjectMap,\n syncedStateCallback: (change: IDirectoryValueChanged, local: boolean) => void,\n refreshView: () => void,\n storedHandleMap: SharedMap,\n): Promise<void> => {\n const maybeValue: IFluidObjectMapItem | undefined = fluidObjectMap.get(handle.absolutePath);\n let value: IFluidObjectMapItem = {\n isListened: false,\n isRuntimeMap: false,\n };\n if (maybeValue === undefined) {\n fluidObjectMap.set(\n handle.absolutePath,\n value,\n );\n } else {\n value = maybeValue;\n }\n value.isListened = false;\n fluidObjectMap.set(handle.absolutePath, value);\n if (!storedHandleMap.has(handle.absolutePath)) {\n storedHandleMap.set(handle.absolutePath, handle);\n }\n return handle.get().then((fluidObject) => {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (value.isRuntimeMap) {\n (fluidObject as SharedMap).on(\"valueChanged\", syncedStateCallback);\n } else if (value.listenedEvents !== undefined) {\n for (const event of value.listenedEvents) {\n (fluidObject as SharedObject).on(event, refreshView);\n }\n }\n value.fluidObject = fluidObject;\n value.isListened = true;\n fluidObjectMap.set(handle.absolutePath, value);\n });\n};\n\nexport function isEquivalent(a, b) {\n if (a === undefined || b === undefined) {\n return a === b;\n }\n const aKeys = Object.getOwnPropertyNames(a);\n const bKeys = Object.getOwnPropertyNames(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const i of aKeys) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n"]}
package/lib/interface.js DELETED
@@ -1,8 +0,0 @@
1
- export const instanceOfIFluidLoadable = (object) => object === Object(object) && "IFluidLoadable" in object;
2
- export const instanceOfEffectFunction = (object) => object === Object(object) && "function" in object;
3
- export const instanceOfAsyncEffectFunction = (object) => object === Object(object) && "asyncFunction" in object;
4
- export const instanceOfStateUpdateFunction = (object) => object === Object(object) && "function" in object;
5
- export const instanceOfAsyncStateUpdateFunction = (object) => object === Object(object) && "asyncFunction" in object;
6
- export const instanceOfSelectorFunction = (object) => object === Object(object) && "function" in object;
7
- export const instanceOfFluidObjectSelectorFunction = (object) => object === Object(object) && "function" in object;
8
- //# sourceMappingURL=interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAwOA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACpC,MAAW,EACa,EAAE,CAC1B,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,gBAAgB,IAAI,MAAM,CAAC;AAgE5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKpC,MAAW,EAC6B,EAAE,CAC1C,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,IAAI,MAAM,CAAC;AAoBtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAKzC,MAAW,EACkC,EAAE,CAC/C,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,eAAe,IAAI,MAAM,CAAC;AAqB3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAKzC,MAAW,EACkC,EAAE,CAC/C,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,IAAI,MAAM,CAAC;AAwCtD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAK9C,MAAW,EACuC,EAAE,CACpD,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,eAAe,IAAI,MAAM,CAAC;AA6C3D,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAKtC,MAAW,EAC+B,EAAE,CAC5C,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,IAAI,MAAM,CAAC;AAEtD,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAKjD,MAAW,EACqC,EAAE,CAClD,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,IAAI,MAAM,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ISharedMap, IValueChanged } from \"@fluidframework/map\";\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidHandle,\n IFluidLoadable,\n IFluidObject,\n} from \"@fluidframework/core-interfaces\";\nimport { SyncedDataObject } from \"./syncedDataObject\";\n\n/**\n * The combined state contains the Fluid and view states and the data props\n * that are passed in to all reducers and selectors\n */\nexport interface ICombinedState<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The react view state that will be used for all view renders\n */\n viewState: SV;\n /**\n * The Fluid state that will be used to update the synced values in the state. This will be\n * undefined until it is initialized, after which the state will update with the defined values\n */\n fluidState?: SF;\n /**\n * Data props that are loaded in during the Fluid initialization step. This contains the runtime\n * and the Fluid object map, along with any other properties the user wants to pass to reducers\n * and selectors\n */\n dataProps: C;\n}\n\n/**\n * The Fluid schema that is generated on load and will be stored in the synced state\n */\nexport interface IFluidSchema {\n /**\n * (k,v) = (viewKeys, needsFluidConverter)\n */\n viewMatchingMap: ISharedMap;\n /**\n * (k,v) = (fluidKeys, needsViewConverter)\n */\n fluidMatchingMap: ISharedMap;\n /**\n * (k,v) = (path, handle)\n */\n storedHandleMap: ISharedMap;\n}\n\n/**\n * A map of the view state values that need conversion to their Fluid state counterparts and the\n * respective converters\n */\nexport type ViewToFluidMap<SV, SF> = Map<keyof SV, IFluidConverter<SV, SF>>;\n\n/**\n * A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n */\nexport type FluidToViewMap<SV, SF> = Map<keyof SF, IViewConverter<SV, SF>>;\n\n/**\n * The Fluid reducer, containing an object that is keyed by function name and contains state update and\n * effect functions. Each function will have the view state, fluid state, and data props passed into it\n * as parameters in the combined state. State update functions are used to modify values on the state and return\n * the updated state and any new Fluid object handles. Effect functions use values on the state to apply changes\n * elsewhere. They do not return any new objects or state.\n */\nexport interface IFluidReducer<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n [key: string]:\n | FluidAsyncStateUpdateFunction<SV, SF, C>\n | FluidStateUpdateFunction<SV, SF, C>\n | FluidEffectFunction<SV, SF, C>\n | FluidAsyncEffectFunction<SV, SF, C>;\n}\n\n/**\n * The Fluid selector, containing an object that is keyed by function name and contains selector\n * functions. Each function will have the view state, fluid state, and data props passed into it\n * as parameters in the combined state. Selector functions can also optionally pass in a\n * handle to fetch from the Fluid object map.\n * Selector functions are used to retrieve Fluid objects or parameters from other Fluid objects.\n * It offers a way to fetch these values and return them to the view, with the\n * Fluid object map being updated if the view requires a Fluid object that hasn't been locally loaded yet\n */\nexport interface IFluidSelector<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n [key: string]:\n | FluidSelectorFunction<SV, SF, C>\n | FluidObjectSelectorFunction<SV, SF, C>;\n}\n\n/**\n * Props passed in to create a FluidReactView or passed in to the useStateFluid hook\n */\nexport interface IFluidProps<\n SV extends IViewState,\n SF extends IFluidState\n > {\n /**\n * Unique ID to use for storing the synced state in the SyncedDataObject's syncedState SharedMap\n */\n syncedStateId: string;\n /**\n * An instance of the SyncedDataObject that this view will be rendered in\n */\n syncedDataObject: SyncedDataObject;\n /**\n * Data props containing the Fluid object map and the runtime\n * Optional as the above two will be passed by default. This only need to be defined\n * if there are additional values from the Fluid object lifecycle that need to be made\n * available to the reducers\n */\n dataProps?: IFluidDataProps;\n}\n\n/**\n * View converters to take the synced state Fluid value that they are keyed against in the FluidToView map\n * and convert them into their view state counterparts\n */\nexport interface IViewConverter<\n SV extends IViewState,\n SF extends IFluidState\n > {\n /**\n * The type of object this key in the Fluid state holds\n */\n type: string;\n /**\n * The corresponding value key within the view state type\n */\n viewKey: keyof SV;\n /**\n * A callback that takes in the partial Fluid state containing the value that\n * this converter maps to, and returns the corresponding partial view state\n */\n viewConverter?: (\n viewState: SV,\n fluidState: Partial<SF>,\n fluidObjectMap: FluidObjectMap\n ) => Partial<SV>;\n /**\n * If this is a fluid DDS SharedObject type (i.e. SharedCounter, SharedMap), supply its create function\n * here and add any events that it will fire to the listenedEvents param below to trigger state updates\n */\n sharedObjectCreate?: (runtime: IFluidDataStoreRuntime) => any;\n /**\n * List of events fired on this Fluid object that will trigger a state update\n */\n listenedEvents?: string[];\n /**\n * If this Fluid object is stored on the Fluid DataObject root under a different key\n * than the name of this Fluid state key within the synced state map,\n * provide the key on the root for this object here. The changes will also\n * reflect under that key if the data needs to be used elsewhere\n */\n rootKey?: string;\n}\n\n/**\n * Fluid converters to take the view state value that they are keyed against in the ViewToFluid map\n * and convert them into their synced Fluid state counterparts\n */\nexport interface IFluidConverter<\n SV extends IViewState,\n SF extends IFluidState\n > {\n /**\n * The type of object this key in the view state holds\n */\n type: string;\n /**\n * The corresponding value within the Fluid state\n */\n fluidKey: keyof SF;\n /**\n * A callback that takes in the partial view state containing the value that\n * this converter maps to, and optionally returns a value. This value will be automatically set on the synced state\n * under the view key this converter maps to\n */\n fluidConverter?: (viewState: SV, fluidState: Partial<SF>) => any;\n}\n\n/**\n * Base interface to extend from for the Fluid state. These values can and should be left\n * undefined when passing in the initial state as they will be used to establish the Fluid state\n */\nexport interface IFluidState {\n /**\n * The unique state ID for this React Fluid view\n */\n syncedStateId?: string;\n /**\n * Boolean indicating if any DDSes or Fluid objects on this state are being listened on\n * for synced state updates to trigger React state updates\n */\n isInitialized?: boolean;\n}\n\n/**\n * Base interface to extend from for the view state.\n * This should be crafted based off of what the view will use from the Fluid state.\n */\nexport interface IViewState\n extends IFluidState {\n /**\n * The map containing the locally available Fluid objects that have been loaded. If there are\n * any Fluid objects loaded during initialization that the view needs to use,\n * they should be fetched and loaded in here.\n * Any new Fluid objects added through reducers/selectors during the React lifecycle\n * will be automatically added to this map and the state will re-update when they become asynchronously available\n */\n fluidObjectMap?: FluidObjectMap;\n}\n\nexport type IFluidReactState = IFluidState & IViewState;\n\nexport const instanceOfIFluidLoadable = (\n object: any,\n): object is IFluidLoadable =>\n object === Object(object) && \"IFluidLoadable\" in object;\n\n/**\n * The values stored in the Fluid object map\n */\nexport interface IFluidObjectMapItem {\n /**\n * The actual Fluid object that the path this value is keyed against leads to\n */\n fluidObject?: IFluidObject & IFluidLoadable;\n /**\n * Boolean indicating if we are listening to changes on this Fluid object's synced state to trigger React\n * state updates. Only set if you want custom behavior for adding listeners to your Fluid state\n */\n isListened?: boolean;\n /**\n * List of events fired on this Fluid object that will trigger a state update\n */\n listenedEvents?: string[];\n /**\n * INTERNAL\n * Does not need to be set\n * Is this a SharedMap that was added as a Fluid React requirement\n */\n isRuntimeMap?: boolean;\n}\n\n/**\n * A map of the Fluid object handle absolute path to the Fluid object\n */\nexport type FluidObjectMap = Map<string, IFluidObjectMapItem>;\n\n/**\n * Base interface to extend from for the data props that will be passed in for reducers and\n * selectors to use to offer inter-Fluid object operability\n */\nexport interface IFluidDataProps {\n /**\n * The Fluid data store runtime passed in from Fluid object initialization\n */\n runtime: IFluidDataStoreRuntime;\n /**\n * The running map of all the Fluid objects being used to render the React view. This\n * can be view/data Fluid objects, and they will be asynchronously loaded here so that they are,\n * in turn, synchronously available for the view when the state updates after they are fetched\n */\n fluidObjectMap: FluidObjectMap;\n}\n\n/**\n * Definition for an effect function used in reducers\n */\nexport interface FluidEffectFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The function defined here will take the combined state and apply some\n * logic that does not cause any state update changes\n */\n function: (oldState?: ICombinedState<SV, SF, C>, ...args: any) => void;\n}\n\nexport const instanceOfEffectFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidEffectFunction<SV, SF, C> =>\n object === Object(object) && \"function\" in object;\n\n/**\n * Definition for an async effect function used in reducers\n */\nexport interface FluidAsyncEffectFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The function defined here will take the combined state and apply some\n * async logic that does not cause any state update changes\n */\n asyncFunction: (\n oldState?: ICombinedState<SV, SF, C>,\n ...args: any\n ) => Promise<void>;\n}\n\nexport const instanceOfAsyncEffectFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidAsyncEffectFunction<SV, SF, C> =>\n object === Object(object) && \"asyncFunction\" in object;\n\n/**\n * Definition for a state update function used in reducers\n */\nexport interface FluidStateUpdateFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The function defined here will take the combined state and update either\n * the Fluid state, the view state, or both. The new combined state and any new Fluid object\n * handles to load in are returned by the function.\n */\n function: (\n oldState?: ICombinedState<SV, SF, C>,\n ...args: any\n ) => IStateUpdateResult<SV, SF, C>;\n}\n\nexport const instanceOfStateUpdateFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidStateUpdateFunction<SV, SF, C> =>\n object === Object(object) && \"function\" in object;\n\n/**\n * Definition for an async state update function used in reducers\n */\nexport interface FluidAsyncStateUpdateFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The function defined here will take the combined state and update either\n * the Fluid state, the view state, or both in an async manner. The new combined state and any new\n * Fluid object handles to load in will be returned by the function when it finishes.\n */\n asyncFunction: (\n oldState?: ICombinedState<SV, SF, C>,\n ...args: any\n ) => Promise<IStateUpdateResult<SV, SF, C>>;\n}\n\n/**\n * The value returned by state update functions.\n */\nexport interface IStateUpdateResult<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The new view and Fluid states that were updated by the function\n */\n state: ICombinedState<SV, SF, C>;\n /**\n * Any new Fluid objects that were added in due this function need to have\n * their corresponding handles passed in so that the object can also be loaded for all other users\n */\n newFluidHandles?: IFluidHandle[];\n}\n\nexport const instanceOfAsyncStateUpdateFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidAsyncStateUpdateFunction<SF, SV, C> =>\n object === Object(object) && \"asyncFunction\" in object;\n\n/**\n * Definition for a selector function used in selectors\n */\nexport interface FluidSelectorFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * The function defined here will take the combined state and return\n * to the view any values that it needs from other values/Fluid objects that were passed\n * in to the data props on initializing.\n * It will also return any new Fluid handles that will be needed for other users to render the view value\n */\n function: (\n state?: ICombinedState<SV, SF, C>\n ) => {\n result: any | undefined;\n newFluidHandles?: IFluidHandle[];\n };\n}\n\n/**\n * Definition for a Fluid object selector function used in selectors\n */\nexport interface FluidObjectSelectorFunction<\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n > {\n /**\n * Similar to the FluidSelectorFunction's function but this also takes in a\n * handle if we need to fetch a Fluid object from the fluidObjectMap\n */\n function: (\n handle: IFluidHandle<any>,\n state?: ICombinedState<SV, SF, C>,\n ) => {\n result: IFluidObject | undefined;\n newFluidHandles?: IFluidHandle[];\n };\n}\n\nexport const instanceOfSelectorFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidSelectorFunction<SV, SF, C> =>\n object === Object(object) && \"function\" in object;\n\nexport const instanceOfFluidObjectSelectorFunction = <\n SV extends IViewState,\n SF extends IFluidState,\n C extends IFluidDataProps\n>(\n object: any,\n): object is FluidObjectSelectorFunction<SV, SF, C> =>\n object === Object(object) && \"function\" in object;\n\n/**\n * Props passed in to the useReducerFluid hook\n */\nexport interface IFluidReducerProps<\n SV extends IViewState,\n SF extends IFluidState,\n A extends IFluidReducer<SV, SF, C>,\n B,\n C extends IFluidDataProps\n > {\n /**\n * Unique ID to use for storing the view's synced state in the SyncedDataObject's syncedState SharedMap\n */\n syncedStateId: string;\n /**\n * An instance of the SyncedDataObject that this will be rendered in\n */\n syncedDataObject: SyncedDataObject;\n /**\n * The Fluid reducer containing all the functions as defined by an extension of the IFluidReducer type.\n * Any mutations to the state, or effects outside of the Fluid object involving the state should be done here.\n */\n reducer: A;\n /**\n * The Fluid selector containing all the functions as defined by an extension of the IFluidSelector\n * type. Any fetching of new Fluid objects or data from other Fluid objects should be done here.\n */\n selector: B;\n /**\n * Data props that are loaded in during the Fluid initialization step. This contains the runtime\n * and the Fluid object map\n * TODO: Move data props out as it can be fetched from synced Fluid data object but\n * still needs to be extensible for reducers\n */\n dataProps?: C;\n}\n\n/**\n * Props containing the context that will be passed down through the Fluid context provider to the consumer\n */\nexport interface IFluidContextProps<SV, SF, C> extends IFluidProps<SV, SF> {\n /**\n * The additional data that will be passed through the Fluid context\n */\n reactContext?: C;\n}\n\n/**\n * The state that is available through the react context\n */\nexport interface FluidContextState<\n SV extends IViewState,\n C\n > {\n /**\n * The view state\n */\n state: SV;\n /**\n * Callback to update the state\n */\n setState: (state: SV) => void;\n /**\n * The context passed in from the props\n */\n reactContext: Partial<C>;\n}\n\n/**\n * The returned value of createFluidContext\n */\nexport interface FluidContext<\n SV extends IViewState,\n C\n > {\n /**\n * The context provider React component that will give the FluidContextState to\n * its children\n */\n Provider: React.ProviderExoticComponent<\n React.ProviderProps<FluidContextState<SV, C>>\n >;\n /**\n * The context consumer that allows children to use the FluidContextState\n */\n Consumer: React.Consumer<FluidContextState<SV, C>>;\n /**\n * Callback to get the context\n */\n usePrimedContext: () => FluidContextState<SV, C>;\n /**\n * The view state\n */\n state: SV;\n /**\n * Callback to update the state\n */\n setState: (newState: SV) => void;\n}\n\nexport interface ISyncedStateConfig<SV, SF> {\n /**\n * Unique ID to use for storing the view's synced state in the SyncedDataObject's syncedState SharedMap\n */\n syncedStateId: string;\n /**\n * The backup default view that any view with this ID will use prior to Fluid state initializing, this can be\n * overridden by the view developer themselves\n */\n defaultViewState: SV;\n /**\n * A map of the Fluid state values that need conversion to their view state counterparts and the\n * respective converters\n */\n fluidToView: FluidToViewMap<SV, SF>;\n /**\n * A map of the view state values that need conversion to their Fluid state counterparts and the\n * respective converters\n */\n viewToFluid?: ViewToFluidMap<SV, SF>;\n}\n\n/**\n * The configurations that define the relationships between Fluid and view states for\n * views that are rendered in a SyncedDataObject\n */\nexport type SyncedStateConfig = Map<string, ISyncedStateConfig<any, any>>;\n\n/**\n * The interface for interacting with the synced state that is stored on a SyncedDataObject\n */\nexport interface ISyncedState {\n /**\n * Set values on the synced state for a syncedStateId as key\n */\n set: (key: string, value: any) => void;\n /**\n * Get values from the synced state for a syncedStateId as key\n */\n get: <T>(key: string) => T | undefined;\n /**\n * Add a listener to the synced state using a provided callback\n */\n addValueChangedListener: (\n callback: (changed: IValueChanged, local: boolean) => void) => void;\n}\n"]}
package/lib/reactView.js DELETED
@@ -1,56 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import * as React from "react";
6
- import { syncState, initializeState } from "./helpers";
7
- /**
8
- * A React view with a synced state, initial props, and a Fluid-to-view state two-way mapping
9
- */
10
- export class FluidReactView extends React.Component {
11
- constructor(props) {
12
- super(props);
13
- const { syncedStateId, syncedDataObject, } = props;
14
- const config = syncedDataObject.getConfig(syncedStateId);
15
- if (config === undefined) {
16
- throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
17
- }
18
- this._viewToFluid = config.viewToFluid;
19
- this._fluidToView = config.fluidToView;
20
- this._syncedStateId = syncedStateId;
21
- this._syncedState = syncedDataObject.syncedState;
22
- this._dataProps = syncedDataObject.dataProps;
23
- this.state = config.defaultViewState;
24
- }
25
- async componentDidMount() {
26
- await initializeState(this._syncedStateId, this._syncedState, this._dataProps, this.state, this._setState.bind(this), this._fluidToView, this._viewToFluid);
27
- }
28
- /**
29
- * Function to update the state from both synced state updates or local ones. Only updates the synced state
30
- * on local updates
31
- * @param newState - the new state to be set
32
- * @param fromRootUpdate - is this update coming locally or from a synced state value change
33
- * @param isLocal - should this update be applied only locally
34
- */
35
- _setState(newState, fromRootUpdate, isLocal) {
36
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
37
- if (isLocal) {
38
- super.setState(newState);
39
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
40
- }
41
- else if (fromRootUpdate) {
42
- syncState(true, this._syncedStateId, this._syncedState, this._dataProps.runtime, newState, this._setState.bind(this), this._dataProps.fluidObjectMap, this._fluidToView, this._viewToFluid);
43
- }
44
- else {
45
- this.setState(newState);
46
- }
47
- }
48
- /**
49
- * Function to update the current state. It overloads the React setState function
50
- * @param newState - New state to be set both locally and on the synced state
51
- */
52
- setState(newState) {
53
- syncState(false, this._syncedStateId, this._syncedState, this._dataProps.runtime, newState, this._setState.bind(this), this._dataProps.fluidObjectMap, this._fluidToView, this._viewToFluid);
54
- }
55
- }
56
- //# sourceMappingURL=reactView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactView.js","sourceRoot":"","sources":["../src/reactView.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAgB,cACM,SAAQ,KAAK,CAAC,SAAkC;IAMxE,YAAY,KAA0B;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,MAAM,EACF,aAAa,EACb,gBAAgB,GACnB,GAAG,KAAK,CAAC;QACV,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,MAAM,KAAK,SAAS,EAAE;YACtB,MAAM,KAAK,CAAC,qDAAqD,aAAa,EAAE,CAAC,CAAC;SACrF;QACD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAkB,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAkB,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC,WAAW,CAAC;QACjD,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,SAAS,CAAC;QAC7C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,iBAAiB;QAC1B,MAAM,eAAe,CACjB,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACzB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,CACpB,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACK,SAAS,CACb,QAAY,EACZ,cAAwB,EACxB,OAAiB;QAEjB,yEAAyE;QACzE,IAAI,OAAO,EAAE;YACT,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC7B,yEAAyE;SACxE;aAAM,IAAI,cAAc,EAAE;YACvB,SAAS,CACL,IAAI,EACJ,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EACvB,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACzB,IAAI,CAAC,UAAU,CAAC,cAAc,EAC9B,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,CACpB,CAAC;SACL;aAAM;YACH,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC3B;IACL,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,QAAY;QACxB,SAAS,CACL,KAAK,EACL,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EACvB,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACzB,IAAI,CAAC,UAAU,CAAC,cAAc,EAC9B,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,CACpB,CAAC;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport {\n IFluidProps,\n IFluidState,\n IViewState,\n IFluidConverter,\n IViewConverter,\n IFluidDataProps,\n ISyncedState,\n} from \"./interface\";\nimport { syncState, initializeState } from \"./helpers\";\n\n/**\n * A React view with a synced state, initial props, and a Fluid-to-view state two-way mapping\n */\nexport abstract class FluidReactView<SV extends IViewState,\n SF extends IFluidState> extends React.Component<IFluidProps<SV, SF>, SV> {\n private readonly _syncedStateId: string;\n private readonly _syncedState: ISyncedState;\n private readonly _dataProps: IFluidDataProps;\n private readonly _viewToFluid: Map<keyof SV, IFluidConverter<SV, SF>>;\n private readonly _fluidToView: Map<keyof SF, IViewConverter<SV, SF>>;\n constructor(props: IFluidProps<SV, SF>) {\n super(props);\n const {\n syncedStateId,\n syncedDataObject,\n } = props;\n const config = syncedDataObject.getConfig(syncedStateId);\n if (config === undefined) {\n throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);\n }\n this._viewToFluid = config.viewToFluid as any;\n this._fluidToView = config.fluidToView as any;\n this._syncedStateId = syncedStateId;\n this._syncedState = syncedDataObject.syncedState;\n this._dataProps = syncedDataObject.dataProps;\n this.state = config.defaultViewState;\n }\n\n public async componentDidMount() {\n await initializeState(\n this._syncedStateId,\n this._syncedState,\n this._dataProps,\n this.state,\n this._setState.bind(this),\n this._fluidToView,\n this._viewToFluid,\n );\n }\n\n /**\n * Function to update the state from both synced state updates or local ones. Only updates the synced state\n * on local updates\n * @param newState - the new state to be set\n * @param fromRootUpdate - is this update coming locally or from a synced state value change\n * @param isLocal - should this update be applied only locally\n */\n private _setState(\n newState: SV,\n fromRootUpdate?: boolean,\n isLocal?: boolean,\n ) {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (isLocal) {\n super.setState(newState);\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n } else if (fromRootUpdate) {\n syncState(\n true,\n this._syncedStateId,\n this._syncedState,\n this._dataProps.runtime,\n newState,\n this._setState.bind(this),\n this._dataProps.fluidObjectMap,\n this._fluidToView,\n this._viewToFluid,\n );\n } else {\n this.setState(newState);\n }\n }\n\n /**\n * Function to update the current state. It overloads the React setState function\n * @param newState - New state to be set both locally and on the synced state\n */\n public setState(newState: SV) {\n syncState(\n false,\n this._syncedStateId,\n this._syncedState,\n this._dataProps.runtime,\n newState,\n this._setState.bind(this),\n this._dataProps.fluidObjectMap,\n this._fluidToView,\n this._viewToFluid,\n );\n }\n}\n"]}
@@ -1,245 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { DataObject } from "@fluidframework/aqueduct";
6
- import { SharedMap } from "@fluidframework/map";
7
- import { generateFluidObjectSchema, setSchema, getSchema, } from "./helpers";
8
- /**
9
- * SyncedDataObject is a base class for Fluid data objects with views. It extends DataObject.
10
- * In addition to the root and task manager, the SyncedDataObject also provides a syncedStateConfig
11
- * and assures that the syncedState will be initialized according the config by the time the view
12
- * is rendered.
13
- *
14
- * As this is used for views, it also implements the IFluidHTMLView interface, and requires
15
- * the render function to be filled in.
16
- */
17
- export class SyncedDataObject extends DataObject {
18
- constructor() {
19
- super(...arguments);
20
- this.syncedStateConfig = new Map();
21
- this.fluidObjectMap = new Map();
22
- this.syncedStateDirectoryId = "syncedState";
23
- }
24
- get IFluidHTMLView() {
25
- return this;
26
- }
27
- /**
28
- * Runs the first time the SyncedDataObject is generated and sets up all necessary data structures for the view
29
- * To extend this function, please call super() prior to adding to functionality to ensure correct initializing
30
- */
31
- async initializingFirstTime() {
32
- // Initialize our synced state map for the first time using our
33
- // syncedStateConfig values
34
- await this.initializeStateFirstTime();
35
- }
36
- /**
37
- * Runs any time the SyncedDataObject is rendered again. It sets up all necessary data structures for the view,
38
- * along with any additional ones that may have been added due to user behavior
39
- * To extend this function, please call super() prior to adding to functionality to ensure correct initializing
40
- */
41
- async initializingFromExisting() {
42
- // Load our existing state values to be ready for the render lifecycle
43
- await this.initializeStateFromExisting();
44
- }
45
- /**
46
- * Returns an interface to interact with the stored synced state for the SyncedDataObject.
47
- * Views can get and fetch values from it based on their syncedStateId to retrieve their view-specific information.
48
- * They can also attach listeners using the addValueChangedListener
49
- */
50
- get syncedState() {
51
- if (this.internalSyncedState === undefined) {
52
- throw new Error(this.getUninitializedErrorString(`syncedState`));
53
- }
54
- return {
55
- set: this.internalSyncedState.set.bind(this.internalSyncedState),
56
- get: this.internalSyncedState.get.bind(this.internalSyncedState),
57
- addValueChangedListener: (callback) => {
58
- if (this.internalSyncedState === undefined) {
59
- throw new Error(this.getUninitializedErrorString(`syncedState`));
60
- }
61
- this.internalSyncedState.on("valueChanged", callback);
62
- },
63
- };
64
- }
65
- /**
66
- * Returns the data props used by the view to manage the different DDSes and add any new ones
67
- */
68
- get dataProps() {
69
- return {
70
- // The return type is defined explicitly here to prevent TypeScript from generating dynamic imports
71
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
72
- runtime: this.runtime,
73
- fluidObjectMap: this.fluidObjectMap,
74
- };
75
- }
76
- /**
77
- * Set values to the syncedStateConfig where the view and Fluid states have the same values defined by S.
78
- * Each view with a unique syncedStateId needs its own value in the syncedStateConfig.
79
- * @param key - The syncedStateId that maps to the view that will be using these definitions
80
- * @param value - The config value containing the syncedStateId and the fluidToView and viewToFluid maps
81
- */
82
- // eslint-disable-next-line @typescript-eslint/no-shadow
83
- setConfig(key, value) {
84
- this.syncedStateConfig.set(key, value);
85
- }
86
- /**
87
- * Set values to the syncedStateConfig with different view and Fluid state definitions.
88
- * Each view with a unique syncedStateId needs its own value in the syncedStateConfig,
89
- * with SV being the view state definition and SF being the Fluid state definition.
90
- * @param key - The syncedStateId that maps to the view that will be using these definitions
91
- * @param value - The config value containing the syncedStateId and the fluidToView and viewToFluid maps
92
- * that establish the relationship between SV and SF
93
- */
94
- setFluidConfig(key, value) {
95
- this.syncedStateConfig.set(key, value);
96
- }
97
- /**
98
- * Get a config for a specific view with the key as its syncedStateId
99
- * @param key - The syncedStateId to get the config for
100
- */
101
- getConfig(key) {
102
- return this.syncedStateConfig.get(key);
103
- }
104
- /**
105
- * Returns a view. This function need to be implemented for any consumer of SyncedDataObject
106
- * to render values that have been initialized using the syncedStateConfig
107
- * @param element - The document that the rendered value will be displayed in
108
- */
109
- render(element) {
110
- throw Error("Render function was not implemented");
111
- }
112
- async initializeStateFirstTime() {
113
- var _a;
114
- this.internalSyncedState = SharedMap.create(this.runtime, this.syncedStateDirectoryId);
115
- this.internalSyncedState.bindToContext();
116
- for (const stateConfig of this.syncedStateConfig.values()) {
117
- const { syncedStateId, fluidToView, viewToFluid, defaultViewState, } = stateConfig;
118
- // Add the SharedMap to store the Fluid state
119
- const storedFluidState = SharedMap.create(this.runtime);
120
- // Add it to the Fluid object map so that it will have a listener added to it once
121
- // we enter the render lifecycle
122
- this.fluidObjectMap.set(storedFluidState.handle.absolutePath, {
123
- fluidObject: storedFluidState,
124
- isRuntimeMap: true,
125
- });
126
- // Add the state to our map of synced states so that we can load it later for persistence
127
- this.syncedState.set(`syncedState-${syncedStateId}`, storedFluidState.handle);
128
- // Initialize any DDSes needed for the state or fetch any values from the root if they are stored
129
- // on the root under a different key
130
- for (const [key, value] of fluidToView.entries()) {
131
- const fluidKey = key;
132
- const rootKey = value.rootKey;
133
- const createCallback = value.sharedObjectCreate;
134
- if (createCallback !== undefined) {
135
- const sharedObject = createCallback(this.runtime);
136
- this.fluidObjectMap.set(sharedObject.handle.absolutePath, {
137
- fluidObject: sharedObject,
138
- listenedEvents: (_a = value.listenedEvents) !== null && _a !== void 0 ? _a : ["valueChanged"],
139
- });
140
- storedFluidState.set(fluidKey, sharedObject.handle);
141
- if (rootKey !== undefined) {
142
- this.root.set(rootKey, sharedObject.handle);
143
- }
144
- }
145
- else if (rootKey !== undefined) {
146
- storedFluidState.set(fluidKey, this.root.get(rootKey));
147
- }
148
- }
149
- // Generate our schema and store it, so that we don't need to parse our maps each time
150
- const schema = generateFluidObjectSchema(this.runtime, defaultViewState, fluidToView, viewToFluid);
151
- const schemaHandles = {
152
- fluidMatchingMapHandle: schema.fluidMatchingMap
153
- .handle,
154
- viewMatchingMapHandle: schema.viewMatchingMap
155
- .handle,
156
- storedHandleMapHandle: schema.storedHandleMap
157
- .handle,
158
- };
159
- this.fluidObjectMap.set(schema.fluidMatchingMap.handle.absolutePath, {
160
- fluidObject: schema.fluidMatchingMap,
161
- isRuntimeMap: true,
162
- });
163
- this.fluidObjectMap.set(schema.viewMatchingMap.handle.absolutePath, {
164
- fluidObject: schema.viewMatchingMap,
165
- isRuntimeMap: true,
166
- });
167
- this.fluidObjectMap.set(schema.storedHandleMap.handle.absolutePath, {
168
- fluidObject: schema.storedHandleMap,
169
- isRuntimeMap: true,
170
- });
171
- setSchema(syncedStateId, this.syncedState, schemaHandles);
172
- }
173
- }
174
- async initializeStateFromExisting() {
175
- var _a, _b;
176
- // Fetch our synced state that stores all of our information to re-initialize the view state
177
- this.internalSyncedState = (await this.runtime.getChannel(this.syncedStateDirectoryId));
178
- // Reload the stored state for each config provided
179
- for (const stateConfig of this.syncedStateConfig.values()) {
180
- const { syncedStateId, fluidToView } = stateConfig;
181
- // Fetch this specific view's state using the syncedStateId
182
- const storedFluidStateHandle = this.syncedState.get(`syncedState-${syncedStateId}`);
183
- if (storedFluidStateHandle === undefined) {
184
- throw new Error(this.getUninitializedErrorString(`syncedState-${syncedStateId}`));
185
- }
186
- const storedFluidState = await storedFluidStateHandle.get();
187
- // Add it to the Fluid object map so that it will have a listener added to it once
188
- // we enter the render lifecycle
189
- this.fluidObjectMap.set(storedFluidStateHandle.absolutePath, {
190
- fluidObject: storedFluidState,
191
- isRuntimeMap: true,
192
- });
193
- // If the view is using any Fluid data stores or SharedObjects, asynchronously fetch them
194
- // from their stored handles
195
- for (const [key, value] of fluidToView.entries()) {
196
- const fluidKey = key;
197
- const rootKey = value.rootKey;
198
- const createCallback = value.sharedObjectCreate;
199
- if (createCallback !== undefined) {
200
- const handle = rootKey !== undefined
201
- ? this.root.get(rootKey)
202
- : storedFluidState.get(fluidKey);
203
- if (handle === undefined) {
204
- throw new Error(`Failed to find ${fluidKey} in synced state`);
205
- }
206
- this.fluidObjectMap.set(handle.absolutePath, {
207
- fluidObject: await handle.get(),
208
- listenedEvents: (_a = value.listenedEvents) !== null && _a !== void 0 ? _a : ["valueChanged"],
209
- });
210
- }
211
- else {
212
- const storedValue = rootKey !== undefined
213
- ? this.root.get(rootKey)
214
- : storedFluidState.get(fluidKey);
215
- const handle = storedValue === null || storedValue === void 0 ? void 0 : storedValue.IFluidHandle;
216
- if (handle !== undefined) {
217
- this.fluidObjectMap.set(handle.absolutePath, {
218
- fluidObject: await handle.get(),
219
- listenedEvents: (_b = value.listenedEvents) !== null && _b !== void 0 ? _b : [
220
- "valueChanged",
221
- ],
222
- });
223
- }
224
- }
225
- }
226
- const schemaHandles = getSchema(syncedStateId, this.syncedState);
227
- if (schemaHandles === undefined) {
228
- throw new Error(this.getUninitializedErrorString(`schema-${syncedStateId}`));
229
- }
230
- this.fluidObjectMap.set(schemaHandles.fluidMatchingMapHandle.absolutePath, {
231
- fluidObject: await schemaHandles.fluidMatchingMapHandle.get(),
232
- isRuntimeMap: true,
233
- });
234
- this.fluidObjectMap.set(schemaHandles.viewMatchingMapHandle.absolutePath, {
235
- fluidObject: await schemaHandles.viewMatchingMapHandle.get(),
236
- isRuntimeMap: true,
237
- });
238
- this.fluidObjectMap.set(schemaHandles.storedHandleMapHandle.absolutePath, {
239
- fluidObject: await schemaHandles.storedHandleMapHandle.get(),
240
- isRuntimeMap: true,
241
- });
242
- }
243
- }
244
- }
245
- //# sourceMappingURL=syncedDataObject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncedDataObject.js","sourceRoot":"","sources":["../src/syncedDataObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAMtD,OAAO,EAAE,SAAS,EAAc,MAAM,qBAAqB,CAAC;AAY5D,OAAO,EACH,yBAAyB,EACzB,SAAS,EACT,SAAS,GACZ,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,MAAM,OAAgB,gBAKhB,SAAQ,UAAmB;IALjC;;QAMqB,sBAAiB,GAAsB,IAAI,GAAG,EAAE,CAAC;QACjD,mBAAc,GAAmB,IA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EAAE;wBACtB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE;4BACzC,WAAW,EAAE,MAAM,MAAM,CAAC,GAAG,EAAE;4BAC/B,cAAc,QAAE,KAAK,CAAC,cAAc,mCAAI;gCACpC,cAAc;6BACjB;yBACJ,CAAC,CAAC;qBACN;iBACJ;aACJ;YACD,MAAM,aAAa,GAAG,SAAS,CAC3B,aAAa,EACb,IAAI,CAAC,WAAW,CACnB,CAAC;YACF,IAAI,aAAa,KAAK,SAAS,EAAE;gBAC7B,MAAM,IAAI,KAAK,CACX,IAAI,CAAC,2BAA2B,CAC5B,UAAU,aAAa,EAAE,CAC5B,CACJ,CAAC;aACL;YACD,IAAI,CAAC,cAAc,CAAC,GAAG,CACnB,aAAa,CAAC,sBAAsB,CAAC,YAAY,EACjD;gBACI,WAAW,EAAE,MAAM,aAAa,CAAC,sBAAsB,CAAC,GAAG,EAAE;gBAC7D,YAAY,EAAE,IAAI;aACrB,CACJ,CAAC;YACF,IAAI,CAAC,cAAc,CAAC,GAAG,CACnB,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAChD;gBACI,WAAW,EAAE,MAAM,aAAa,CAAC,qBAAqB,CAAC,GAAG,EAAE;gBAC5D,YAAY,EAAE,IAAI;aACrB,CACJ,CAAC;YACF,IAAI,CAAC,cAAc,CAAC,GAAG,CACnB,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAChD;gBACI,WAAW,EAAE,MAAM,aAAa,CAAC,qBAAqB,CAAC,GAAG,EAAE;gBAC5D,YAAY,EAAE,IAAI;aACrB,CACJ,CAAC;SACL;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { DataObject } from \"@fluidframework/aqueduct\";\nimport {\n IFluidObject,\n IFluidHandle,\n} from \"@fluidframework/core-interfaces\";\nimport { IEvent } from \"@fluidframework/common-definitions\";\nimport { SharedMap, ISharedMap } from \"@fluidframework/map\";\nimport { IFluidHTMLView } from \"@fluidframework/view-interfaces\";\nimport type { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\n\nimport {\n FluidObjectMap,\n SyncedStateConfig,\n ISyncedStateConfig,\n IViewState,\n IFluidState,\n ISyncedState,\n} from \"./interface\";\nimport {\n generateFluidObjectSchema,\n setSchema,\n getSchema,\n} from \"./helpers\";\n\n/**\n * SyncedDataObject is a base class for Fluid data objects with views. It extends DataObject.\n * In addition to the root and task manager, the SyncedDataObject also provides a syncedStateConfig\n * and assures that the syncedState will be initialized according the config by the time the view\n * is rendered.\n *\n * As this is used for views, it also implements the IFluidHTMLView interface, and requires\n * the render function to be filled in.\n */\nexport abstract class SyncedDataObject<\n // eslint-disable-next-line @typescript-eslint/ban-types\n P extends IFluidObject = object,\n S = undefined,\n E extends IEvent = IEvent\n > extends DataObject<P, S, E> implements IFluidHTMLView {\n private readonly syncedStateConfig: SyncedStateConfig = new Map();\n private readonly fluidObjectMap: FluidObjectMap = new Map();\n private readonly syncedStateDirectoryId = \"syncedState\";\n private internalSyncedState: ISharedMap | undefined;\n\n public get IFluidHTMLView() {\n return this;\n }\n\n /**\n * Runs the first time the SyncedDataObject is generated and sets up all necessary data structures for the view\n * To extend this function, please call super() prior to adding to functionality to ensure correct initializing\n */\n protected async initializingFirstTime(): Promise<void> {\n // Initialize our synced state map for the first time using our\n // syncedStateConfig values\n await this.initializeStateFirstTime();\n }\n\n /**\n * Runs any time the SyncedDataObject is rendered again. It sets up all necessary data structures for the view,\n * along with any additional ones that may have been added due to user behavior\n * To extend this function, please call super() prior to adding to functionality to ensure correct initializing\n */\n protected async initializingFromExisting(): Promise<void> {\n // Load our existing state values to be ready for the render lifecycle\n await this.initializeStateFromExisting();\n }\n\n /**\n * Returns an interface to interact with the stored synced state for the SyncedDataObject.\n * Views can get and fetch values from it based on their syncedStateId to retrieve their view-specific information.\n * They can also attach listeners using the addValueChangedListener\n */\n public get syncedState(): ISyncedState {\n if (this.internalSyncedState === undefined) {\n throw new Error(this.getUninitializedErrorString(`syncedState`));\n }\n return {\n set: this.internalSyncedState.set.bind(this.internalSyncedState),\n get: this.internalSyncedState.get.bind(this.internalSyncedState),\n addValueChangedListener: (callback) => {\n if (this.internalSyncedState === undefined) {\n throw new Error(\n this.getUninitializedErrorString(`syncedState`),\n );\n }\n this.internalSyncedState.on(\"valueChanged\", callback);\n },\n };\n }\n\n /**\n * Returns the data props used by the view to manage the different DDSes and add any new ones\n */\n public get dataProps() {\n return {\n // The return type is defined explicitly here to prevent TypeScript from generating dynamic imports\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n runtime: this.runtime as IFluidDataStoreRuntime,\n fluidObjectMap: this.fluidObjectMap,\n };\n }\n\n /**\n * Set values to the syncedStateConfig where the view and Fluid states have the same values defined by S.\n * Each view with a unique syncedStateId needs its own value in the syncedStateConfig.\n * @param key - The syncedStateId that maps to the view that will be using these definitions\n * @param value - The config value containing the syncedStateId and the fluidToView and viewToFluid maps\n */\n // eslint-disable-next-line @typescript-eslint/no-shadow\n public setConfig<S>(key: string, value: ISyncedStateConfig<S, S>) {\n this.syncedStateConfig.set(key, value);\n }\n\n /**\n * Set values to the syncedStateConfig with different view and Fluid state definitions.\n * Each view with a unique syncedStateId needs its own value in the syncedStateConfig,\n * with SV being the view state definition and SF being the Fluid state definition.\n * @param key - The syncedStateId that maps to the view that will be using these definitions\n * @param value - The config value containing the syncedStateId and the fluidToView and viewToFluid maps\n * that establish the relationship between SV and SF\n */\n public setFluidConfig<\n SV extends IViewState,\n SF extends IFluidState\n >(key: string, value: ISyncedStateConfig<SV, SF>) {\n this.syncedStateConfig.set(key, value);\n }\n\n /**\n * Get a config for a specific view with the key as its syncedStateId\n * @param key - The syncedStateId to get the config for\n */\n public getConfig(key: string) {\n return this.syncedStateConfig.get(key);\n }\n\n /**\n * Returns a view. This function need to be implemented for any consumer of SyncedDataObject\n * to render values that have been initialized using the syncedStateConfig\n * @param element - The document that the rendered value will be displayed in\n */\n public render(element: HTMLElement) {\n throw Error(\"Render function was not implemented\");\n }\n\n private async initializeStateFirstTime() {\n this.internalSyncedState = SharedMap.create(\n this.runtime,\n this.syncedStateDirectoryId,\n );\n this.internalSyncedState.bindToContext();\n for (const stateConfig of this.syncedStateConfig.values()) {\n const {\n syncedStateId,\n fluidToView,\n viewToFluid,\n defaultViewState,\n } = stateConfig;\n // Add the SharedMap to store the Fluid state\n const storedFluidState = SharedMap.create(this.runtime);\n // Add it to the Fluid object map so that it will have a listener added to it once\n // we enter the render lifecycle\n this.fluidObjectMap.set(storedFluidState.handle.absolutePath, {\n fluidObject: storedFluidState,\n isRuntimeMap: true,\n });\n // Add the state to our map of synced states so that we can load it later for persistence\n this.syncedState.set(\n `syncedState-${syncedStateId}`,\n storedFluidState.handle,\n );\n // Initialize any DDSes needed for the state or fetch any values from the root if they are stored\n // on the root under a different key\n for (const [key, value] of fluidToView.entries()) {\n const fluidKey = key as string;\n const rootKey = value.rootKey;\n const createCallback = value.sharedObjectCreate;\n if (createCallback !== undefined) {\n const sharedObject = createCallback(this.runtime);\n this.fluidObjectMap.set(sharedObject.handle.absolutePath, {\n fluidObject: sharedObject,\n listenedEvents: value.listenedEvents ?? [\"valueChanged\"],\n });\n storedFluidState.set(fluidKey, sharedObject.handle);\n if (rootKey !== undefined) {\n this.root.set(rootKey, sharedObject.handle);\n }\n } else if (rootKey !== undefined) {\n storedFluidState.set(fluidKey, this.root.get(rootKey));\n }\n }\n\n // Generate our schema and store it, so that we don't need to parse our maps each time\n const schema = generateFluidObjectSchema(\n this.runtime,\n defaultViewState,\n fluidToView,\n viewToFluid,\n );\n const schemaHandles = {\n fluidMatchingMapHandle: schema.fluidMatchingMap\n .handle as IFluidHandle<SharedMap>,\n viewMatchingMapHandle: schema.viewMatchingMap\n .handle as IFluidHandle<SharedMap>,\n storedHandleMapHandle: schema.storedHandleMap\n .handle as IFluidHandle<SharedMap>,\n };\n this.fluidObjectMap.set(\n schema.fluidMatchingMap.handle.absolutePath,\n {\n fluidObject: schema.fluidMatchingMap,\n isRuntimeMap: true,\n },\n );\n this.fluidObjectMap.set(\n schema.viewMatchingMap.handle.absolutePath,\n {\n fluidObject: schema.viewMatchingMap,\n isRuntimeMap: true,\n },\n );\n this.fluidObjectMap.set(\n schema.storedHandleMap.handle.absolutePath,\n {\n fluidObject: schema.storedHandleMap,\n isRuntimeMap: true,\n },\n );\n\n setSchema(\n syncedStateId,\n this.syncedState,\n schemaHandles,\n );\n }\n }\n\n private async initializeStateFromExisting() {\n // Fetch our synced state that stores all of our information to re-initialize the view state\n this.internalSyncedState = (await this.runtime.getChannel(\n this.syncedStateDirectoryId,\n )) as ISharedMap;\n // Reload the stored state for each config provided\n for (const stateConfig of this.syncedStateConfig.values()) {\n const { syncedStateId, fluidToView } = stateConfig;\n // Fetch this specific view's state using the syncedStateId\n const storedFluidStateHandle = this.syncedState.get<\n IFluidHandle<ISharedMap>\n >(`syncedState-${syncedStateId}`);\n if (storedFluidStateHandle === undefined) {\n throw new Error(\n this.getUninitializedErrorString(\n `syncedState-${syncedStateId}`,\n ),\n );\n }\n const storedFluidState = await storedFluidStateHandle.get();\n // Add it to the Fluid object map so that it will have a listener added to it once\n // we enter the render lifecycle\n this.fluidObjectMap.set(storedFluidStateHandle.absolutePath, {\n fluidObject: storedFluidState,\n isRuntimeMap: true,\n });\n // If the view is using any Fluid data stores or SharedObjects, asynchronously fetch them\n // from their stored handles\n for (const [key, value] of fluidToView.entries()) {\n const fluidKey = key as string;\n const rootKey = value.rootKey;\n const createCallback = value.sharedObjectCreate;\n if (createCallback !== undefined) {\n const handle = rootKey !== undefined\n ? this.root.get(rootKey)\n : storedFluidState.get(fluidKey);\n if (handle === undefined) {\n throw new Error(\n `Failed to find ${fluidKey} in synced state`,\n );\n }\n this.fluidObjectMap.set(handle.absolutePath, {\n fluidObject: await handle.get(),\n listenedEvents: value.listenedEvents ?? [\"valueChanged\"],\n });\n } else {\n const storedValue = rootKey !== undefined\n ? this.root.get(rootKey)\n : storedFluidState.get(fluidKey);\n const handle = storedValue?.IFluidHandle;\n if (handle !== undefined) {\n this.fluidObjectMap.set(handle.absolutePath, {\n fluidObject: await handle.get(),\n listenedEvents: value.listenedEvents ?? [\n \"valueChanged\",\n ],\n });\n }\n }\n }\n const schemaHandles = getSchema(\n syncedStateId,\n this.syncedState,\n );\n if (schemaHandles === undefined) {\n throw new Error(\n this.getUninitializedErrorString(\n `schema-${syncedStateId}`,\n ),\n );\n }\n this.fluidObjectMap.set(\n schemaHandles.fluidMatchingMapHandle.absolutePath,\n {\n fluidObject: await schemaHandles.fluidMatchingMapHandle.get(),\n isRuntimeMap: true,\n },\n );\n this.fluidObjectMap.set(\n schemaHandles.viewMatchingMapHandle.absolutePath,\n {\n fluidObject: await schemaHandles.viewMatchingMapHandle.get(),\n isRuntimeMap: true,\n },\n );\n this.fluidObjectMap.set(\n schemaHandles.storedHandleMapHandle.absolutePath,\n {\n fluidObject: await schemaHandles.storedHandleMapHandle.get(),\n isRuntimeMap: true,\n },\n );\n }\n }\n}\n"]}
@@ -1,72 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { SharedObjectSequence } from "@fluidframework/sequence";
6
- import { useReducerFluid, } from "../..";
7
- export function setFluidSyncedArrayConfig(syncedDataObject, syncedStateId, viewKey, fluidKey, defaultViewState, sharedObjectCreate = SharedObjectSequence.create) {
8
- syncedDataObject.setFluidConfig(syncedStateId, {
9
- syncedStateId,
10
- fluidToView: new Map([
11
- [
12
- fluidKey,
13
- {
14
- type: SharedObjectSequence.name,
15
- viewKey,
16
- viewConverter: (viewState, fluidState) => {
17
- if (fluidState[fluidKey] === undefined) {
18
- throw Error("Fluid state was not initialized");
19
- }
20
- viewState[viewKey] = fluidState[fluidKey].getItems(0);
21
- return viewState;
22
- },
23
- sharedObjectCreate,
24
- listenedEvents: ["valueChanged"],
25
- },
26
- ],
27
- ]),
28
- viewToFluid: new Map([
29
- [
30
- viewKey,
31
- {
32
- type: "array",
33
- fluidKey,
34
- fluidConverter: (viewState, fluidState) => {
35
- if (fluidState[fluidKey] === undefined) {
36
- throw Error("Fluid state was not initialized");
37
- }
38
- viewState[viewKey] = fluidState[fluidKey].getItems(0);
39
- return fluidState;
40
- },
41
- },
42
- ],
43
- ]),
44
- defaultViewState,
45
- });
46
- }
47
- export function generateSyncedArrayReducer(viewKey, fluidKey) {
48
- const syncedArrayReducer = {
49
- add: {
50
- function: (state, value) => {
51
- var _a;
52
- if (((_a = state === null || state === void 0 ? void 0 : state.fluidState) === null || _a === void 0 ? void 0 : _a[fluidKey]) === undefined) {
53
- throw Error("State was not initialized prior to dispatch call");
54
- }
55
- state.fluidState[fluidKey].insert(state.fluidState[fluidKey].getLength(), [Object.assign({}, value)]);
56
- state.viewState[viewKey] = state.fluidState[fluidKey].getItems(0);
57
- return { state };
58
- },
59
- },
60
- };
61
- return syncedArrayReducer;
62
- }
63
- export function useSyncedArrayReducerFluid(syncedDataObject, syncedStateId, viewKey, fluidKey, defaultViewState) {
64
- const syncedArrayReducer = generateSyncedArrayReducer(viewKey, fluidKey);
65
- return useReducerFluid({
66
- syncedDataObject,
67
- syncedStateId,
68
- reducer: syncedArrayReducer,
69
- selector: {},
70
- }, defaultViewState);
71
- }
72
- //# sourceMappingURL=fluidSyncedArray.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fluidSyncedArray.js","sourceRoot":"","sources":["../../../src/syncedObjects/array/fluidSyncedArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAMH,eAAe,GAClB,MAAM,OAAO,CAAC;AAGf,MAAM,UAAU,yBAAyB,CAIrC,gBAAkC,EAClC,aAAqB,EACrB,OAAiB,EACjB,QAAkB,EAClB,gBAAoB,EACpB,kBAAkB,GAAG,oBAAoB,CAAC,MAAM;IAEhD,gBAAgB,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M,SAAS,EAAE;oBAC7C,MAAM,KAAK,CACP,kDAAkD,CACrD,CAAC;iBACL;gBACD,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAC7B,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,EACtC,mBAAM,KAAK,EAAG,CACjB,CAAC;gBACF,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAC1D,CAAC,CACJ,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,CAAC;YACrB,CAAC;SACJ;KACJ,CAAC;IACF,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,0BAA0B,CAItC,gBAAkC,EAClC,aAAqB,EACrB,OAAiB,EACjB,QAAkB,EAClB,gBAAoB;IAGpB,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzE,OAAO,eAAe,CAQlB;QACI,gBAAgB;QAChB,aAAa;QACb,OAAO,EAAE,kBAAkB;QAC3B,QAAQ,EAAE,EAAE;KACf,EACD,gBAAgB,CACnB,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { SharedObjectSequence } from \"@fluidframework/sequence\";\nimport {\n IViewState,\n IFluidState,\n SyncedDataObject,\n ICombinedState,\n IFluidDataProps,\n useReducerFluid,\n} from \"../..\";\nimport { IFluidSyncedArrayReducer } from \"./interface\";\n\nexport function setFluidSyncedArrayConfig<\n SV extends IViewState,\n SF extends IFluidState\n>(\n syncedDataObject: SyncedDataObject,\n syncedStateId: string,\n viewKey: keyof SV,\n fluidKey: keyof SF,\n defaultViewState: SV,\n sharedObjectCreate = SharedObjectSequence.create,\n) {\n syncedDataObject.setFluidConfig<SV, SF>(syncedStateId, {\n syncedStateId,\n fluidToView: new Map([\n [\n fluidKey,\n {\n type: SharedObjectSequence.name,\n viewKey,\n viewConverter: (viewState, fluidState) => {\n if (fluidState[fluidKey] === undefined) {\n throw Error(\"Fluid state was not initialized\");\n }\n viewState[viewKey] = (fluidState[\n fluidKey\n ] as any).getItems(0);\n return viewState;\n },\n sharedObjectCreate,\n listenedEvents: [\"valueChanged\"],\n },\n ],\n ]),\n viewToFluid: new Map([\n [\n viewKey,\n {\n type: \"array\",\n fluidKey,\n fluidConverter: (viewState, fluidState) => {\n if (fluidState[fluidKey] === undefined) {\n throw Error(\"Fluid state was not initialized\");\n }\n viewState[viewKey] = (fluidState[\n fluidKey\n ] as any).getItems(0);\n return fluidState;\n },\n },\n ],\n ]),\n defaultViewState,\n });\n}\n\nexport function generateSyncedArrayReducer<\n SV extends IViewState,\n SF extends IFluidState\n>(viewKey: keyof SV, fluidKey: keyof SF): IFluidSyncedArrayReducer<SV, SF> {\n const syncedArrayReducer = {\n add: {\n function: (state, value: any) => {\n if (state?.fluidState?.[fluidKey] === undefined) {\n throw Error(\n \"State was not initialized prior to dispatch call\",\n );\n }\n state.fluidState[fluidKey].insert(\n state.fluidState[fluidKey].getLength(),\n [{ ...value }],\n );\n state.viewState[viewKey] = state.fluidState[fluidKey].getItems(\n 0,\n );\n return { state };\n },\n },\n };\n return syncedArrayReducer;\n}\n\nexport function useSyncedArrayReducerFluid<\n SV extends IViewState,\n SF extends IFluidState\n>(\n syncedDataObject: SyncedDataObject,\n syncedStateId: string,\n viewKey: keyof SV,\n fluidKey: keyof SF,\n defaultViewState: SV,\n// eslint-disable-next-line @typescript-eslint/ban-types\n): [ICombinedState<SV, SF, IFluidDataProps>, IFluidSyncedArrayReducer<SV, SF>, {}] {\n const syncedArrayReducer = generateSyncedArrayReducer(viewKey, fluidKey);\n return useReducerFluid<\n SV,\n SF,\n IFluidSyncedArrayReducer<SV, SF>,\n // eslint-disable-next-line @typescript-eslint/ban-types\n {},\n IFluidDataProps\n >(\n {\n syncedDataObject,\n syncedStateId,\n reducer: syncedArrayReducer,\n selector: {},\n },\n defaultViewState,\n );\n}\n"]}
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export * from "./syncedArray";
6
- export * from "./interface";
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/syncedObjects/array/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./syncedArray\";\nexport * from \"./interface\";\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/syncedObjects/array/interface.ts"],"names":[],"mappings":"","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { SharedObjectSequence } from \"@fluidframework/sequence\";\nimport {\n IViewState,\n IFluidState,\n IFluidReducer,\n IFluidDataProps,\n FluidStateUpdateFunction,\n} from \"../..\";\n\n/**\n * The state interface exposed to the view for the synced array\n */\nexport interface ISyncedArrayViewState<T> extends IViewState {\n values: T[];\n}\n\n/**\n * The state interface for the Fluid data source that powers the synced array\n */\nexport interface ISyncedArrayFluidState<T> extends IFluidState {\n values: SharedObjectSequence<T>;\n}\n\n/**\n * The reducer interface for modifying the synced array\n * TODO: Add more functions that further expose the SharedObjectSequence interface for use\n */\nexport interface ISyncedArrayReducer<T> {\n add: (value: T) => void;\n}\n\n/**\n * The underlying reducer interface passed to the useReducerFluid hook to bind the view and Fluid\n * state definitions together\n */\nexport interface IFluidSyncedArrayReducer<\n SV extends IViewState,\n SF extends IFluidState\n > extends IFluidReducer<SV, SF, IFluidDataProps> {\n add: FluidStateUpdateFunction<SV, SF, IFluidDataProps>;\n}\n"]}