atom.io 0.6.1 → 0.6.3

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 (90) hide show
  1. package/dist/index.d.mts +3 -3
  2. package/dist/index.d.ts +3 -3
  3. package/dist/index.js +7 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +7 -2
  6. package/dist/index.mjs.map +1 -1
  7. package/json/dist/index.js.map +1 -1
  8. package/json/dist/index.mjs.map +1 -1
  9. package/package.json +13 -3
  10. package/react/dist/index.js.map +1 -1
  11. package/react/dist/index.mjs.map +1 -1
  12. package/react-devtools/dist/index.js +32 -18
  13. package/react-devtools/dist/index.js.map +1 -1
  14. package/react-devtools/dist/index.mjs +32 -18
  15. package/react-devtools/dist/index.mjs.map +1 -1
  16. package/realtime/dist/index.js.map +1 -1
  17. package/realtime/dist/index.mjs.map +1 -1
  18. package/realtime-react/dist/index.js.map +1 -1
  19. package/realtime-react/dist/index.mjs.map +1 -1
  20. package/realtime-testing/dist/index.d.mts +49 -0
  21. package/realtime-testing/dist/index.d.ts +49 -0
  22. package/realtime-testing/dist/index.js +153 -0
  23. package/realtime-testing/dist/index.js.map +1 -0
  24. package/realtime-testing/dist/index.mjs +117 -0
  25. package/realtime-testing/dist/index.mjs.map +1 -0
  26. package/realtime-testing/package.json +15 -0
  27. package/src/atom.ts +15 -15
  28. package/src/index.ts +59 -59
  29. package/src/internal/atom-internal.ts +36 -36
  30. package/src/internal/families-internal.ts +114 -114
  31. package/src/internal/get.ts +83 -83
  32. package/src/internal/is-default.ts +17 -17
  33. package/src/internal/meta/attach-meta.ts +7 -7
  34. package/src/internal/meta/meta-state.ts +115 -115
  35. package/src/internal/operation.ts +93 -93
  36. package/src/internal/selector/create-read-write-selector.ts +46 -46
  37. package/src/internal/selector/create-readonly-selector.ts +37 -37
  38. package/src/internal/selector/lookup-selector-sources.ts +9 -9
  39. package/src/internal/selector/register-selector.ts +44 -44
  40. package/src/internal/selector/trace-selector-atoms.ts +30 -30
  41. package/src/internal/selector/update-selector-atoms.ts +25 -25
  42. package/src/internal/selector-internal.ts +37 -37
  43. package/src/internal/set.ts +78 -78
  44. package/src/internal/store.ts +118 -118
  45. package/src/internal/subscribe-internal.ts +62 -62
  46. package/src/internal/time-travel-internal.ts +76 -76
  47. package/src/internal/timeline/add-atom-to-timeline.ts +158 -153
  48. package/src/internal/timeline-internal.ts +80 -80
  49. package/src/internal/transaction/abort-transaction.ts +8 -8
  50. package/src/internal/transaction/apply-transaction.ts +41 -41
  51. package/src/internal/transaction/build-transaction.ts +28 -28
  52. package/src/internal/transaction/index.ts +7 -7
  53. package/src/internal/transaction/redo-transaction.ts +13 -13
  54. package/src/internal/transaction/undo-transaction.ts +13 -13
  55. package/src/internal/transaction-internal.ts +48 -48
  56. package/src/json/select-json.ts +12 -12
  57. package/src/logger.ts +30 -30
  58. package/src/react/store-context.tsx +4 -4
  59. package/src/react/store-hooks.ts +18 -18
  60. package/src/react-devtools/AtomIODevtools.tsx +83 -82
  61. package/src/react-devtools/StateEditor.tsx +53 -53
  62. package/src/react-devtools/TokenList.tsx +47 -42
  63. package/src/react-explorer/AtomIOExplorer.tsx +197 -185
  64. package/src/react-explorer/explorer-effects.ts +11 -11
  65. package/src/react-explorer/explorer-states.ts +186 -193
  66. package/src/react-explorer/index.ts +11 -11
  67. package/src/react-explorer/space-states.ts +48 -50
  68. package/src/react-explorer/view-states.ts +25 -25
  69. package/src/realtime/hook-composition/expose-family.ts +81 -81
  70. package/src/realtime/hook-composition/expose-single.ts +26 -26
  71. package/src/realtime/hook-composition/expose-timeline.ts +60 -0
  72. package/src/realtime/hook-composition/index.ts +2 -2
  73. package/src/realtime/hook-composition/receive-state.ts +18 -18
  74. package/src/realtime/hook-composition/receive-transaction.ts +8 -8
  75. package/src/realtime-react/realtime-context.tsx +17 -17
  76. package/src/realtime-react/realtime-hooks.ts +17 -17
  77. package/src/realtime-react/realtime-state.ts +4 -4
  78. package/src/realtime-react/use-pull-family-member.ts +15 -15
  79. package/src/realtime-react/use-pull-family.ts +13 -13
  80. package/src/realtime-react/use-pull.ts +12 -12
  81. package/src/realtime-react/use-push.ts +15 -15
  82. package/src/realtime-react/use-server-action.ts +21 -21
  83. package/src/realtime-testing/index.ts +1 -0
  84. package/src/realtime-testing/setup-realtime-test.tsx +160 -0
  85. package/src/selector.ts +25 -25
  86. package/src/silo.ts +38 -38
  87. package/src/subscribe.ts +68 -68
  88. package/src/timeline.ts +13 -13
  89. package/src/transaction.ts +28 -28
  90. package/src/web-effects/storage.ts +17 -17
