atom.io 0.36.0 → 0.36.1

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 (100) hide show
  1. package/dist/internal/index.d.ts +83 -67
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +98 -98
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/introspection/index.d.ts +5 -6
  6. package/dist/introspection/index.d.ts.map +1 -1
  7. package/dist/introspection/index.js +2 -3
  8. package/dist/introspection/index.js.map +1 -1
  9. package/dist/main/index.d.ts +27 -29
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +8 -9
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/react/index.d.ts +2 -2
  14. package/dist/react/index.d.ts.map +1 -1
  15. package/dist/react/index.js.map +1 -1
  16. package/dist/react-devtools/index.d.ts.map +1 -1
  17. package/dist/react-devtools/index.js.map +1 -1
  18. package/dist/realtime-client/index.d.ts +7 -8
  19. package/dist/realtime-client/index.d.ts.map +1 -1
  20. package/dist/realtime-client/index.js +3 -4
  21. package/dist/realtime-client/index.js.map +1 -1
  22. package/dist/realtime-react/index.d.ts +4 -4
  23. package/dist/realtime-react/index.d.ts.map +1 -1
  24. package/dist/realtime-react/index.js.map +1 -1
  25. package/dist/realtime-server/index.d.ts +2 -2
  26. package/dist/realtime-server/index.d.ts.map +1 -1
  27. package/dist/realtime-server/index.js.map +1 -1
  28. package/dist/transceivers/set-rtx/index.d.ts +9 -2
  29. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  30. package/dist/transceivers/set-rtx/index.js +3 -0
  31. package/dist/transceivers/set-rtx/index.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/internal/atom/create-regular-atom.ts +5 -5
  34. package/src/internal/atom/has-role.ts +12 -0
  35. package/src/internal/atom/index.ts +1 -0
  36. package/src/internal/caching.ts +38 -16
  37. package/src/internal/families/find-in-store.ts +1 -1
  38. package/src/internal/families/get-family-of-token.ts +1 -1
  39. package/src/internal/families/init-family-member.ts +1 -1
  40. package/src/internal/families/seek-in-store.ts +1 -1
  41. package/src/internal/get-state/read-or-compute-value.ts +29 -20
  42. package/src/internal/index.ts +8 -8
  43. package/src/internal/join/join-internal.ts +7 -4
  44. package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
  45. package/src/internal/mutable/create-mutable-atom.ts +1 -1
  46. package/src/internal/mutable/get-json-family.ts +1 -1
  47. package/src/internal/mutable/get-json-token.ts +1 -1
  48. package/src/internal/mutable/get-update-family.ts +1 -1
  49. package/src/internal/mutable/get-update-token.ts +1 -1
  50. package/src/internal/mutable/tracker-family.ts +27 -31
  51. package/src/internal/mutable/tracker.ts +29 -23
  52. package/src/internal/mutable/transceiver.ts +11 -10
  53. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  54. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  55. package/src/internal/selector/create-writable-held-selector.ts +3 -3
  56. package/src/internal/selector/create-writable-pure-selector.ts +3 -3
  57. package/src/internal/set-state/set-atom.ts +15 -22
  58. package/src/internal/set-state/set-into-store.ts +5 -4
  59. package/src/internal/store/counterfeit.ts +1 -1
  60. package/src/internal/store/deposit.ts +7 -8
  61. package/src/internal/store/store.ts +6 -6
  62. package/src/internal/store/withdraw.ts +8 -8
  63. package/src/internal/subscribe/subscribe-in-store.ts +2 -2
  64. package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
  65. package/src/internal/timeline/create-timeline.ts +3 -3
  66. package/src/internal/transaction/act-upon-store.ts +2 -2
  67. package/src/internal/transaction/apply-transaction.ts +2 -2
  68. package/src/internal/transaction/build-transaction.ts +2 -2
  69. package/src/internal/transaction/create-transaction.ts +3 -3
  70. package/src/internal/transaction/index.ts +2 -2
  71. package/src/internal/transaction/is-root-store.ts +4 -2
  72. package/src/internal/utility-types.ts +1 -1
  73. package/src/introspection/attach-introspection-states.ts +3 -3
  74. package/src/introspection/attach-transaction-index.ts +4 -4
  75. package/src/introspection/attach-transaction-logs.ts +4 -4
  76. package/src/introspection/auditor.ts +3 -3
  77. package/src/main/atom.ts +4 -4
  78. package/src/main/dispose-state.ts +4 -3
  79. package/src/main/find-state.ts +1 -1
  80. package/src/main/get-state.ts +6 -5
  81. package/src/main/reset-state.ts +3 -3
  82. package/src/main/set-state.ts +3 -3
  83. package/src/main/subscribe.ts +3 -3
  84. package/src/main/tokens.ts +6 -10
  85. package/src/main/transaction.ts +13 -15
  86. package/src/react/use-json.ts +5 -5
  87. package/src/react-devtools/TransactionIndex.tsx +3 -3
  88. package/src/react-devtools/Updates.tsx +2 -2
  89. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
  90. package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
  91. package/src/realtime-client/pull-mutable-atom.ts +5 -8
  92. package/src/realtime-client/push-state.ts +6 -5
  93. package/src/realtime-client/server-action.ts +5 -4
  94. package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
  95. package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
  96. package/src/realtime-react/use-server-action.ts +2 -2
  97. package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
  98. package/src/realtime-server/realtime-mutable-provider.ts +1 -1
  99. package/src/transceivers/set-rtx/set-rtx.ts +14 -1
  100. package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
