atom.io 0.40.6 → 0.40.8

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 (186) hide show
  1. package/README.md +1 -1
  2. package/dist/data/index.d.ts +1 -1
  3. package/dist/data/index.js +1 -2
  4. package/dist/data/index.js.map +1 -1
  5. package/dist/employ-socket-D6wgByWh.js +12 -0
  6. package/dist/employ-socket-D6wgByWh.js.map +1 -0
  7. package/dist/eslint-plugin/index.js.map +1 -1
  8. package/dist/has-role-CMlaUlaf.js +1133 -0
  9. package/dist/has-role-CMlaUlaf.js.map +1 -0
  10. package/dist/internal/index.d.ts +248 -248
  11. package/dist/internal/index.d.ts.map +1 -1
  12. package/dist/internal/index.js +590 -1803
  13. package/dist/internal/index.js.map +1 -1
  14. package/dist/introspection/index.d.ts +1 -1
  15. package/dist/introspection/index.d.ts.map +1 -1
  16. package/dist/introspection/index.js +13 -32
  17. package/dist/introspection/index.js.map +1 -1
  18. package/dist/is-fn-DY1wZ-md.js +10 -0
  19. package/dist/is-fn-DY1wZ-md.js.map +1 -0
  20. package/dist/json/index.d.ts.map +1 -1
  21. package/dist/json/index.js.map +1 -1
  22. package/dist/main/index.d.ts +33 -33
  23. package/dist/main/index.d.ts.map +1 -1
  24. package/dist/main/index.js +3 -4
  25. package/dist/main/index.js.map +1 -1
  26. package/dist/mutex-store-CSvxY9i3.js +11 -0
  27. package/dist/mutex-store-CSvxY9i3.js.map +1 -0
  28. package/dist/react/index.d.ts +5 -5
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react-devtools/index.d.ts.map +1 -1
  32. package/dist/react-devtools/index.js +9 -11
  33. package/dist/react-devtools/index.js.map +1 -1
  34. package/dist/realtime/index.d.ts +7 -15
  35. package/dist/realtime/index.d.ts.map +1 -1
  36. package/dist/realtime/index.js +4 -35
  37. package/dist/realtime/index.js.map +1 -1
  38. package/dist/realtime-client/index.d.ts +6 -9
  39. package/dist/realtime-client/index.d.ts.map +1 -1
  40. package/dist/realtime-client/index.js +96 -88
  41. package/dist/realtime-client/index.js.map +1 -1
  42. package/dist/realtime-react/index.d.ts +17 -13
  43. package/dist/realtime-react/index.d.ts.map +1 -1
  44. package/dist/realtime-react/index.js +39 -50
  45. package/dist/realtime-react/index.js.map +1 -1
  46. package/dist/realtime-server/index.d.ts +83 -84
  47. package/dist/realtime-server/index.d.ts.map +1 -1
  48. package/dist/realtime-server/index.js +604 -543
  49. package/dist/realtime-server/index.js.map +1 -1
  50. package/dist/realtime-testing/index.d.ts +5 -4
  51. package/dist/realtime-testing/index.d.ts.map +1 -1
  52. package/dist/realtime-testing/index.js +35 -22
  53. package/dist/realtime-testing/index.js.map +1 -1
  54. package/dist/shared-room-store-BfW3nWif.js +31 -0
  55. package/dist/shared-room-store-BfW3nWif.js.map +1 -0
  56. package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
  57. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
  58. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  59. package/dist/transceivers/set-rtx/index.js +4 -8
  60. package/dist/transceivers/set-rtx/index.js.map +1 -1
  61. package/dist/web/index.d.ts +3 -3
  62. package/dist/web/index.d.ts.map +1 -1
  63. package/dist/web/index.js +4 -3
  64. package/dist/web/index.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/internal/atom/create-regular-atom.ts +5 -4
  67. package/src/internal/atom/dispose-atom.ts +7 -2
  68. package/src/internal/atom/has-role.ts +3 -3
  69. package/src/internal/caching.ts +4 -2
  70. package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
  71. package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
  72. package/src/internal/families/create-regular-atom-family.ts +2 -1
  73. package/src/internal/families/create-writable-held-selector-family.ts +2 -1
  74. package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
  75. package/src/internal/families/dispose-from-store.ts +4 -4
  76. package/src/internal/families/find-in-store.ts +10 -10
  77. package/src/internal/families/get-family-of-token.ts +2 -2
  78. package/src/internal/families/index.ts +1 -0
  79. package/src/internal/families/mint-in-store.ts +54 -19
  80. package/src/internal/families/seek-in-store.ts +1 -1
  81. package/src/internal/get-state/get-fallback.ts +2 -2
  82. package/src/internal/get-state/get-from-store.ts +5 -5
  83. package/src/internal/get-state/read-or-compute-value.ts +1 -1
  84. package/src/internal/get-state/reduce-reference.ts +8 -6
  85. package/src/internal/index.ts +2 -220
  86. package/src/internal/molecule.ts +1 -2
  87. package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
  88. package/src/internal/mutable/create-mutable-atom.ts +4 -2
  89. package/src/internal/mutable/get-json-family.ts +1 -1
  90. package/src/internal/mutable/get-update-family.ts +1 -1
  91. package/src/internal/mutable/tracker-family.ts +2 -1
  92. package/src/internal/mutable/tracker.ts +71 -59
  93. package/src/internal/safe-compute.ts +1 -1
  94. package/src/internal/selector/create-readonly-held-selector.ts +2 -1
  95. package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
  96. package/src/internal/selector/create-writable-held-selector.ts +2 -1
  97. package/src/internal/selector/create-writable-pure-selector.ts +2 -1
  98. package/src/internal/selector/dispose-selector.ts +3 -2
  99. package/src/internal/selector/register-selector.ts +8 -5
  100. package/src/internal/selector/trace-selector-atoms.ts +2 -1
  101. package/src/internal/set-state/dispatch-state-update.ts +3 -2
  102. package/src/internal/set-state/evict-downstream.ts +1 -1
  103. package/src/internal/set-state/operate-on-store.ts +16 -22
  104. package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
  105. package/src/internal/set-state/reset-in-store.ts +5 -5
  106. package/src/internal/set-state/set-atom-or-selector.ts +2 -2
  107. package/src/internal/set-state/set-atom.ts +4 -2
  108. package/src/internal/set-state/set-into-store.ts +21 -39
  109. package/src/internal/set-state/set-selector.ts +3 -2
  110. package/src/internal/state-types.ts +228 -0
  111. package/src/internal/store/deposit.ts +4 -4
  112. package/src/internal/store/index.ts +0 -1
  113. package/src/internal/store/store.ts +9 -9
  114. package/src/internal/store/withdraw.ts +4 -4
  115. package/src/internal/subscribe/recall-state.ts +1 -1
  116. package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
  117. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  118. package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
  119. package/src/internal/transaction/build-transaction.ts +3 -2
  120. package/src/internal/transaction/index.ts +1 -23
  121. package/src/internal/transaction/is-root-store.ts +4 -1
  122. package/src/internal/transaction/transaction-meta-progress.ts +22 -0
  123. package/src/main/atom.ts +1 -2
  124. package/src/main/find-state.ts +5 -5
  125. package/src/main/get-state.ts +4 -4
  126. package/src/main/realm.ts +2 -2
  127. package/src/main/set-state.ts +10 -10
  128. package/src/react/parse-state-overloads.ts +3 -3
  129. package/src/react/use-i.ts +6 -4
  130. package/src/react/use-loadable.ts +4 -10
  131. package/src/react/use-o.ts +6 -4
  132. package/src/react-devtools/store.ts +6 -6
  133. package/src/realtime/index.ts +1 -0
  134. package/src/realtime/mutex-store.ts +11 -0
  135. package/src/realtime/realtime-continuity.ts +1 -5
  136. package/src/realtime-client/index.ts +0 -1
  137. package/src/realtime-client/pull-atom-family-member.ts +14 -17
  138. package/src/realtime-client/pull-atom.ts +1 -1
  139. package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
  140. package/src/realtime-client/pull-selector-family-member.ts +8 -35
  141. package/src/realtime-client/pull-selector-roots.ts +90 -0
  142. package/src/realtime-client/pull-selector.ts +2 -27
  143. package/src/realtime-client/push-state.ts +33 -5
  144. package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
  145. package/src/realtime-react/index.ts +2 -2
  146. package/src/realtime-react/realtime-context.tsx +9 -5
  147. package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
  148. package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
  149. package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
  150. package/src/realtime-react/use-push.ts +7 -3
  151. package/src/realtime-react/use-realtime-service.ts +11 -11
  152. package/src/realtime-react/use-single-effect.ts +11 -14
  153. package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
  154. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  155. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
  156. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  157. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  158. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  159. package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
  160. package/src/realtime-server/employ-socket.ts +14 -0
  161. package/src/realtime-server/index.ts +3 -22
  162. package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
  163. package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
  164. package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
  165. package/src/realtime-server/realtime-family-provider.ts +78 -29
  166. package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
  167. package/src/realtime-server/realtime-mutable-provider.ts +30 -22
  168. package/src/realtime-server/realtime-server-stores/index.ts +0 -2
  169. package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
  170. package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
  171. package/src/realtime-server/realtime-state-provider.ts +30 -29
  172. package/src/realtime-server/realtime-state-receiver.ts +62 -16
  173. package/src/realtime-server/server-config.ts +8 -0
  174. package/src/realtime-server/socket-interface.ts +14 -0
  175. package/src/realtime-testing/setup-realtime-test.tsx +70 -31
  176. package/src/web/index.ts +1 -1
  177. package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
  178. package/src/internal/store/mint-or-counterfeit.ts +0 -108
  179. package/src/realtime-client/server-action.ts +0 -23
  180. package/src/realtime-react/on-mount.ts +0 -5
  181. package/src/realtime-react/use-server-action.ts +0 -19
  182. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  183. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  184. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
  185. package/src/realtime-server/realtime-action-receiver.ts +0 -40
  186. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