@@ -5,97 +5,97 @@ import * as AtomIO from "atom.io"
5
5
  import type { ServerConfig } from ".."
6
6
 
7
7
  const subscribeToTokenCreation = <T>(
8
- family: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,
9
- handleTokenCreation: (token: AtomIO.StateToken<T>) => void
8
+ family: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,
9
+ handleTokenCreation: (token: AtomIO.StateToken<T>) => void,
10
10
  ): (() => void) => {
11
- const subscription =
12
- family.type === `atom_family`
13
- ? family.subject.subscribe(handleTokenCreation)
14
- : family.subject.subscribe(handleTokenCreation)
15
- return () => subscription.unsubscribe()
11
+ const subscription =
12
+ family.type === `atom_family`
13
+ ? family.subject.subscribe(handleTokenCreation)
14
+ : family.subject.subscribe(handleTokenCreation)
15
+ return () => subscription.unsubscribe()
16
16
  }
17
17
 
18
18
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
19
19
  export const useExposeFamily = ({ socket, store }: ServerConfig) => {
20
- return function exposeFamily<J extends Json>(
21
- family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
22
- index: AtomIO.StateToken<Set<string>>
23
- ): () => void {
24
- const unsubSingleCallbacksByKey = new Map<string, () => void>()
25
- const unsubFamilyCallbacksByKey = new Map<string, () => void>()
20
+ return function exposeFamily<J extends Json>(
21
+ family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
22
+ index: AtomIO.StateToken<Set<string>>,
23
+ ): () => void {
24
+ const unsubSingleCallbacksByKey = new Map<string, () => void>()
25
+ const unsubFamilyCallbacksByKey = new Map<string, () => void>()
26
26
 
27
- const fillFamilyUnsubRequest = () => {
28
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub())
29
- unsubFamilyCallbacksByKey.clear()
30
- socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)
31
- }
27
+ const fillFamilyUnsubRequest = () => {
28
+ unsubFamilyCallbacksByKey.forEach((unsub) => unsub())
29
+ unsubFamilyCallbacksByKey.clear()
30
+ socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)
31
+ }
32
32
 
33
- const fillSingleUnsubRequest = (key: string) => {
34
- socket.off(`unsub:${key}`, fillSingleUnsubRequest)
35
- const unsub = unsubSingleCallbacksByKey.get(key)
36
- if (unsub) {
37
- unsub()
38
- unsubSingleCallbacksByKey.delete(key)
39
- }
40
- }
33
+ const fillSingleUnsubRequest = (key: string) => {
34
+ socket.off(`unsub:${key}`, fillSingleUnsubRequest)
35
+ const unsub = unsubSingleCallbacksByKey.get(key)
36
+ if (unsub) {
37
+ unsub()
38
+ unsubSingleCallbacksByKey.delete(key)
39
+ }
40
+ }
41
41
 