@@ -30,7 +30,7 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
30
30
  * @overload Mutable Atom
31
31
  */
32
32
  export function findState<
33
- T extends Transceiver<any, any>,
33
+ T extends Transceiver<any, any, any>,
34
34
  K extends Canonical,
35
35
  Key extends K,
36
36
  >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
@@ -1,4 +1,5 @@
1
- import * as Internal from "atom.io/internal"
1
+ import type { ViewOf } from "atom.io/internal"
2
+ import { getFromStore, IMPLICIT } from "atom.io/internal"
2
3
  import type { Canonical } from "atom.io/json"
3
4
 
4
5
  import type { ReadableFamilyToken, ReadableToken } from "."
@@ -10,7 +11,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
10
11
  * @overload Default
11
12
  * @default
12
13
  */
13
- export function getState<T>(token: ReadableToken<T>): T
14
+ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
14
15
 
15
16
  /**
16
17
  * Read or compute the current value of a state
@@ -22,7 +23,7 @@ export function getState<T>(token: ReadableToken<T>): T
22
23
  export function getState<T, K extends Canonical, Key extends K>(
23
24
  token: ReadableFamilyToken<T, K>,
24
25
  key: Key,
25
- ): T
26
+ ): ViewOf<T>
26
27
 
27
28
  export function getState(
28
29
  ...params:
@@ -30,7 +31,7 @@ export function getState(
30
31
  | [token: ReadableToken<any>]
31
32
  ): any {
32
33
  if (params.length === 2) {
33
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
34
+ return getFromStore(IMPLICIT.STORE, ...params)
34
35
  }
35
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
36
+ return getFromStore(IMPLICIT.STORE, ...params)
36
37
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, resetInStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "."
@@ -26,8 +26,8 @@ export function resetState(
26
26
  | [token: WritableToken<any>]
27
27
  ): void {
28
28
  if (params.length === 2) {
29
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
29
+ resetInStore(IMPLICIT.STORE, ...params)
30
30
  } else {
31
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
31
+ resetInStore(IMPLICIT.STORE, ...params)
32
32
  }
33
33
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, setIntoStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "./tokens"
@@ -45,8 +45,8 @@ export function setState<T, New extends T>(
45
45
  | [token: WritableToken<T>, value: New | Setter<T, New>]
46
46
  ): void {
47
47
  if (params.length === 2) {
48
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
48
+ setIntoStore(IMPLICIT.STORE, ...params)
49
49
  } else {
50
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
50
+ setIntoStore(IMPLICIT.STORE, ...params)
51
51
  }
52
52
  }
@@ -1,4 +1,4 @@
1
- import type { Flat, Func } from "atom.io/internal"
1
+ import type { Flat, Fn } from "atom.io/internal"
2
2
  import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
3
3
 
4
4
  import type {
@@ -20,7 +20,7 @@ export type KeyedStateUpdate<T> = Flat<
20
20
  }
21
21
  >
22
22
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
23
- export type TransactionUpdateHandler<F extends Func> = (
23
+ export type TransactionUpdateHandler<F extends Fn> = (
24
24
  data: TransactionUpdate<F>,
25
25
  ) => void
26
26
 
@@ -45,7 +45,7 @@ export function subscribe<T>(
45
45
  * @returns A function that can be called to unsubscribe from the transaction
46
46
  * @overload Transaction
47
47
  */