@@ -1,5 +1,5 @@
1
- import type { ReadableState } from ".."
2
1
  import { newest } from "../lineage"
2
+ import type { ReadableState } from "../state-types"
3
3
  import type { Store } from "../store"
4
4
 
5
5
  export const recallState = <T, E>(
@@ -1,5 +1,5 @@
1
- import type { Atom, Selector } from ".."
2
1
  import { readOrComputeValue } from "../get-state/read-or-compute-value"
2
+ import type { Atom, Selector } from "../state-types"
3
3
  import type { Store } from "../store"
4
4
  import { recallState } from "./recall-state"
5
5
 
@@ -37,14 +37,3 @@ export const subscribeToRootDependency = (
37
37
  },
38
38
  )
39
39
  }
40
-
41
- // export const subscribeToRootAtoms = (
42
- // store: Store,
43
- // selector: Selector<any>,
44
- // ): (() => void)[] => {
45
- // const target = newest(store)
46
- // const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
47
- // (atom) => subscribeToRootDependency(target, selector, atom),
48
- // )
49
- // return dependencySubscriptions
50
- // }
@@ -1,5 +1,6 @@
1
1
  import type { ReadableToken, StateUpdate, UpdateHandler } from "atom.io"
2
2
 
3
+ import { hasRole } from "../atom"
3
4
  import { readOrComputeValue } from "../get-state"