42
- const fillSubRequest = (subKey?: AtomIO.Serializable) => {
43
- if (subKey === undefined) {
44
- const keys = AtomIO.getState(index, store)
45
- keys.forEach((key) => {
46
- const token = family(key)
47
- socket.emit(
48
- `serve:${family.key}`,
49
- parseJson(token.family?.subKey || `null`),
50
- AtomIO.getState(token, store)
51
- )
52
- })
42
+ const fillSubRequest = (subKey?: AtomIO.Serializable) => {
43
+ if (subKey === undefined) {
44
+ const keys = AtomIO.getState(index, store)
45
+ keys.forEach((key) => {
46
+ const token = family(key)
47
+ socket.emit(
48
+ `serve:${family.key}`,
49
+ parseJson(token.family?.subKey || `null`),
50
+ AtomIO.getState(token, store),
51
+ )
52
+ })
53
53
 
54
- const unsubscribeFromTokenCreation = subscribeToTokenCreation(
55
- family,
56
- (token) => {
57
- const unsub = AtomIO.subscribe(
58
- token,
59
- ({ newValue }) => {
60
- socket.emit(
61
- `serve:${family.key}`,
62
- parseJson(token.family?.subKey || `null`),
63
- newValue
64
- )
65
- },
66
- store
67
- )
68
- unsubFamilyCallbacksByKey.set(token.key, unsub)
69
- }
70
- )
71
- unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)
54
+ const unsubscribeFromTokenCreation = subscribeToTokenCreation(
55
+ family,
56
+ (token) => {
57
+ const unsub = AtomIO.subscribe(
58
+ token,
59
+ ({ newValue }) => {
60
+ socket.emit(
61
+ `serve:${family.key}`,
62
+ parseJson(token.family?.subKey || `null`),
63
+ newValue,
64
+ )
65
+ },
66
+ store,
67
+ )
68
+ unsubFamilyCallbacksByKey.set(token.key, unsub)
69
+ },
70
+ )
71
+ unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)
72
72
 
73
- socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)
74
- } else {
75
- const token = family(subKey)
76
- socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))
77
- const unsubscribe = AtomIO.subscribe(
78
- token,
79
- ({ newValue }) => {
80
- socket.emit(`serve:${token.key}`, newValue)
81
- },
82
- store
83
- )
84
- unsubSingleCallbacksByKey.set(token.key, unsubscribe)
85
- socket.on(`unsub:${token.key}`, () => {
86
- fillSingleUnsubRequest(token.key)
87
- })
88
- }
89
- }
73
+ socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)
74
+ } else {
75
+ const token = family(subKey)
76
+ socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))
77
+ const unsubscribe = AtomIO.subscribe(
78
+ token,
79
+ ({ newValue }) => {
80
+ socket.emit(`serve:${token.key}`, newValue)
81
+ },
82
+ store,
83
+ )
84
+ unsubSingleCallbacksByKey.set(token.key, unsubscribe)
85
+ socket.on(`unsub:${token.key}`, () => {
86
+ fillSingleUnsubRequest(token.key)
87
+ })
88
+ }
89
+ }
90
90
 
91
- socket.on(`sub:${family.key}`, fillSubRequest)
91
+ socket.on(`sub:${family.key}`, fillSubRequest)
92
92
 
93
- return () => {
94
- socket.off(`sub:${family.key}`, fillSubRequest)
95
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub())
96
- unsubSingleCallbacksByKey.forEach((unsub) => unsub())
97
- unsubFamilyCallbacksByKey.clear()
98
- unsubSingleCallbacksByKey.clear()
99
- }
100
- }
93
+ return () => {
94
+ socket.off(`sub:${family.key}`, fillSubRequest)
95
+ unsubFamilyCallbacksByKey.forEach((unsub) => unsub())
96
+ unsubSingleCallbacksByKey.forEach((unsub) => unsub())
97
+ unsubFamilyCallbacksByKey.clear()
98
+ unsubSingleCallbacksByKey.clear()
99
+ }
100
+ }
101
101
  }
@@ -5,34 +5,34 @@ import type { ServerConfig } from ".."
5
5
 