48
- export function subscribe<F extends Func>(
48
+ export function subscribe<F extends Fn>(
49
49
  token: TransactionToken<F>,
50
50
  handleUpdate: TransactionUpdateHandler<F>,
51
51
  key?: string,
@@ -1,4 +1,4 @@
1
- import type { AsJSON, Func, Transceiver } from "atom.io/internal"
1
+ import type { AsJSON, Fn, Transceiver } from "atom.io/internal"
2
2
  import type { Canonical, stringified } from "atom.io/json"
3
3
 
4
4
  /**
@@ -53,7 +53,7 @@ export type TimelineToken<M> = {
53
53
  __M?: M
54
54
  }
55
55
 
56
- export type TransactionToken<F extends Func> = {
56
+ export type TransactionToken<F extends Fn> = {
57
57
  /** The unique identifier of the transaction */
58
58
  key: string
59
59
  /** Discriminator */
@@ -63,7 +63,7 @@ export type TransactionToken<F extends Func> = {
63
63
  }
64
64
 
65
65
  export type AtomToken<T, K extends Canonical = any> =
66
- | MutableAtomToken<T extends Transceiver<any, any> ? T : never, K>
66
+ | MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
67
67
  | RegularAtomToken<T, K>
68
68
  export type RegularAtomToken<T, K extends Canonical = any> = {
69
69
  /** The unique identifier of the atom. */
@@ -76,7 +76,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
76
76
  __T?: T
77
77
  }
78
78
  export type MutableAtomToken<
79
- T extends Transceiver<any, any>,
79
+ T extends Transceiver<any, any, any>,
80
80
  K extends Canonical = any,
81
81
  > = {
82
82
  /** The unique identifier of the atom. */
@@ -87,8 +87,6 @@ export type MutableAtomToken<
87
87
  family?: FamilyMetadata<K>
88
88
  /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
89
89
  __J?: AsJSON<T>
90
- /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
91
- __U?: T extends Transceiver<infer Update, any> ? Update : never
92
90
  }
93
91
 
94
92
  export type SelectorToken<T, K extends Canonical = any> =
@@ -159,7 +157,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
159
157
  }
160
158
 
161
159
  export type AtomFamilyToken<T, K extends Canonical = Canonical> =
162
- | MutableAtomFamilyToken<T extends Transceiver<any, any> ? T : never, K>
160
+ | MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
163
161
  | RegularAtomFamilyToken<T, K>
164
162
  export type RegularAtomFamilyToken<T, K extends Canonical> = {
165
163
  /** The unique identifier of the atom family */
@@ -172,7 +170,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
172
170
  __K?: K
173
171
  }
174
172
  export type MutableAtomFamilyToken<
175
- T extends Transceiver<any, any>,
173
+ T extends Transceiver<any, any, any>,
176
174
  K extends Canonical,
177
175
  > = {
178
176
  /** The unique identifier of the atom family */
@@ -181,8 +179,6 @@ export type MutableAtomFamilyToken<
181
179
  type: `mutable_atom_family`
182
180
  /** Never present. This is a marker that preserves the type of atoms in this family */
183
181
  __T?: T
184
- /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
185
- __J?: AsJSON<T>
186
182
  /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
187
183
  __K?: K
188
184
  }
@@ -1,9 +1,4 @@
1
- import type {
2
- AsJSON,
3
- EnvironmentData,
4
- Func,
5
- Transceiver,
6
- } from "atom.io/internal"
1
+ import type { AsJSON, EnvironmentData, Fn, Transceiver } from "atom.io/internal"
7
2
  import {
8
3
  actUponStore,
9
4
  arbitrary,
@@ -33,6 +28,9 @@ export type StateCreation<Token extends ReadableToken<any>> = {
33
28
  export type StateDisposal<Token extends ReadableToken<any>> =
34
29
  | AtomDisposal<Token>
35
30
  | SelectorDisposal<Token>
31
+ export type StateLifecycleEvent<Token extends ReadableToken<any>> =
32
+ | StateCreation<Token>
33
+ | StateDisposal<Token>
36
34
 
37
35
  export type AtomDisposal<Token extends ReadableToken<any>> = {
38
36
  type: `state_disposal`
@@ -72,9 +70,9 @@ export type TransactionUpdateContent =
72
70
  | MoleculeTransfer
73
71
  | StateCreation<ReadableToken<unknown>>
74
72
  | StateDisposal<ReadableToken<unknown>>
75
- | TransactionUpdate<Func>
73
+ | TransactionUpdate<Fn>
76
74
 
77
- export type TransactionUpdate<F extends Func> = {
75
+ export type TransactionUpdate<F extends Fn> = {
78
76
  type: `transaction_update`
79
77
  key: string
80
78
  id: string
@@ -91,7 +89,7 @@ export type ActorToolkit = Readonly<{
91
89
  set: typeof setState
92
90
  reset: typeof resetState
93
91
  find: typeof findState
94
- json: <T extends Transceiver<any, any>>(
92
+ json: <T extends Transceiver<any, any, any>>(
95
93
  state: MutableAtomToken<T>,
96
94
  ) => WritablePureSelectorToken<AsJSON<T>>
97
95
  dispose: typeof disposeState
@@ -99,21 +97,21 @@ export type ActorToolkit = Readonly<{
99
97
  env: () => EnvironmentData
100
98
  }>
101
99
 
102
- export type Read<F extends Func> = (
100
+ export type Read<F extends Fn> = (
103
101
  toolkit: ReaderToolkit,
104
102
  ...parameters: Parameters<F>
105
103
  ) => ReturnType<F>
106
- export type Write<F extends Func> = (
104
+ export type Write<F extends Fn> = (
107
105
  toolkit: WriterToolkit,
108
106
  ...parameters: Parameters<F>
109
107
  ) => ReturnType<F>
110
- export type Transact<F extends Func> = (
108
+ export type Transact<F extends Fn> = (
111
109
  toolkit: ActorToolkit,
112
110
  ...parameters: Parameters<F>
113
111
  ) => ReturnType<F>
114
112
  export type TransactionIO<Token extends TransactionToken<any>> =
115
113
  Token extends TransactionToken<infer F> ? F : never
116
- export type TransactionOptions<F extends Func> = {
114
+ export type TransactionOptions<F extends Fn> = {
117
115
  /** The unique identifier of the transaction */
118
116
  key: string
119
117
  /** The operation to perform */
@@ -125,7 +123,7 @@ export type TransactionOptions<F extends Func> = {
125
123
  * @param options - {@link TransactionOptions}
126
124
  * @returns A reference to the transaction created: a {@link TransactionToken}
127
125
  */
128
- export function transaction<F extends Func>(
126
+ export function transaction<F extends Fn>(
129
127
  options: TransactionOptions<F>,
130
128
  ): TransactionToken<F> {
131
129
  return createTransaction(IMPLICIT.STORE, options)
@@ -137,7 +135,7 @@ export function transaction<F extends Func>(
137
135
  * @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
138
136
  * @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
139
137
  */
140
- export function runTransaction<F extends Func>(
138
+ export function runTransaction<F extends Fn>(
141
139
  token: TransactionToken<F>,
142
140
  id: string = arbitrary(),
143
141
  ): (...parameters: Parameters<F>) => ReturnType<F> {
@@ -7,14 +7,14 @@ import * as React from "react"
7
7
  import { StoreContext } from "./store-context"
8
8
  import { useO } from "./use-o"
9
9
 
10
- export function useJSON<T extends Transceiver<any, any>>(
10
+ export function useJSON<T extends Transceiver<any, any, any>>(
11
11
  token: MutableAtomToken<T>,
12
12
  ): AsJSON<T>
13
13
 
14
- export function useJSON<T extends Transceiver<any, any>, K extends Canonical>(
15
- token: MutableAtomFamilyToken<T, K>,
16
- key: K,
17
- ): AsJSON<T>
14
+ export function useJSON<
15
+ T extends Transceiver<any, any, any>,
16
+ K extends Canonical,
17
+ >(token: MutableAtomFamilyToken<T, K>, key: K): AsJSON<T>
18
18
 
19
19
  export function useJSON(
20
20
  token: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,
@@ -4,7 +4,7 @@ import type {
4
4
  TransactionToken,
5
5
  TransactionUpdate,
6
6
  } from "atom.io"
7
- import { findInStore, type Func } from "atom.io/internal"
7
+ import { findInStore, type Fn } from "atom.io/internal"
8
8
  import { useI, useO } from "atom.io/react"
9
9
  import { type FC, useContext } from "react"
10
10
 
@@ -13,9 +13,9 @@ import { DevtoolsContext } from "./store"
13
13
  import { article } from "./Updates"
14
14
 
15
15
  export const TransactionLog: FC<{
16
- token: TransactionToken<Func>
16
+ token: TransactionToken<Fn>
17
17
  isOpenState: RegularAtomToken<boolean>
18
- logState: ReadonlyPureSelectorToken<TransactionUpdate<Func>[]>
18
+ logState: ReadonlyPureSelectorToken<TransactionUpdate<Fn>[]>
19
19
  }> = ({ token, isOpenState, logState }) => {
20
20
  const log = useO(logState)
21
21
  const isOpen = useO(isOpenState)
@@ -3,7 +3,7 @@ import type {
3
3
  TimelineUpdate,
4
4
  TransactionUpdate,
5
5
  } from "atom.io"
6
- import type { Func } from "atom.io/internal"
6
+ import type { Fn } from "atom.io/internal"
7
7
  import { discoverType, prettyJson } from "atom.io/introspection"
8
8
  import { stringifyJson } from "atom.io/json"
9
9
  import * as React from "react"
@@ -37,7 +37,7 @@ const AtomUpdateFC: React.FC<{
37
37
 
38
38
  const TransactionUpdateFC: React.FC<{
39
39
  serialNumber: number
40
- transactionUpdate: TransactionUpdate<Func>
40
+ transactionUpdate: TransactionUpdate<Fn>
41
41
  }> = ({ serialNumber, transactionUpdate }) => {
42
42
  return (
43
43
  <article
@@ -1,5 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import {
4
4
  actUponStore,
5
5
  getEpochNumberOfContinuity,
@@ -22,7 +22,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
22
22
  optimisticUpdates: AtomIO.TransactionUpdate<any>[],
23
23
  confirmedUpdates: AtomIO.TransactionUpdate<any>[],
24
24
  ) =>
25
- (confirmed: AtomIO.TransactionUpdate<Func>): void => {
25
+ (confirmed: AtomIO.TransactionUpdate<Fn>): void => {
26
26
  function reconcileEpoch(
27
27
  optimisticUpdate: AtomIO.TransactionUpdate<any>,
28
28
  confirmedUpdate: AtomIO.TransactionUpdate<any>,
@@ -1,16 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { AsJSON, Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
4
  import { parseJson } from "atom.io/json"
5
5
  import type { Socket } from "socket.io-client"
6
6
 
7
7
  /* eslint-disable no-console */
8
8
 
9
- export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
10
- store: Store,
11
- socket: Socket,
12
- token: AtomIO.MutableAtomToken<T>,
13
- ): () => void {
9
+ export function pullMutableAtomFamilyMember<
10
+ T extends Transceiver<any, any, any>,
11
+ >(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
14
12
  if (!(`family` in token)) {
15
13
  console.error(`Token is not a family member:`, token)
16
14
  return () => {}
@@ -21,13 +19,10 @@ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
21
19
  const jsonToken = getJsonToken(store, token)
22
20
  setIntoStore(store, jsonToken, data)
23
21
  })
24
- socket.on(
25
- `next:${token.key}`,
26
- (data: T extends Transceiver<infer Signal, any> ? Signal : never) => {
27
- const trackerToken = getUpdateToken(token)
28
- setIntoStore(store, trackerToken, data)
29
- },
30
- )
22
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
23
+ const trackerToken = getUpdateToken(token)
24
+ setIntoStore(store, trackerToken, data)
25
+ })
31
26
  socket.emit(`sub:${familyKey}`, subKey)
32
27
  return () => {
33
28
  socket.off(`serve:${token.key}`)
@@ -1,9 +1,9 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { AsJSON, Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
4
  import type { Socket } from "socket.io-client"
5
5
 
6
- export function pullMutableAtom<T extends Transceiver<any, any>>(
6
+ export function pullMutableAtom<T extends Transceiver<any, any, any>>(
7
7
  store: Store,
8
8
  socket: Socket,
9
9
  token: AtomIO.MutableAtomToken<T>,
@@ -13,12 +13,9 @@ export function pullMutableAtom<T extends Transceiver<any, any>>(
13
13
  socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
14
14
  setIntoStore(store, jsonToken, data)
15
15
  })
16
- socket.on(
17
- `next:${token.key}`,
18
- (data: T extends Transceiver<infer Update, any> ? Update : never) => {
19
- setIntoStore(store, updateToken, data)
20
- },
21
- )
16
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
17
+ setIntoStore(store, updateToken, data)
18
+ })
22
19
  socket.emit(`sub:${token.key}`)
23
20
  return () => {
24
21
  socket.off(`init:${token.key}`)
@@ -1,15 +1,16 @@
1
- import type * as AtomIO from "atom.io"
2
- import * as Internal from "atom.io/internal"
1
+ import type { WritableToken } from "atom.io"
2
+ import type { Store } from "atom.io/internal"
3
+ import { subscribeToState } from "atom.io/internal"
3
4
  import type { Json } from "atom.io/json"
4
5
  import type { Socket } from "socket.io-client"
5
6
 
6
7
  export function pushState<J extends Json.Serializable>(
7
- store: Internal.Store,
8
+ store: Store,
8
9
  socket: Socket,
9
- token: AtomIO.WritableToken<J>,
10
+ token: WritableToken<J>,
10
11
  ): () => void {
11
12
  socket.emit(`claim:${token.key}`)
12
- Internal.subscribeToState(store, token, `push`, ({ newValue }) => {
13
+ subscribeToState(store, token, `push`, ({ newValue }) => {
13
14
  socket.emit(`pub:${token.key}`, newValue)
14
15
  })
15
16
  return () => {
@@ -1,13 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import * as Internal from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
+ import { subscribeToTransaction } from "atom.io/internal"
3
4
  import type { Socket } from "socket.io-client"
4
5
 
5
- export function serverAction<F extends Internal.Func>(
6
- store: Internal.Store,
6
+ export function serverAction<F extends Fn>(
7
+ store: Store,
7
8
  socket: Socket,
8
9
  token: AtomIO.TransactionToken<F>,
9
10
  ): () => void {
10
- const unsubscribeFromLocalUpdates = Internal.subscribeToTransaction(
11
+ const unsubscribeFromLocalUpdates = subscribeToTransaction(
11
12
  store,
12
13
  token,
13
14
  `tx-run:${token.key}:${socket.id}`,
@@ -6,7 +6,7 @@ import * as React from "react"
6
6
 
7
7
  import { useRealtimeService } from "./use-realtime-service"
8
8
 
9
- export function usePullMutable<T extends Transceiver<any, any>>(
9
+ export function usePullMutable<T extends Transceiver<any, any, any>>(
10
10
  token: AtomIO.MutableAtomToken<T>,
11
11
  ): T {
12
12
  const store = React.useContext(StoreContext)
@@ -9,7 +9,7 @@ import * as React from "react"
9
9
  import { useRealtimeService } from "./use-realtime-service"
10
10
 
11
11
  export function usePullMutableAtomFamilyMember<
12
- T extends Transceiver<any, any>,
12
+ T extends Transceiver<any, any, any>,
13
13
  K extends Canonical,
14
14
  Key extends K,
15
15
  >(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
@@ -1,5 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Func } from "atom.io/internal"
2
+ import type { Fn } from "atom.io/internal"
3
3
  import { actUponStore, arbitrary } from "atom.io/internal"
4
4
  import { StoreContext } from "atom.io/react"
5
5
  import * as RTC from "atom.io/realtime-client"
@@ -7,7 +7,7 @@ import * as React from "react"
7
7
 
8
8
  import { useRealtimeService } from "./use-realtime-service"
9
9
 
10
- export function useServerAction<F extends Func>(
10
+ export function useServerAction<F extends Fn>(
11
11
  token: AtomIO.TransactionToken<F>,
12
12
  ): (...parameters: Parameters<F>) => ReturnType<F> {
13
13
  const store = React.useContext(StoreContext)
@@ -21,7 +21,7 @@ export function realtimeMutableFamilyProvider({
21
21
  store = IMPLICIT.STORE,
22
22
  }: ServerConfig) {
23
23
  return function mutableFamilyProvider<
24
- T extends Transceiver<any, any>,
24
+ T extends Transceiver<any, any, any>,
25
25
  K extends Canonical,
26
26
  >(
27
27
  family: AtomIO.MutableAtomFamilyToken<T, K>,
@@ -17,7 +17,7 @@ export function realtimeMutableProvider({
17
17
  store = IMPLICIT.STORE,
18
18
  }: ServerConfig) {
19
19
  return function mutableProvider<
20
- Core extends Transceiver<Json.Serializable, Json.Serializable>,
20
+ Core extends Transceiver<any, Json.Serializable, Json.Serializable>,
21
21
  >(token: AtomIO.MutableAtomToken<Core>): () => void {
22
22
  let unsubscribeFromStateUpdates: (() => void) | null = null
23
23
 
@@ -7,6 +7,13 @@ export type SetUpdateType = `add` | `clear` | `del` | `tx`
7
7
  export type SetUpdate = `${SetUpdateType}:${string}`
8
8
  export type NumberedSetUpdate = `${number}=${SetUpdate}`
9
9
 
10
+ export interface SetRTXView<P extends primitive> extends ReadonlySet<P> {
11
+ readonly cache: ReadonlyArray<NumberedSetUpdate | null>
12
+ readonly cacheLimit: number
13
+ readonly cacheIdx: number
14
+ readonly cacheUpdateNumber: number
15
+ }
16
+
10
17
  export interface SetRTXJson<P extends primitive> extends Json.Object {
11
18
  members: P[]
12
19
  cache: (NumberedSetUpdate | null)[]
@@ -16,7 +23,9 @@ export interface SetRTXJson<P extends primitive> extends Json.Object {
16
23
  }
17
24
  export class SetRTX<P extends primitive>
18
25
  extends Set<P>
19
- implements Transceiver<NumberedSetUpdate, SetRTXJson<P>>, Lineage
26
+ implements
27
+ Transceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,
28
+ Lineage
20
29
  {
21
30
  public mode: TransceiverMode = `record`
22
31
  public readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()
@@ -42,6 +51,10 @@ export class SetRTX<P extends primitive>
42
51
  }
43
52
  }
44
53
 
54
+ public view(): SetRTXView<P> {
55
+ return this
56
+ }
57
+
45
58
  public toJSON(): SetRTXJson<P> {
46
59
  return {
47
60
  members: [...this],
@@ -1,29 +0,0 @@
1
- import type { MutableAtom, Transceiver } from ".."
2
- import { Tracker } from "../mutable"
3
- import type { Store } from "../store"
4
-
5
- export function copyMutableIfNeeded<T extends Transceiver<any, any>>(
6
- target: Store,
7
- atom: MutableAtom<T>,
8
- origin: Store,
9
- ): T {
10
- const originValue = origin.valueMap.get(atom.key) as
11
- | Transceiver<any, any>
12
- | undefined
13
- const targetValue = target.valueMap.get(atom.key)
14
-
15
- if (originValue !== targetValue) {
16
- return targetValue
17
- }
18
-
19
- if (originValue === undefined) {
20
- return new atom.class()
21
- }
22
-
23
- origin.logger.info(`📃`, `atom`, atom.key, `copying`)
24
- const jsonValue = originValue.toJSON()
25
- const copiedValue = atom.class.fromJSON(jsonValue)
26
- target.valueMap.set(atom.key, copiedValue)
27
- new Tracker(atom, origin)
28
- return copiedValue
29
- }