4
5
  import { reduceReference } from "../get-state/reduce-reference"
5
6
  import { traceRootSelectorAtoms } from "../selector"
@@ -15,6 +16,14 @@ export function subscribeToState<T, E>(
15
16
  ): () => void {
16
17
  function safelyHandleUpdate(update: StateUpdate<any>): void {
17
18
  if (store.operation.open) {
19
+ if (
20
+ state?.type === `atom` &&
21
+ hasRole(state, `tracker:signal`) &&
22
+ `*` + store.operation.token.key === token.key &&
23
+ `inboundTracker` in handleUpdate
24
+ ) {
25
+ return
26
+ }
18
27
  const unsubscribe = store.on.operationClose.subscribe(
19
28
  `state subscription ${key}`,
20
29
  () => {
@@ -1,7 +1,8 @@
1
1
  import type { TransactionToken, TransactionUpdateHandler } from "atom.io"
2
2
 
3
- import type { Fn, Store } from ".."
4
- import { withdraw } from ".."
3
+ import type { Store } from "../store"
4
+ import { withdraw } from "../store"
5
+ import type { Fn } from "../utility-types"
5
6
 
6
7
  export const subscribeToTransaction = <F extends Fn>(
7
8
  store: Store,
@@ -16,9 +16,10 @@ import { getJsonToken } from "../mutable"
16
16
  import { MapOverlay } from "../overlays/map-overlay"
17
17
  import { resetInStore, setIntoStore } from "../set-state"
18
18
  import type { Fn } from "../utility-types"
19
- import type { TransactionProgress } from "."
20
- import { actUponStore, getEpochNumberOfAction } from "."
19
+ import { actUponStore } from "./act-upon-store"
20
+ import { getEpochNumberOfAction } from "./get-epoch-number"
21
21
  import type { ChildStore, RootStore } from "./is-root-store"
22
+ import type { TransactionProgress } from "./transaction-meta-progress"
22
23
 
23
24
  export const buildTransaction = (
24
25
  store: RootStore,
@@ -1,12 +1,3 @@
1
- import type {
2
- ActorToolkit,
3
- TransactionOutcomeEvent,
4
- TransactionToken,
5
- } from "atom.io"
6
-
7
- import type { Junction } from "../junction"
8
- import type { Fn } from "../utility-types"
9
-
10
1
  export * from "./abort-transaction"
11
2
  export * from "./act-upon-store"
12
3
  export * from "./apply-transaction"
@@ -16,17 +7,4 @@ export * from "./create-transaction"
16
7
  export * from "./get-epoch-number"
17
8
  export * from "./is-root-store"
18
9
  export * from "./set-epoch-number"
19
-
20
- export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
21
- export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
22
-
23
- export type TransactionProgress<F extends Fn> = {
24
- phase: `applying` | `building`
25
- update: TransactionOutcomeEvent<TransactionToken<F>>
26
- toolkit: ActorToolkit
27
- }
28
-
29
- export type TransactionEpoch = {
30
- epoch: Map<string, number>
31
- actionContinuities: Junction<`continuity`, string, `action`, string>
32
- }
10
+ export * from "./transaction-meta-progress"
@@ -1,7 +1,10 @@
1
1
  import type { MapOverlay } from "../overlays/map-overlay"
2
2
  import type { Store } from "../store"
3
3
  import type { Fn } from "../utility-types"
4
- import type { TransactionEpoch, TransactionProgress } from "."
4
+ import type {
5
+ TransactionEpoch,
6
+ TransactionProgress,
7
+ } from "./transaction-meta-progress"
5
8
 
6
9
  export interface RootStore extends Store {
7
10
  transactionMeta: TransactionEpoch
@@ -0,0 +1,22 @@
1
+ import type {
2
+ ActorToolkit,
3
+ TransactionOutcomeEvent,
4
+ TransactionToken,
5
+ } from "atom.io"
6
+
7
+ import type { Junction } from "../junction"
8
+ import type { Fn } from "../utility-types"
9
+
10
+ export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
11
+ export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
12
+
13
+ export type TransactionProgress<F extends Fn> = {
14
+ phase: `applying` | `building`
15
+ update: TransactionOutcomeEvent<TransactionToken<F>>
16
+ toolkit: ActorToolkit
17
+ }
18
+
19
+ export type TransactionEpoch = {
20
+ epoch: Map<string, number>
21
+ actionContinuities: Junction<`continuity`, string, `action`, string>
22
+ }
package/src/main/atom.ts CHANGED
@@ -9,7 +9,6 @@ import {
9
9
  import type { Canonical } from "atom.io/json"
10
10
 
11
11
  import type { StateUpdate } from "./events"
12
- import type { Setter } from "./set-state"
13
12
  import type {
14
13
  MutableAtomFamilyToken,
15
14
  MutableAtomToken,
@@ -78,7 +77,7 @@ export type Effectors<T> = {
78
77
  * Set the value of the atom
79
78
  * @param next - The new value of the atom, or a setter function
80
79
  */
81
- setSelf: <New extends T>(next: New | Setter<T, New>) => void
80
+ setSelf: <New extends T>(next: New | ((old: T) => New)) => void
82
81
  /** Subscribe to changes to the atom */
83
82
  onSet: (callback: (options: StateUpdate<T>) => void) => void
84
83
  }
@@ -50,7 +50,7 @@ export function findState<
50
50
  export function findState<T, K extends Canonical, Key extends K>(
51
51
  token: RegularAtomFamilyToken<T, K>,
52
52
  key: Key,
53
- ): RegularAtomToken<T, K>
53
+ ): RegularAtomToken<T, Key>
54
54
  /**
55
55
  * Finds a {@link WritableSelectorToken} in the store, without accessing its value.
56
56
  *
@@ -67,7 +67,7 @@ export function findState<T, K extends Canonical, Key extends K>(
67
67
  export function findState<T, K extends Canonical, Key extends K>(
68
68
  token: WritableSelectorFamilyToken<T, K>,
69
69
  key: Key,
70
- ): WritableSelectorToken<T, K>
70
+ ): WritableSelectorToken<T, Key>
71
71
  /**
72
72
  * Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
73
73
  *
@@ -84,7 +84,7 @@ export function findState<T, K extends Canonical, Key extends K>(
84
84
  export function findState<T, K extends Canonical, Key extends K>(
85
85
  token: ReadonlySelectorFamilyToken<T, K>,
86
86
  key: Key,
87
- ): ReadonlySelectorToken<T, K>
87
+ ): ReadonlySelectorToken<T, Key>
88
88
  /**
89
89
  * Finds a {@link WritableToken} in the store, without accessing its value.
90
90
  *
@@ -101,7 +101,7 @@ export function findState<T, K extends Canonical, Key extends K>(
101
101
  export function findState<T, K extends Canonical, Key extends K>(
102
102
  token: WritableFamilyToken<T, K>,
103
103
  key: Key,
104
- ): WritableToken<T, K>
104
+ ): WritableToken<T, Key>
105
105
  /**
106
106
  * Finds a {@link MutableAtomToken} in the store, without accessing its value.
107
107
  *
@@ -119,7 +119,7 @@ export function findState<T, K extends Canonical, Key extends K>(
119
119
  export function findState<T, K extends Canonical, Key extends K>(
120
120
  token: ReadableFamilyToken<T, K>,
121
121
  key: Key,
122
- ): ReadableToken<T, K>
122
+ ): ReadableToken<T, Key>
123
123
 
124
124
  export function findState(
125
125
  token: ReadableFamilyToken<any, any>,
@@ -22,14 +22,14 @@ export function getState<T, E = never>(
22
22
  * @return The current value of the state
23
23
  * @overload Streamlined
24
24
  */
25
- export function getState<T, K extends Canonical, Key extends K, E = never>(
25
+ export function getState<T, K extends Canonical, E = never>(
26
26
  token: ReadableFamilyToken<T, K, E>,
27
- key: Key,
27
+ key: NoInfer<K>,
28
28
  ): ViewOf<E | T>
29
29
 
30
- export function getState<T, K extends Canonical, Key extends K, E = never>(
30
+ export function getState<T, K extends Canonical, E = never>(
31
31
  ...params:
32
- | [token: ReadableFamilyToken<T, K, E>, key: Key]
32
+ | [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
33
33
  | [token: ReadableToken<T, any, E>]
34
34
  ): ViewOf<E | T> {
35
35
  return getFromStore(IMPLICIT.STORE, ...params)
package/src/main/realm.ts CHANGED
@@ -34,7 +34,7 @@ export class Realm<H extends Hierarchy> {
34
34
  this.store = store
35
35
  this.deallocateTX = createDeallocateTX(store)
36
36
  this.claimTX = createClaimTX(store)
37
- makeRootMoleculeInStore(`root`, store)
37
+ makeRootMoleculeInStore(store, `root`)
38
38
  }
39
39
  /**
40
40
  * Make space for a new subject of the realm
@@ -117,7 +117,7 @@ export class Anarchy {
117
117
  this.store = store
118
118
  this.deallocateTX = createDeallocateTX(store)
119
119
  this.claimTX = createClaimTX(store)
120
- makeRootMoleculeInStore(`root`, store)
120
+ makeRootMoleculeInStore(store, `root`)
121
121
  }
122
122
  /**
123
123
  * Declare a new entity
@@ -9,7 +9,7 @@ import type { WritableFamilyToken, WritableToken } from "./tokens"
9
9
  * @returns
10
10
  * The new value of the state.
11
11
  */
12
- export type Setter<T, New extends T> = (oldValue: T) => New
12
+ export type Setter<T> = (oldValue: T) => T
13
13
 
14
14
  /**
15
15
  * Set the value of a state into the implicit store.
@@ -18,9 +18,9 @@ export type Setter<T, New extends T> = (oldValue: T) => New
18
18
  * @overload Default
19
19
  * @default
20
20
  */
21
- export function setState<T, New extends T>(
21
+ export function setState<T, TT extends T>(
22
22
  token: WritableToken<T, any, any>,
23
- value: New | Setter<T, New>,
23
+ value: Setter<TT> | TT,
24
24
  ): void
25
25
 
26
26
  /**
@@ -30,20 +30,20 @@ export function setState<T, New extends T>(
30
30
  * @param value - The new value of the state.
31
31
  * @overload Streamlined
32
32
  */
33
- export function setState<T, K extends Canonical, New extends T, Key extends K>(
33
+ export function setState<T, TT extends T, K extends Canonical>(
34
34
  token: WritableFamilyToken<T, K, any>,
35
- key: Key,
36
- value: New | Setter<T, New>,
35
+ key: NoInfer<K>,
36
+ value: Setter<TT> | TT,
37
37
  ): void
38
38
 
39
- export function setState<T, K extends Canonical, New extends T, Key extends K>(
39
+ export function setState<T, TT extends T, K extends Canonical>(
40
40
  ...params:
41
41
  | [
42
42
  token: WritableFamilyToken<T, K, any>,
43
- key: Key,
44
- value: New | Setter<T, New>,
43
+ key: NoInfer<K>,
44
+ value: Setter<TT> | TT,
45
45
  ]
46
- | [token: WritableToken<T, any, any>, value: New | Setter<T, New>]
46
+ | [token: WritableToken<T, any, any>, value: Setter<TT> | TT]
47
47
  ): void {
48
48
  setIntoStore(IMPLICIT.STORE, ...params)
49
49
  }
@@ -11,17 +11,17 @@ import type { Canonical } from "atom.io/json"
11
11
  export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
12
12
  store: Store,
13
13
  ...rest: [WritableFamilyToken<T, K, E>, Key] | [WritableToken<T, any, E>]
14
- ): WritableToken<T, K, E>
14
+ ): WritableToken<T, Key, E>
15
15
 
16
16
  export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
17
17
  store: Store,
18
18
  ...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
19
- ): ReadableToken<T, K, E>
19
+ ): ReadableToken<T, Key, E>
20
20
 
21
21
  export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
22
22
  store: Store,
23
23
  ...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
24
- ): ReadableToken<T, K, E> {
24
+ ): ReadableToken<T, Key, E> {
25
25
  let token: ReadableToken<any, any, any>
26
26
  if (rest.length === 2) {
27
27
  const family = rest[0]
@@ -10,13 +10,15 @@ export function useI<T>(
10
10
  token: WritableToken<T, any, any>,
11
11
  ): <New extends T>(next: New | ((old: T) => New)) => void
12
12
 
13
- export function useI<T, K extends Canonical, Key extends K>(
13
+ export function useI<T, K extends Canonical>(
14
14
  token: WritableFamilyToken<T, K, any>,
15
- key: Key,
15
+ key: NoInfer<K>,
16
16
  ): <New extends T>(next: New | ((old: T) => New)) => void
17
17
 
18
- export function useI<T, K extends Canonical, Key extends K>(
19
- ...params: [WritableFamilyToken<T, K, any>, Key] | [WritableToken<T, any, any>]
18
+ export function useI<T, K extends Canonical>(
19
+ ...params:
20
+ | [WritableFamilyToken<T, K, any>, NoInfer<K>]
21
+ | [WritableToken<T, any, any>]
20
22
  ): <New extends T>(next: New | ((old: T) => New)) => void {
21
23
  const store = React.useContext(StoreContext)
22
24
  const token = parseStateOverloads(store, ...params)
@@ -9,9 +9,9 @@ export function useLoadable<T, E>(
9
9
  token: ReadableToken<Loadable<T>, any, E>,
10
10
  ): `LOADING` | { loading: boolean; value: E | T }
11
11
 
12
- export function useLoadable<T, K extends Canonical, Key extends K, E>(
12
+ export function useLoadable<T, K extends Canonical, E>(
13
13
  token: ReadableFamilyToken<Loadable<T>, K, E>,
14
- key: Key,
14
+ key: NoInfer<K>,
15
15
  ): `LOADING` | { loading: boolean; value: E | T }
16
16
 
17
17
  export function useLoadable<T, F extends T, E>(
@@ -19,15 +19,9 @@ export function useLoadable<T, F extends T, E>(
19
19
  fallback: F,
20
20
  ): { loading: boolean; value: T; error?: E }
21
21
 
22
- export function useLoadable<
23
- T,
24
- K extends Canonical,
25
- F extends T,
26
- Key extends K,
27
- E,
28
- >(
22
+ export function useLoadable<T, K extends Canonical, F extends T, E>(
29
23
  token: ReadableFamilyToken<Loadable<T>, K, E>,
30
- key: Key,
24
+ key: NoInfer<K>,
31
25
  fallback: F,
32
26
  ): { loading: boolean; value: T; error?: E }
33
27
 
@@ -8,13 +8,15 @@ import { StoreContext } from "./store-context"
8
8
 
9
9
  export function useO<T, E>(token: ReadableToken<T, any, E>): E | T
10
10
 
11
- export function useO<T, K extends Canonical, Key extends K, E>(
11
+ export function useO<T, K extends Canonical, E>(
12
12
  token: ReadableFamilyToken<T, K, E>,
13
- key: Key,
13
+ key: NoInfer<K>,
14
14
  ): E | T
15
15
 
16
- export function useO<T, K extends Canonical, Key extends K, E>(
17
- ...params: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
16
+ export function useO<T, K extends Canonical, E>(
17
+ ...params:
18
+ | [ReadableFamilyToken<T, K, E>, NoInfer<K>]
19
+ | [ReadableToken<T, any, E>]
18
20
  ): E | T {
19
21
  const store = React.useContext(StoreContext)
20
22
  const token = parseStateOverloads(store, ...params)
@@ -16,7 +16,7 @@ import type {
16
16
  WritableTokenIndex,
17
17
  } from "atom.io/introspection"
18
18
  import { attachIntrospectionStates, isPlainObject } from "atom.io/introspection"
19
- import { persistSync } from "atom.io/web"
19
+ import { storageSync } from "atom.io/web"
20
20
  import type { Context } from "react"
21
21
  import { createContext } from "react"
22
22
 
@@ -48,7 +48,7 @@ export function attachDevtoolsStates(
48
48
  typeof window === `undefined`
49
49
  ? []
50
50
  : [
51
- persistSync(window.localStorage, JSON, `🔍 Devtools Are Hidden`),
51
+ storageSync(window.localStorage, JSON, `🔍 Devtools Are Hidden`),
52
52
  ({ setSelf }) => {
53
53
  window.addEventListener(`keydown`, (e) => {
54
54
  if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === `a`) {
@@ -70,7 +70,7 @@ export function attachDevtoolsStates(
70
70
  effects:
71
71
  typeof window === `undefined`
72
72
  ? []
73
- : [persistSync(window.localStorage, JSON, `🔍 Devtools Are Open`)],
73
+ : [storageSync(window.localStorage, JSON, `🔍 Devtools Are Open`)],
74
74
  },
75
75
  undefined,
76
76
  )
@@ -87,7 +87,7 @@ export function attachDevtoolsStates(
87
87
  effects:
88
88
  typeof window === `undefined`
89
89
  ? []
90
- : [persistSync(window.localStorage, JSON, `🔍 Devtools View`)],
90
+ : [storageSync(window.localStorage, JSON, `🔍 Devtools View`)],
91
91
  },
92
92
  undefined,
93
93
  )
@@ -104,7 +104,7 @@ export function attachDevtoolsStates(
104
104
  effects:
105
105
  typeof window === `undefined`
106
106
  ? []
107
- : [persistSync(window.localStorage, JSON, `🔍 Devtools View Options`)],
107
+ : [storageSync(window.localStorage, JSON, `🔍 Devtools View Options`)],
108
108
  },
109
109
  undefined,
110
110
  )
@@ -119,7 +119,7 @@ export function attachDevtoolsStates(
119
119
  effects: (key) =>
120
120
  typeof window === `undefined`
121
121
  ? []
122
- : [persistSync(window.localStorage, JSON, `view-is-open:${key.join()}`)],
122
+ : [storageSync(window.localStorage, JSON, `view-is-open:${key.join()}`)],
123
123
  })
124
124
 
125
125
  const openCloseAllTX: TransactionToken<
@@ -1,2 +1,3 @@
1
+ export * from "./mutex-store"
1
2
  export * from "./realtime-continuity"
2
3
  export * from "./shared-room-store"
@@ -0,0 +1,11 @@
1
+ import type { AtomFamilyToken } from "atom.io"
2
+ import { atomFamily } from "atom.io"
3
+ import type { Canonical } from "atom.io/json"
4
+
5
+ export const mutexAtoms: AtomFamilyToken<boolean, Canonical> = atomFamily<
6
+ boolean,
7
+ Canonical
8
+ >({
9
+ key: `mutex`,
10
+ default: false,
11
+ })
@@ -16,7 +16,7 @@ import type { UserKey } from "atom.io/realtime-server"
16
16
 
17
17
  /* eslint-disable no-console */
18
18
 
19
- export class InvariantMap<K, V> extends Map<K, V> {
19
+ export class InvariantMap<K, V> extends Map<K, V> implements ReadonlyMap<K, V> {
20
20
  public set(key: K, value: V): this {
21
21
  if (this.has(key)) {
22
22
  console.warn(`Tried to set a key that already exists in an InvariantMap`, {
@@ -27,10 +27,6 @@ export class InvariantMap<K, V> extends Map<K, V> {
27
27
  }
28
28
  return super.set(key, value)
29
29
  }
30
-
31
- public clear(): void {
32
- throw new Error(`Cannot clear an InvariantMap`)
33
- }
34
30
  }
35
31
 
36
32
  export type PerspectiveToken<F extends AtomFamilyToken<any>> = {
@@ -7,5 +7,4 @@ export * from "./pull-selector"
7
7
  export * from "./pull-selector-family-member"
8
8
  export * from "./push-state"
9
9
  export * from "./realtime-client-stores"
10
- export * from "./server-action"
11
10
  export * from "./sync-continuity"
@@ -1,28 +1,25 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import { setIntoStore, type Store } from "atom.io/internal"
3
- import type { Json } from "atom.io/json"
4
- import { parseJson } from "atom.io/json"
2
+ import { findInStore, setIntoStore, type Store } from "atom.io/internal"
3
+ import type { Canonical, Json } from "atom.io/json"
5
4
  import type { Socket } from "socket.io-client"
6
5
 
7
- /* eslint-disable no-console */
8
-
9
- export function pullAtomFamilyMember<J extends Json.Serializable>(
6
+ export function pullAtomFamilyMember<
7
+ J extends Json.Serializable,
8
+ K extends Canonical,
9
+ >(
10
10
  store: Store,
11
11
  socket: Socket,
12
- token: AtomIO.RegularAtomToken<J>,
12
+ family: AtomIO.AtomFamilyToken<J, K, any>,
13
+ key: NoInfer<K>,
13
14
  ): () => void {
14
- if (!(`family` in token)) {
15
- console.error(`Token is not a family member:`, token)
16
- return () => {}
17
- }
18
- const { key: familyKey, subKey: serializedSubKey } = token.family
19
- const subKey = parseJson(serializedSubKey)
20
- socket?.on(`serve:${token.key}`, (data: J) => {
15
+ const token = findInStore(store, family, key)
16
+ const setServedValue = (data: J) => {
21
17
  setIntoStore(store, token, data)
22
- })
23
- socket?.emit(`sub:${familyKey}`, subKey)
18
+ }
19
+ socket?.on(`serve:${token.key}`, setServedValue)
20
+ socket?.emit(`sub:${family.key}`, key)
24
21
  return () => {
25
- socket?.off(`serve:${token.key}`)
22
+ socket?.off(`serve:${token.key}`, setServedValue)
26
23
  socket?.emit(`unsub:${token.key}`)
27
24
  }
28
25
  }
@@ -6,7 +6,7 @@ import type { Socket } from "socket.io-client"
6
6
  export function pullAtom<J extends Json.Serializable>(
7
7
  store: Store,
8
8
  socket: Socket,
9
- token: AtomIO.RegularAtomToken<J>,
9
+ token: AtomIO.RegularAtomToken<J, any, any>,
10
10
  ): () => void {
11
11
  const setServedValue = (data: J) => {
12
12
  setIntoStore(store, token, data)
@@ -1,20 +1,24 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
3
- import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
- import { parseJson } from "atom.io/json"
3
+ import {
4
+ findInStore,
5
+ getJsonToken,
6
+ getUpdateToken,
7
+ setIntoStore,
8
+ } from "atom.io/internal"
9
+ import type { Canonical } from "atom.io/json"
5
10
  import type { Socket } from "socket.io-client"
6
11
 
7
- /* eslint-disable no-console */
8
-
9
12
  export function pullMutableAtomFamilyMember<
10
13
  T extends Transceiver<any, any, any>,
11
- >(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
12
- if (!(`family` in token)) {
13
- console.error(`Token is not a family member:`, token)
14
- return () => {}
15
- }
16
- const { key: familyKey, subKey: serializedSubKey } = token.family
17
- const subKey = parseJson(serializedSubKey)
14
+ K extends Canonical,
15
+ >(
16
+ store: Store,
17
+ socket: Socket,
18
+ family: AtomIO.MutableAtomFamilyToken<T, K>,
19
+ key: NoInfer<K>,
20
+ ): () => void {
21
+ const token = findInStore(store, family, key)
18
22
  socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
19
23
  const jsonToken = getJsonToken(store, token)
20
24
  setIntoStore(store, jsonToken, data)
@@ -23,7 +27,7 @@ export function pullMutableAtomFamilyMember<
23
27
  const trackerToken = getUpdateToken(token)
24
28
  setIntoStore(store, trackerToken, data)
25
29
  })
26
- socket.emit(`sub:${familyKey}`, subKey)
30
+ socket.emit(`sub:${family.key}`, key)
27
31
  return () => {
28
32
  socket.off(`serve:${token.key}`)
29
33
  socket.emit(`unsub:${token.key}`)
@@ -1,44 +1,17 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Store } from "atom.io/internal"
3
+ import { findInStore } from "atom.io/internal"
4
+ import type { Canonical } from "atom.io/json"
3
5
  import type { Socket } from "socket.io-client"
4
6
 
5
- import { pullAtomFamilyMember } from "./pull-atom-family-member"
6
- import { pullMutableAtomFamilyMember } from "./pull-mutable-atom-family-member"
7
+ import { pullSelectorRoots } from "./pull-selector-roots"
7
8
 
8
- /* eslint-disable no-console */
9
-
10
- export function pullSelectorFamilyMember<T>(
9
+ export function pullSelectorFamilyMember<T, K extends Canonical>(
11
10
  store: Store,
12
11
  socket: Socket,
13
- token: AtomIO.SelectorToken<T>,
12
+ familyToken: AtomIO.SelectorFamilyToken<T, K>,
13
+ key: NoInfer<K>,
14
14
  ): () => void {
15
- if (!(`family` in token)) {
16
- console.error(`Token is not a family member:`, token)
17
- return () => {}
18
- }
19
- const atomKeys = store.selectorAtoms.getRelatedKeys(token.key)
20
- const unsubscribes: Array<() => void> = []
21
- if (atomKeys) {
22
- for (const atomKey of atomKeys) {
23
- const atom = store.atoms.get(atomKey)
24
- if (!atom) {
25
- continue
26
- }
27
- switch (atom.type) {
28
- case `atom`: {
29
- unsubscribes.push(pullAtomFamilyMember(store, socket, atom))
30
- break
31
- }
32
- case `mutable_atom`: {
33
- unsubscribes.push(pullMutableAtomFamilyMember(store, socket, atom))
34
- break
35
- }
36
- }
37
- }
38
- }
39
- return () => {
40
- for (const unsubscribe of unsubscribes) {
41
- unsubscribe()
42
- }
43
- }
15
+ const token = findInStore(store, familyToken, key)
16
+ return pullSelectorRoots(store, socket, token)
44
17
  }