6
6
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
7
  export const useExposeSingle = ({ socket, store }: ServerConfig) => {
8
- return function exposeSingle<J extends Json>(
9
- token: AtomIO.StateToken<J>
10
- ): () => void {
11
- let unsubscribeFromStateUpdates: (() => void) | null = null
8
+ return function exposeSingle<J extends Json>(
9
+ token: AtomIO.StateToken<J>,
10
+ ): () => void {
11
+ let unsubscribeFromStateUpdates: (() => void) | null = null
12
12
 
13
- const fillUnsubRequest = () => {
14
- socket.off(`unsub:${token.key}`, fillUnsubRequest)
15
- unsubscribeFromStateUpdates?.()
16
- unsubscribeFromStateUpdates = null
17
- }
13
+ const fillUnsubRequest = () => {
14
+ socket.off(`unsub:${token.key}`, fillUnsubRequest)
15
+ unsubscribeFromStateUpdates?.()
16
+ unsubscribeFromStateUpdates = null
17
+ }
18
18
 
19
- const fillSubRequest = () => {
20
- socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))
21
- unsubscribeFromStateUpdates = AtomIO.subscribe(
22
- token,
23
- ({ newValue }) => {
24
- socket.emit(`serve:${token.key}`, newValue)
25
- },
26
- store
27
- )
28
- socket.on(`unsub:${token.key}`, fillUnsubRequest)
29
- }
19
+ const fillSubRequest = () => {
20
+ socket.emit(`serve:${token.key}`, AtomIO.getState(token, store))
21
+ unsubscribeFromStateUpdates = AtomIO.subscribe(
22
+ token,
23
+ ({ newValue }) => {
24
+ socket.emit(`serve:${token.key}`, newValue)
25
+ },
26
+ store,
27
+ )
28
+ socket.on(`unsub:${token.key}`, fillUnsubRequest)
29
+ }
30
30
 
31
- socket.on(`sub:${token.key}`, fillSubRequest)
31
+ socket.on(`sub:${token.key}`, fillSubRequest)
32
32
 
33
- return () => {
34
- socket.off(`sub:${token.key}`, fillSubRequest)
35
- unsubscribeFromStateUpdates?.()
36
- }
37
- }
33
+ return () => {
34
+ socket.off(`sub:${token.key}`, fillSubRequest)
35
+ unsubscribeFromStateUpdates?.()
36
+ }
37
+ }
38
38
  }
@@ -0,0 +1,60 @@
1
+ import * as AtomIO from "atom.io"
2
+
3
+ import { Join } from "~/packages/anvl/src/join"
4
+
5
+ import type { ServerConfig } from "."
6
+ import type { TimelineTransactionUpdate } from "../../internal"
7
+
8
+ export type TransactionRequest = {
9
+ key: string
10
+ params: unknown[]
11
+ transactionId: string
12
+ }
13
+
14
+ export const useExposeTimeline__UNSTABLE = ({
15
+ socket,
16
+ store,
17
+ }: ServerConfig): ((tl: AtomIO.TimelineToken) => () => void) => {
18
+ const timestampsOfTransactionsState = AtomIO.__INTERNAL__.atom__INTERNAL(
19
+ {
20
+ key: `timestampsOfTransactions`,
21
+ default: new Join<null, `transactionId`, `timestamp`>({
22
+ relationType: `1:1`,
23
+ })
24
+ .from(`transactionId`)
25
+ .to(`timestamp`),
26
+ },
27
+ undefined,
28
+ store,
29
+ )
30
+ return function exposeTimeline(tl: AtomIO.TimelineToken): () => void {
31
+ const handleTransactionRequest = (update: TransactionRequest) => {
32
+ AtomIO.runTransaction(
33
+ { key: update.key, type: `transaction` },
34
+ store,
35
+ )(...update.params)
36
+ }
37
+
38
+ socket.on(`txr:${tl.key}`, handleTransactionRequest)
39
+
40
+ const unsubscribeFromTimeline = AtomIO.subscribeToTimeline(
41
+ tl,
42
+ (update: TimelineTransactionUpdate) => {
43
+ // const timestamp = update.timestamp.toString()
44
+ // AtomIO.setState(
45
+ // timestampsOfTransactionsState,
46
+ // (j) => j.set(update),
47
+ // store
48
+ // )
49
+ if (update.type === `transaction_update`) {
50
+ socket.emit(`tl:${tl.key}`, update)
51
+ }
52
+ },
53
+ )
54
+
55
+ return () => {
56
+ socket.off(`tlu:${tl.key}`, handleTransactionRequest)
57
+ unsubscribeFromTimeline()
58
+ }
59
+ }
60
+ }
@@ -7,6 +7,6 @@ export * from "./receive-transaction"
7
7
  export * from "./receive-state"
