@abloatai/humans 0.63.0 → 0.64.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 (60) hide show
  1. package/dist/Ablo.d.ts +4 -0
  2. package/dist/client.d.ts +11 -31
  3. package/dist/local/client/reactiveEngine.js +4 -5
  4. package/dist/{react/useSyncStatus.d.ts → local/client/status.d.ts} +4 -3
  5. package/dist/local/client/status.js +14 -0
  6. package/dist/local/client/storeLifecycle.js +2 -2
  7. package/dist/local/storeContract.d.ts +3 -4
  8. package/dist/presence/index.js +6 -2
  9. package/dist/react/AbloProvider.d.ts +59 -139
  10. package/dist/react/AbloProvider.js +60 -181
  11. package/dist/react/createAbloReact.d.ts +10 -32
  12. package/dist/react/createAbloReact.js +10 -54
  13. package/dist/react/internalContext.d.ts +3 -20
  14. package/dist/react/snapshot.d.ts +4 -0
  15. package/dist/react/snapshot.js +75 -0
  16. package/dist/react/useAblo.d.ts +28 -45
  17. package/dist/react/useAblo.js +39 -77
  18. package/dist/react/useMutators.d.ts +20 -17
  19. package/dist/react/usePresence.js +7 -6
  20. package/dist/react/useReactive.d.ts +12 -0
  21. package/dist/react/useReactive.js +57 -0
  22. package/dist/react/useUndoScope.d.ts +15 -29
  23. package/dist/react/useUndoScope.js +17 -0
  24. package/dist/react.d.ts +7 -19
  25. package/dist/react.js +7 -15
  26. package/package.json +4 -3
  27. package/src/Ablo.ts +5 -0
  28. package/src/client.ts +12 -31
  29. package/src/local/client/reactiveEngine.ts +4 -5
  30. package/src/local/client/status.ts +20 -0
  31. package/src/local/client/storeLifecycle.ts +2 -2
  32. package/src/local/storeContract.ts +3 -4
  33. package/src/presence/index.ts +6 -2
  34. package/src/react/AbloProvider.tsx +94 -309
  35. package/src/react/createAbloReact.ts +18 -99
  36. package/src/react/internalContext.ts +3 -20
  37. package/src/react/snapshot.ts +67 -0
  38. package/src/react/useAblo.ts +71 -140
  39. package/src/react/useMutators.ts +30 -26
  40. package/src/react/usePresence.ts +7 -12
  41. package/src/react/useReactive.ts +56 -0
  42. package/src/react/useUndoScope.ts +18 -14
  43. package/src/react.ts +7 -69
  44. package/dist/react/ClientSideSuspense.d.ts +0 -36
  45. package/dist/react/ClientSideSuspense.js +0 -17
  46. package/dist/react/useCurrentUserId.d.ts +0 -2
  47. package/dist/react/useCurrentUserId.js +0 -12
  48. package/dist/react/useErrorListener.d.ts +0 -2
  49. package/dist/react/useErrorListener.js +0 -14
  50. package/dist/react/useMutationFailureListener.d.ts +0 -8
  51. package/dist/react/useMutationFailureListener.js +0 -19
  52. package/dist/react/useSyncStatus.js +0 -37
  53. package/dist/useReactive.d.ts +0 -6
  54. package/dist/useReactive.js +0 -43
  55. package/src/react/ClientSideSuspense.tsx +0 -57
  56. package/src/react/useCurrentUserId.ts +0 -17
  57. package/src/react/useErrorListener.ts +0 -22
  58. package/src/react/useMutationFailureListener.ts +0 -34
  59. package/src/react/useSyncStatus.ts +0 -42
  60. package/src/useReactive.ts +0 -51
@@ -1,51 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useRef } from 'react';
4
- import { useSyncExternalStore } from 'react';
5
- import { reaction } from 'mobx';
6
-
7
- /**
8
- * Subscribe a React component to a MobX computation with a cached snapshot.
9
- * This is the framework-level reactive primitive owned by @abloatai/humans;
10
- * store/model hooks are layered above it.
11
- */
12
- export function useReactive<T>(
13
- compute: () => T,
14
- equals: (a: T, b: T) => boolean = defaultEquals,
15
- ): T {
16
- const computeRef = useRef(compute);
17
- const equalsRef = useRef(equals);
18
- const snapshotRef = useRef<{ value: T } | null>(null);
19
- const versionRef = useRef(0);
20
-
21
- equalsRef.current = equals;
22
- if (snapshotRef.current === null) {
23
- snapshotRef.current = { value: compute() };
24
- } else if (computeRef.current !== compute) {
25
- const next = compute();
26
- if (!equals(snapshotRef.current.value, next)) {
27
- snapshotRef.current = { value: next };
28
- versionRef.current++;
29
- }
30
- }
31
- computeRef.current = compute;
32
-
33
- const subscribe = useCallback((onChange: () => void) => reaction(
34
- () => computeRef.current(),
35
- (next) => {
36
- const current = snapshotRef.current!.value;
37
- if (!equalsRef.current(current, next)) {
38
- snapshotRef.current = { value: next };
39
- onChange();
40
- }
41
- },
42
- ), [versionRef.current]);
43
- const getSnapshot = useCallback(() => snapshotRef.current!.value, []);
44
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
45
- }
46
-
47
- function defaultEquals<T>(a: T, b: T): boolean {
48
- if (Object.is(a, b)) return true;
49
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
50
- return a.every((value, index) => Object.is(value, b[index]));
51
- }