8
8
 
9
9
  export type ServerConfig = {
10
- socket: SocketIO.Socket
11
- store?: AtomIO.__INTERNAL__.Store
10
+ socket: SocketIO.Socket
11
+ store?: AtomIO.__INTERNAL__.Store
12
12
  }
@@ -5,25 +5,25 @@ import type { ServerConfig } from ".."
5
5
 
6
6
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
7
  export const useReceiveState = ({ socket, store }: ServerConfig) => {
8
- return function receiveState<J extends Json>(
9
- token: AtomIO.StateToken<J>
10
- ): () => void {
11
- const publish = (newValue: J) => AtomIO.setState(token, newValue, store)
8
+ return function receiveState<J extends Json>(
9
+ token: AtomIO.StateToken<J>,
10
+ ): () => void {
11
+ const publish = (newValue: J) => AtomIO.setState(token, newValue, store)
12
12
 
13
- const fillPubUnclaim = () => {
14
- socket.off(`pub:${token.key}`, publish)
15
- socket.off(`unclaim:${token.key}`, fillPubUnclaim)
16
- }
17
- const fillPubClaim = () => {
18
- socket.on(`pub:${token.key}`, publish)
19
- socket.on(`unclaim:${token.key}`, fillPubUnclaim)
20
- }
13
+ const fillPubUnclaim = () => {
14
+ socket.off(`pub:${token.key}`, publish)
15
+ socket.off(`unclaim:${token.key}`, fillPubUnclaim)
16
+ }
17
+ const fillPubClaim = () => {
18
+ socket.on(`pub:${token.key}`, publish)
19
+ socket.on(`unclaim:${token.key}`, fillPubUnclaim)
20
+ }
21
21
 
22
- socket.on(`claim:${token.key}`, fillPubClaim)
22
+ socket.on(`claim:${token.key}`, fillPubClaim)
23
23
 
24
- return () => {
25
- socket.off(`claim:${token.key}`, fillPubClaim)
26
- socket.off(`pub:${token.key}`, publish)
27
- }
28
- }
24
+ return () => {
25
+ socket.off(`claim:${token.key}`, fillPubClaim)
26
+ socket.off(`pub:${token.key}`, publish)
27
+ }
28
+ }
29
29
  }
@@ -5,14 +5,14 @@ import type { ƒn } from "~/packages/anvl/src/function"
5
5
  import type { ServerConfig } from "."
6
6
 
7
7
  export const useReceiveTransaction = ({ socket, store }: ServerConfig) => {
8
- return function receiveTransaction<ƒ extends ƒn>(
9
- tx: AtomIO.TransactionToken<ƒ>
10
- ): () => void {
11
- const fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>
12
- AtomIO.runTransaction<ƒ>(tx, store)(...update.params)
8
+ return function receiveTransaction<ƒ extends ƒn>(
9
+ tx: AtomIO.TransactionToken<ƒ>,
10
+ ): () => void {
11
+ const fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>
12
+ AtomIO.runTransaction<ƒ>(tx, store)(...update.params)
13
13
 
14
- socket.on(`tx:${tx.key}`, fillTransactionRequest)
14
+ socket.on(`tx:${tx.key}`, fillTransactionRequest)
15
15
 
16
- return () => socket.off(`tx:${tx.key}`, fillTransactionRequest)
17
- }
16
+ return () => socket.off(`tx:${tx.key}`, fillTransactionRequest)
17
+ }
18
18
  }
@@ -7,25 +7,25 @@ import { io } from "socket.io-client"
7
7
  import { myIdState__INTERNAL } from "./realtime-state"
8
8
 
9
9
  export const RealtimeContext = React.createContext<{ socket: Socket }>({
10
- socket: io(),
10
+ socket: io(),
11
11
  })
12
12
 
13
13
  export const RealtimeProvider: React.FC<{
14
- children: React.ReactNode
15
- socket: Socket
14
+ children: React.ReactNode
15
+ socket: Socket
16
16
  }> = ({ children, socket }) => {
17
- const setMyId = AR.useI(myIdState__INTERNAL)
18
- React.useEffect(() => {
19
- socket.on(`connect`, () => {
20
- setMyId(socket.id)
21
- })
22
- socket.on(`disconnect`, () => {
23
- setMyId(null)
24
- })
25
- }, [socket, setMyId])
26
- return (
27
- <RealtimeContext.Provider value={{ socket }}>
28
- {children}
29
- </RealtimeContext.Provider>
30
- )
17
+ const setMyId = AR.useI(myIdState__INTERNAL)
18
+ React.useEffect(() => {
19
+ socket.on(`connect`, () => {
20
+ setMyId(socket.id)
21
+ })
22
+ socket.on(`disconnect`, () => {
23
+ setMyId(null)
24
+ })
25
+ }, [socket, setMyId])
26
+ return (
27
+ <RealtimeContext.Provider value={{ socket }}>
28
+ {children}
29
+ </RealtimeContext.Provider>
30
+ )
31
31
  }
@@ -10,26 +10,26 @@ import { usePush } from "./use-push"
10
10
  import { useServerAction } from "./use-server-action"
11
11
 
12
12
  export type RealtimeHooks = {
13
- usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void
14
- usePullFamily: <J extends Json>(
15
- family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>
16
- ) => void
17
- usePullFamilyMember: <J extends Json>(
18
- family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
19
- subKey: string
20
- ) => void
21
- usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void
22
- useServerAction: <ƒ extends ƒn>(
23
- token: AtomIO.TransactionToken<ƒ>
24
- ) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
13
+ usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void
14
+ usePullFamily: <J extends Json>(
15
+ family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
16
+ ) => void
17
+ usePullFamilyMember: <J extends Json>(
18
+ family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
19
+ subKey: string,
20
+ ) => void
21
+ usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void
22
+ useServerAction: <ƒ extends ƒn>(
23
+ token: AtomIO.TransactionToken<ƒ>,
24
+ ) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
25
25
  }
26
26
 
27
27
  export const realtimeHooks: RealtimeHooks = {
28
- usePull,
29
- usePullFamily,
30
- usePullFamilyMember,
31
- usePush,
32
- useServerAction,
28
+ usePull,
29
+ usePullFamily,
30
+ usePullFamilyMember,
31
+ usePush,
32
+ useServerAction,
33
33
  }
34
34
 
35
35
  export * from "./use-pull"
@@ -1,10 +1,10 @@
1
1
  import * as AtomIO from "atom.io"
2
2
 
3
3
  export const myIdState__INTERNAL = AtomIO.atom<string | null>({
4
- key: `myId__INTERNAL`,
5
- default: null,
4
+ key: `myId__INTERNAL`,
5
+ default: null,
6
6
  })
7
7
  export const myIdState = AtomIO.selector<string | null>({
8
- key: `myId`,
9
- get: ({ get }) => get(myIdState__INTERNAL),
8
+ key: `myId`,
9
+ get: ({ get }) => get(myIdState__INTERNAL),
10
10
  })
@@ -8,20 +8,20 @@ import { RealtimeContext } from "./realtime-context"
8
8
  import { StoreContext } from "../react"
9
9
 
10
10
  export function usePullFamilyMember<J extends Json>(
11
- family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
12
- subKey: AtomIO.Serializable
11
+ family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
12
+ subKey: AtomIO.Serializable,
13
13
  ): void {
14
- const token = family(subKey)
15
- const { socket } = React.useContext(RealtimeContext)
16
- const store = React.useContext(StoreContext)
17
- React.useEffect(() => {
18
- socket?.on(`serve:${token.key}`, (data: J) => {
19
- AtomIO.setState(family(subKey), data, store)
20
- })
21
- socket?.emit(`sub:${family.key}`, subKey)
22
- return () => {
23
- socket?.off(`serve:${token.key}`)
24
- socket?.emit(`unsub:${token.key}`)
25
- }
26
- }, [family.key])
14
+ const token = family(subKey)
15
+ const { socket } = React.useContext(RealtimeContext)
16
+ const store = React.useContext(StoreContext)
17
+ React.useEffect(() => {
18
+ socket?.on(`serve:${token.key}`, (data: J) => {
19
+ AtomIO.setState(family(subKey), data, store)
20
+ })
21
+ socket?.emit(`sub:${family.key}`, subKey)
22
+ return () => {
23
+ socket?.off(`serve:${token.key}`)
24
+ socket?.emit(`unsub:${token.key}`)
25
+ }
26
+ }, [family.key])
27
27
  }
@@ -8,18 +8,18 @@ import { RealtimeContext } from "./realtime-context"
8
8
  import { StoreContext } from "../react"
9
9
 
10
10
  export function usePullFamily<J extends Json>(
11
- family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>
11
+ family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
12
12
  ): void {
13
- const { socket } = React.useContext(RealtimeContext)
14
- const store = React.useContext(StoreContext)
15
- React.useEffect(() => {
16
- socket.on(`serve:${family.key}`, (key: Json, data: J) => {
17
- AtomIO.setState(family(key), data, store)
18
- })
19
- socket?.emit(`sub:${family.key}`)
20
- return () => {
21
- socket?.off(`serve:${family.key}`)
22
- socket?.emit(`unsub:${family.key}`)
23
- }
24
- }, [family.key])
13
+ const { socket } = React.useContext(RealtimeContext)
14
+ const store = React.useContext(StoreContext)
15
+ React.useEffect(() => {
16
+ socket.on(`serve:${family.key}`, (key: Json, data: J) => {
17
+ AtomIO.setState(family(key), data, store)
18
+ })
19
+ socket?.emit(`sub:${family.key}`)
20
+ return () => {
21
+ socket?.off(`serve:${family.key}`)
22
+ socket?.emit(`unsub:${family.key}`)
23
+ }
24
+ }, [family.key])
25
25
  }
@@ -8,16 +8,16 @@ import { RealtimeContext } from "./realtime-context"
8
8
  import { StoreContext } from "../react"
9
9
 
10
10
  export function usePull<J extends Json>(token: AtomIO.StateToken<J>): void {
11
- const { socket } = React.useContext(RealtimeContext)
12
- const store = React.useContext(StoreContext)
13
- React.useEffect(() => {
14
- socket.on(`serve:${token.key}`, (data: J) => {
15
- AtomIO.setState(token, data, store)
16
- })
17
- socket.emit(`sub:${token.key}`)
18
- return () => {
19
- socket.off(`serve:${token.key}`)
20
- socket.emit(`unsub:${token.key}`)
21
- }
22
- }, [token.key])
11
+ const { socket } = React.useContext(RealtimeContext)
12
+ const store = React.useContext(StoreContext)
13
+ React.useEffect(() => {
14
+ socket.on(`serve:${token.key}`, (data: J) => {
15
+ AtomIO.setState(token, data, store)
16
+ })
17
+ socket.emit(`sub:${token.key}`)
18
+ return () => {
19
+ socket.off(`serve:${token.key}`)
20
+ socket.emit(`unsub:${token.key}`)
21
+ }
22
+ }, [token.key])
23
23
  }
@@ -8,19 +8,19 @@ import { RealtimeContext } from "./realtime-context"
8
8
  import { StoreContext } from "../react"
9
9
 
10
10
  export function usePush<J extends Json>(token: AtomIO.StateToken<J>): void {
11
- const { socket } = React.useContext(RealtimeContext)
12
- const store = React.useContext(StoreContext)
13
- React.useEffect(() => {
14
- socket.emit(`claim:${token.key}`)
15
- AtomIO.subscribe(
16
- token,
17
- ({ newValue }) => {
18
- socket.emit(`pub:${token.key}`, newValue)
19
- },
20
- store
21
- )
22
- return () => {
23
- socket.emit(`unclaim:${token.key}`)
24
- }
25
- }, [token.key])
11
+ const { socket } = React.useContext(RealtimeContext)
12
+ const store = React.useContext(StoreContext)
13
+ React.useEffect(() => {
14
+ socket.emit(`claim:${token.key}`)
15
+ AtomIO.subscribe(
16
+ token,
17
+ ({ newValue }) => {
18
+ socket.emit(`pub:${token.key}`, newValue)
19
+ },
20
+ store,
21
+ )
22
+ return () => {
23
+ socket.emit(`unclaim:${token.key}`)
24
+ }
25
+ }, [token.key])
26
26
  }