atom.io 0.34.2 → 0.36.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 (113) hide show
  1. package/dist/eslint-plugin/index.d.ts +2 -18
  2. package/dist/eslint-plugin/index.d.ts.map +1 -1
  3. package/dist/eslint-plugin/index.js +4 -141
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +74 -77
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +197 -202
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/json/index.d.ts +9 -17
  10. package/dist/json/index.d.ts.map +1 -1
  11. package/dist/json/index.js +3 -33
  12. package/dist/json/index.js.map +1 -1
  13. package/dist/main/index.d.ts +689 -795
  14. package/dist/main/index.d.ts.map +1 -1
  15. package/dist/main/index.js +55 -23
  16. package/dist/main/index.js.map +1 -1
  17. package/dist/react/index.d.ts +4 -4
  18. package/dist/react/index.d.ts.map +1 -1
  19. package/dist/react/index.js.map +1 -1
  20. package/dist/react-devtools/index.d.ts.map +1 -1
  21. package/dist/react-devtools/index.js +10 -10
  22. package/dist/react-devtools/index.js.map +1 -1
  23. package/dist/realtime/index.d.ts +4 -4
  24. package/dist/realtime/index.d.ts.map +1 -1
  25. package/dist/realtime/index.js +5 -11
  26. package/dist/realtime/index.js.map +1 -1
  27. package/dist/realtime-client/index.d.ts +2 -2
  28. package/dist/realtime-client/index.d.ts.map +1 -1
  29. package/dist/realtime-client/index.js +10 -10
  30. package/dist/realtime-client/index.js.map +1 -1
  31. package/dist/realtime-react/index.d.ts +2 -2
  32. package/dist/realtime-react/index.d.ts.map +1 -1
  33. package/dist/realtime-react/index.js.map +1 -1
  34. package/dist/realtime-server/index.d.ts +18 -18
  35. package/dist/realtime-server/index.d.ts.map +1 -1
  36. package/dist/realtime-server/index.js +13 -19
  37. package/dist/realtime-server/index.js.map +1 -1
  38. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  39. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  40. package/dist/transceivers/set-rtx/index.js.map +1 -1
  41. package/package.json +7 -7
  42. package/src/eslint-plugin/index.ts +0 -1
  43. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  44. package/src/eslint-plugin/rules/index.ts +0 -1
  45. package/src/internal/atom/create-regular-atom.ts +1 -0
  46. package/src/internal/atom/dispose-atom.ts +1 -0
  47. package/src/internal/atom/index.ts +0 -1
  48. package/src/internal/families/find-in-store.ts +4 -5
  49. package/src/internal/families/get-family-of-token.ts +4 -5
  50. package/src/internal/families/index.ts +0 -1
  51. package/src/internal/families/init-family-member.ts +3 -4
  52. package/src/internal/families/seek-in-store.ts +4 -5
  53. package/src/internal/get-state/read-or-compute-value.ts +14 -2
  54. package/src/internal/index.ts +116 -96
  55. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  56. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  57. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  58. package/src/internal/join/join-internal.ts +6 -18
  59. package/src/internal/molecule.ts +1 -0
  60. package/src/internal/mutable/create-mutable-atom-family.ts +37 -21
  61. package/src/internal/mutable/create-mutable-atom.ts +17 -13
  62. package/src/internal/mutable/get-json-family.ts +7 -6
  63. package/src/internal/mutable/get-json-token.ts +6 -13
  64. package/src/internal/mutable/get-update-family.ts +7 -8
  65. package/src/internal/mutable/get-update-token.ts +5 -9
  66. package/src/internal/mutable/tracker-family.ts +10 -13
  67. package/src/internal/mutable/tracker.ts +66 -90
  68. package/src/internal/mutable/transceiver.ts +35 -8
  69. package/src/internal/selector/dispose-selector.ts +9 -9
  70. package/src/internal/selector/register-selector.ts +2 -2
  71. package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
  72. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  73. package/src/internal/set-state/set-atom.ts +1 -1
  74. package/src/internal/store/counterfeit.ts +3 -4
  75. package/src/internal/store/deposit.ts +7 -9
  76. package/src/internal/store/store.ts +2 -2
  77. package/src/internal/store/withdraw.ts +7 -11
  78. package/src/json/entries.ts +7 -7
  79. package/src/json/index.ts +0 -2
  80. package/src/main/atom.ts +68 -127
  81. package/src/main/dispose-state.ts +4 -6
  82. package/src/main/find-state.ts +6 -13
  83. package/src/main/get-state.ts +0 -2
  84. package/src/main/index.ts +1 -176
  85. package/src/main/join.ts +2 -9
  86. package/src/main/logger.ts +7 -7
  87. package/src/main/reset-state.ts +0 -2
  88. package/src/main/selector.ts +5 -72
  89. package/src/main/set-state.ts +1 -4
  90. package/src/main/silo.ts +14 -5
  91. package/src/main/subscribe.ts +0 -7
  92. package/src/main/timeline.ts +1 -18
  93. package/src/main/tokens.ts +245 -0
  94. package/src/main/transaction.ts +28 -60
  95. package/src/main/validators.ts +2 -2
  96. package/src/react/use-json.ts +15 -25
  97. package/src/react-devtools/store.ts +61 -45
  98. package/src/realtime/shared-room-store.ts +12 -25
  99. package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
  100. package/src/realtime-client/pull-mutable-atom.ts +5 -9
  101. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  102. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  103. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  104. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  105. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  106. package/src/realtime-server/realtime-server-stores/server-user-store.ts +9 -18
  107. package/src/transceivers/set-rtx/set-rtx.ts +1 -1
  108. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  109. package/src/eslint-plugin/walk.ts +0 -81
  110. package/src/internal/atom/create-standalone-atom.ts +0 -39
  111. package/src/internal/families/create-atom-family.ts +0 -38
  112. package/src/json/select-json-family.ts +0 -55
  113. package/src/json/select-json.ts +0 -19
@@ -4,11 +4,18 @@ import type { Store } from "../store"
4
4
  import { setAtom } from "./set-atom"
5
5
 
6
6
  function resetAtom(store: Store, state: Atom<any>) {
7
- let def = state.default
8
- if (def instanceof Function) {
9
- def = def()
7
+ switch (state.type) {
8
+ case `mutable_atom`:
9
+ setAtom(store, state, new state.class())
10
+ return
11
+ case `atom`: {
12
+ let def = state.default
13
+ if (def instanceof Function) {
14
+ def = def()
15
+ }
16
+ setAtom(store, state, def)
17
+ }
10
18
  }
11
- setAtom(store, state, def)
12
19
  }
13
20
 
14
21
  export function resetAtomOrSelector(
@@ -60,7 +60,7 @@ export const setAtom = <T>(
60
60
  } else if (atom.key.startsWith(`*`)) {
61
61
  const mutableKey = atom.key.slice(1)
62
62
  const mutableAtom = target.atoms.get(mutableKey) as Atom<any>
63
- let transceiver: Transceiver<any> = target.valueMap.get(mutableKey)
63
+ let transceiver: Transceiver<any, any> = target.valueMap.get(mutableKey)
64
64
  if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
65
65
  const { parent } = target
66
66
  const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)
@@ -16,7 +16,7 @@ import type {
16
16
  WritablePureSelectorToken,
17
17
  WritableToken,
18
18
  } from "atom.io"
19
- import type { Canonical, Json } from "atom.io/json"
19
+ import type { Canonical } from "atom.io/json"
20
20
  import { stringifyJson } from "atom.io/json"
21
21
 
22
22
  import type { Transceiver } from "../mutable"
@@ -32,11 +32,10 @@ export const FAMILY_MEMBER_TOKEN_TYPES = {
32
32
  } as const
33
33
 
34
34
  export function counterfeit<
35
- T extends Transceiver<any>,
36
- J extends Json.Serializable,
35
+ T extends Transceiver<any, any>,
37
36
  K extends Canonical,
38
37
  Key extends K,
39
- >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>
38
+ >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
40
39
 
41
40
  export function counterfeit<T, K extends Canonical, Key extends K>(
42
41
  token: RegularAtomFamilyToken<T, K>,
@@ -20,7 +20,7 @@ import type {
20
20
  WritablePureSelectorToken,
21
21
  WritableToken,
22
22
  } from "atom.io"
23
- import type { Canonical, Json } from "atom.io/json"
23
+ import type { Canonical } from "atom.io/json"
24
24
 
25
25
  import type {
26
26
  Atom,
@@ -47,9 +47,9 @@ import type {
47
47
  import type { Transaction } from "../transaction"
48
48
 
49
49
  export function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>
50
- export function deposit<T extends Transceiver<any>>(
51
- state: MutableAtom<T, any>,
52
- ): MutableAtomToken<T, any>
50
+ export function deposit<T extends Transceiver<any, any>>(
51
+ state: MutableAtom<T>,
52
+ ): MutableAtomToken<T>
53
53
  export function deposit<T>(state: Atom<T>): AtomToken<T>
54
54
  export function deposit<T>(
55
55
  state: WritablePureSelector<T>,
@@ -64,11 +64,9 @@ export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
64
64
  export function deposit<T, K extends Canonical>(
65
65
  state: RegularAtomFamily<T, K>,
66
66
  ): RegularAtomFamilyToken<T, K>
67
- export function deposit<
68
- T extends Transceiver<any>,
69
- J extends Json.Serializable,
70
- K extends Canonical,
71
- >(state: MutableAtomFamily<T, J, K>): MutableAtomFamilyToken<T, J, K>
67
+ export function deposit<T extends Transceiver<any, any>, K extends Canonical>(
68
+ state: MutableAtomFamily<T, K>,
69
+ ): MutableAtomFamilyToken<T, K>
72
70
  export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
73
71
  export function deposit<T>(
74
72
  state: WritablePureSelectorFamily<T, any>,
@@ -70,11 +70,11 @@ export class Store implements Lineage {
70
70
  makeContentKey: (...keys) => keys.sort().join(`:`),
71
71
  },
72
72
  )
73
- public trackers: Map<string, Tracker<Transceiver<any>>> = new Map()
73
+ public trackers: Map<string, Tracker<Transceiver<any, any>>> = new Map()
74
74
  public families: Map<
75
75
  string,
76
76
  | HeldSelectorFamily<any, any>
77
- | MutableAtomFamily<any, any, any>
77
+ | MutableAtomFamily<any, any>
78
78
  | PureSelectorFamily<any, any>
79
79
  | RegularAtomFamily<any, any>
80
80
  > = new Map()
@@ -32,7 +32,7 @@ import type {
32
32
  WritableSelectorToken,
33
33
  WritableToken,
34
34
  } from "atom.io"
35
- import type { Canonical, Json } from "atom.io/json"
35
+ import type { Canonical } from "atom.io/json"
36
36
 
37
37
  import type {
38
38
  Atom,
@@ -76,10 +76,10 @@ export function withdraw<T>(
76
76
  store: Store,
77
77
  token: RegularAtomToken<T>,
78
78
  ): RegularAtom<T>
79
- export function withdraw<T extends Transceiver<any>>(
79
+ export function withdraw<T extends Transceiver<any, any>>(
80
80
  store: Store,
81
81
  token: MutableAtomToken<T, any>,
82
- ): MutableAtom<T, any>
82
+ ): MutableAtom<T>
83
83
  export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
84
84
  export function withdraw<T>(
85
85
  store: Store,
@@ -127,14 +127,10 @@ export function withdraw<T, K extends Canonical>(
127
127
  store: Store,
128
128
  token: RegularAtomFamilyToken<T, K>,
129
129
  ): RegularAtomFamily<T, K>
130
- export function withdraw<
131
- T extends Transceiver<any>,
132
- J extends Json.Serializable,
133
- K extends Canonical,
134
- >(
135
- store: Store,
136
- token: MutableAtomFamilyToken<T, J, K>,
137
- ): MutableAtomFamily<T, J, K>
130
+ export function withdraw<T extends Transceiver<any, any>, K extends Canonical>(
131
+ store: Store,
132
+ token: MutableAtomFamilyToken<T, K>,
133
+ ): MutableAtomFamily<T, K>
138
134
  export function withdraw<T, K extends Canonical>(
139
135
  store: Store,
140
136
  token: AtomFamilyToken<T, K>,
@@ -1,32 +1,32 @@
1
1
  import type { Count, Flat } from "atom.io/internal"
2
2
 
3
- /** @public Tuples of `[key, value]` pairs, as returned from `Object.entries` */
3
+ /** Tuples of `[key, value]` pairs, as returned from `Object.entries` */
4
4
  export type Entries<K extends PropertyKey = PropertyKey, V = any> = [K, V][]
5
5
 
6
- /** @public The collective or "union" type of the keys in a set of entries */
6
+ /** The collective or "union" type of the keys in a set of entries */
7
7
  export type KeyOfEntries<E extends Entries> = E extends [infer K, any][]
8
8
  ? K
9
9
  : never
10
10
 
11
- /** @public The type of the value of entry `K` in a set of entries `E` */
11
+ /** The type of the value of entry `K` in a set of entries `E` */
12
12
  export type ValueOfEntry<E extends Entries, K extends KeyOfEntries<E>> = {
13
13
  [P in Count<E[`length`]>]: E[P] extends [K, infer V] ? V : never
14
14
  }[Count<E[`length`]>]
15
15
 
16
- /** @public The type of a set of entries `E` in object form */
16
+ /** The type of a set of entries `E` in object form */
17
17
  export type FromEntries<E extends Entries> = Flat<{
18
18
  [K in KeyOfEntries<E>]: ValueOfEntry<E, K>
19
19
  }>
20
20
 
21
- /** @public Typed form of `Object.fromEntries` */
21
+ /** Typed form of `Object.fromEntries` */
22
22
  export function fromEntries<E extends Entries>(entries: E): FromEntries<E> {
23
23
  return Object.fromEntries(entries) as FromEntries<E>
24
24
  }
25
25
 
26
- /** @public The type of an object T in {@link Entries} form */
26
+ /** The type of an object T in {@link Entries} form */
27
27
  export type ToEntries<T extends object> = Entries<keyof T, T[keyof T]>
28
28
 
29
- /** @public Typed form of `Object.entries` */
29
+ /** Typed form of `Object.entries` */
30
30
  export function toEntries<T extends object>(obj: T): ToEntries<T> {
31
31
  return Object.entries(obj) as Entries<keyof T, T[keyof T]>
32
32
  }
package/src/json/index.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from "./entries"
2
- export * from "./select-json"
3
- export * from "./select-json-family"
4
2
 
5
3
  export type primitive = boolean | number | string | null
6
4
 
package/src/main/atom.ts CHANGED
@@ -1,15 +1,48 @@
1
- import type { Transceiver } from "atom.io/internal"
1
+ import type { ConstructorOf, Transceiver } from "atom.io/internal"
2
2
  import {
3
- createAtomFamily,
4
- createStandaloneAtom,
3
+ createMutableAtom,
4
+ createMutableAtomFamily,
5
+ createRegularAtom,
6
+ createRegularAtomFamily,
5
7
  IMPLICIT,
6
8
  } from "atom.io/internal"
7
- import type { Canonical, Json, JsonInterface } from "atom.io/json"
9
+ import type { Canonical } from "atom.io/json"
8
10
 
9
- import type { AtomToken, MutableAtomToken, RegularAtomToken, Setter } from "."
11
+ import type { Setter } from "./set-state"
12
+ import type {
13
+ MutableAtomFamilyToken,
14
+ MutableAtomToken,
15
+ RegularAtomFamilyToken,
16
+ RegularAtomToken,
17
+ } from "./tokens"
10
18
 
19
+ export type RegularAtomOptions<T> = {
20
+ /** The unique identifier of the atom */
21
+ key: string
22
+ /** The starting value of the atom */
23
+ default: T | (() => T)
24
+ /** Hooks used to run side effects when the atom is set */
25
+ effects?: AtomEffect<T>[]
26
+ }
27
+ /**
28
+ * Create a regular atom, a global reactive variable in the implicit store
29
+ * @param options - {@link RegularAtomOptions}.
30
+ * @returns
31
+ * A reference to the atom created: a {@link RegularAtomToken}
32
+ */
33
+ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
34
+ return createRegularAtom(IMPLICIT.STORE, options, undefined)
35
+ }
36
+
37
+ export type MutableAtomOptions<T extends Transceiver<any, any>> = {
38
+ /** The unique identifier of the atom */
39
+ key: string
40
+ /** A constructor for the atom's value */
41
+ class: ConstructorOf<T>
42
+ /** Hooks used to run side effects when the atom is set */
43
+ effects?: AtomEffect<T>[]
44
+ }
11
45
  /**
12
- * @public
13
46
  * Create a mutable atom, a global reactive variable in the implicit store
14
47
  *
15
48
  * The value of a mutable atom must be some kind of {@link Transceiver}.
@@ -17,27 +50,20 @@ import type { AtomToken, MutableAtomToken, RegularAtomToken, Setter } from "."
17
50
  * @param options - {@link MutableAtomOptions}.
18
51
  * @returns
19
52
  * A reference to the atom created: a {@link MutableAtomToken}
20
- * @overload Mutable
21
53
  */
22
- export function atom<T extends Transceiver<any>, J extends Json.Serializable>(
23
- options: MutableAtomOptions<T, J>,
24
- ): MutableAtomToken<T, J>
54
+ export function mutableAtom<T extends Transceiver<any, any>>(
55
+ options: MutableAtomOptions<T>,
56
+ ): MutableAtomToken<T> {
57
+ return createMutableAtom(IMPLICIT.STORE, options, undefined)
58
+ }
59
+
25
60
  /**
26
- * @public
27
- * Create a regular atom, a global reactive variable in the implicit store
28
- * @param options - {@link RegularAtomOptions}.
61
+ * A function that runs side effects when the atom is set
62
+ * @param tools - {@link Effectors} that can be used to run side effects
29
63
  * @returns
30
- * A reference to the atom created: a {@link RegularAtomToken}
31
- * @overload Regular
64
+ * Optionally, a cleanup function that will be called when the atom is disposed
32
65
  */
33
- export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
34
- export function atom(
35
- options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
36
- ): AtomToken<any> {
37
- return createStandaloneAtom(IMPLICIT.STORE, options)
38
- }
39
-
40
- /** @public */
66
+ export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
41
67
  export type Effectors<T> = {
42
68
  /**
43
69
  * Reset the value of the atom to its default
@@ -52,44 +78,6 @@ export type Effectors<T> = {
52
78
  onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
53
79
  }
54
80
 
55
- /**
56
- * @public
57
- * A function that runs side effects when the atom is set
58
- * @param tools - {@link Effectors} that can be used to run side effects
59
- * @returns
60
- * Optionally, a cleanup function that will be called when the atom is disposed
61
- */
62
- export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
63
-
64
- /** @public */
65
- export type RegularAtomOptions<T> = {
66
- /** The unique identifier of the atom */
67
- key: string
68
- /** The starting value of the atom */
69
- default: T | (() => T)
70
- /** Hooks used to run side effects when the atom is set */
71
- effects?: AtomEffect<T>[]
72
- }
73
-
74
- /** @public */
75
- // biome-ignore format: intersection
76
- export type MutableAtomOptions<
77
- T extends Transceiver<any>,
78
- J extends Json.Serializable,
79
- > =
80
- & JsonInterface<T, J>
81
- & {
82
- /** Used to signal that the atom is mutable */
83
- mutable: true
84
- /** The unique identifier of the atom */
85
- key: string
86
- /** A function to create an initial value for the atom */
87
- default: () => T
88
- /** Hooks used to run side effects when the atom is set */
89
- effects?: AtomEffect<T>[]
90
- }
91
-
92
- /** @public */
93
81
  export type RegularAtomFamilyOptions<T, K extends Canonical> = {
94
82
  /** The unique identifier of the atom family */
95
83
  key: string
@@ -98,59 +86,30 @@ export type RegularAtomFamilyOptions<T, K extends Canonical> = {
98
86
  /** Hooks used to run side effects when an atom in the family is set */
99
87
  effects?: (key: K) => AtomEffect<T>[]
100
88
  }
101
-
102
- export type RegularAtomFamilyToken<T, K extends Canonical> = {
103
- /** The unique identifier of the atom family */
104
- key: string
105
- /** Discriminator */
106
- type: `atom_family`
107
- /** Never present. This is a marker that preserves the type of atoms in this family */
108
- __T?: T
109
- /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
110
- __K?: K
89
+ /**
90
+ * Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
91
+ * @param options - {@link RegularAtomFamilyOptions}
92
+ * @returns
93
+ * A reference to the atom family created: a {@link RegularAtomFamilyToken}
94
+ */
95
+ export function atomFamily<T, K extends Canonical>(
96
+ options: RegularAtomFamilyOptions<T, K>,
97
+ ): RegularAtomFamilyToken<T, K> {
98
+ return createRegularAtomFamily(IMPLICIT.STORE, options)
111
99
  }
112
100
 
113
- /** @public */
114
- // biome-ignore format: intersection
115
101
  export type MutableAtomFamilyOptions<
116
- T extends Transceiver<any>,
117
- J extends Json.Serializable,
118
- K extends Canonical,
119
- > =
120
- & JsonInterface<T, J>
121
- & {
122
- /** Used to signal that the atoms created from this family are mutable */
123
- mutable: true
124
- /** The unique identifier of the atom family */
125
- key: string
126
- /** A function to create an initial value for each atom in the family */
127
- default: (key: K) => T
128
- /** Hooks used to run side effects when an atom in the family is set */
129
- effects?: (key: K) => AtomEffect<T>[]
130
- }
131
-
132
- export type MutableAtomFamilyToken<
133
- T extends Transceiver<any>,
134
- J extends Json.Serializable,
102
+ T extends Transceiver<any, any>,
135
103
  K extends Canonical,
136
104
  > = {
137
105
  /** The unique identifier of the atom family */
138
106
  key: string
139
- /** Discriminator */
140
- type: `mutable_atom_family`
141
- /** Never present. This is a marker that preserves the type of atoms in this family */
142
- __T?: T
143
- /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
144
- __J?: J
145
- /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
146
- __K?: K
107
+ /** The class of the transceiver to be created */
108
+ class: ConstructorOf<T>
109
+ /** Hooks used to run side effects when an atom in the family is set */
110
+ effects?: (key: K) => AtomEffect<T>[]
147
111
  }
148
- export type AtomFamilyToken<T, K extends Canonical = Canonical> =
149
- | MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
150
- | RegularAtomFamilyToken<T, K>
151
-
152
112
  /**
153
- * @public
154
113
  * Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
155
114
  *
156
115
  * The value of a mutable atom must be some kind of {@link Transceiver}.
@@ -158,28 +117,10 @@ export type AtomFamilyToken<T, K extends Canonical = Canonical> =
158
117
  * @param options - {@link MutableAtomFamilyOptions}
159
118
  * @returns
160
119
  * A reference to the atom family created: a {@link MutableAtomFamilyToken}
161
- * @overload Mutable
162
120
  */
163
- export function atomFamily<
164
- T extends Transceiver<any>,
165
- J extends Json.Serializable,
121
+ export function mutableAtomFamily<
122
+ T extends Transceiver<any, any>,
166
123
  K extends Canonical,
167
- >(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K>
168
- /**
169
- * @public
170
- * Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
171
- * @param options - {@link RegularAtomFamilyOptions}
172
- * @returns
173
- * A reference to the atom family created: a {@link RegularAtomFamilyToken}
174
- * @overload Regular
175
- */
176
- export function atomFamily<T, K extends Canonical>(
177
- options: RegularAtomFamilyOptions<T, K>,
178
- ): RegularAtomFamilyToken<T, K>
179
- export function atomFamily<T, K extends Canonical>(
180
- options:
181
- | MutableAtomFamilyOptions<any, any, any>
182
- | RegularAtomFamilyOptions<T, K>,
183
- ): MutableAtomFamilyToken<any, any, any> | RegularAtomFamilyToken<T, K> {
184
- return createAtomFamily(IMPLICIT.STORE, options)
124
+ >(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
125
+ return createMutableAtomFamily(IMPLICIT.STORE, options)
185
126
  }
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
5
5
 
6
6
  /**
7
- * @public
8
7
  * Disposes of a state in the implicit store.
9
8
  *
10
9
  * Only family members can be disposed of.
@@ -14,7 +13,6 @@ import type { ReadableFamilyToken, ReadableToken } from "."
14
13
  */
15
14
  export function disposeState(token: ReadableToken<any>): void
16
15
  /**
17
- * @public
18
16
  * Disposes of a state in the implicit store.
19
17
  *
20
18
  * Only family members can be disposed of.
@@ -27,13 +25,13 @@ export function disposeState<K extends Canonical>(
27
25
  key: K,
28
26
  ): void
29
27
  export function disposeState(
30
- ...[token, key]:
28
+ ...params:
31
29
  | [token: ReadableFamilyToken<any, any>, key: Canonical]
32
30
  | [token: ReadableToken<any>]
33
31
  ): void {
34
- if (key) {
35
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any, key)
32
+ if (params.length === 2) {
33
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
36
34
  } else {
37
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any)
35
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
38
36
  }
39
37
  }
@@ -1,11 +1,9 @@
1
1
  import type {
2
- MutableAtomFamilyToken,
3
2
  MutableAtomToken,
4
3
  ReadableFamilyToken,
5
4
  ReadableToken,
6
5
  ReadonlySelectorFamilyToken,
7
6
  ReadonlySelectorToken,
8
- RegularAtomFamilyToken,
9
7
  RegularAtomToken,
10
8
  WritableFamilyToken,
11
9
  WritableSelectorFamilyToken,
@@ -14,10 +12,11 @@ import type {
14
12
  } from "atom.io"
15
13
  import type { Transceiver } from "atom.io/internal"
16
14
  import { findInStore, IMPLICIT } from "atom.io/internal"
17
- import type { Canonical, Json } from "atom.io/json"
15
+ import type { Canonical } from "atom.io/json"
16
+
17
+ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
18
18
 
19
19
  /**
20
- * @public
21
20
  * Finds a {@link MutableAtomToken} in the store, without accessing its value.
22
21
  *
23
22
  * In an ephemeral store, this will create a new atom if one does not exist with the given key.
@@ -31,13 +30,11 @@ import type { Canonical, Json } from "atom.io/json"
31
30
  * @overload Mutable Atom
32
31
  */
33
32
  export function findState<
34
- T extends Transceiver<any>,
35
- J extends Json.Serializable,
33
+ T extends Transceiver<any, any>,
36
34
  K extends Canonical,
37
35
  Key extends K,
38
- >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
36
+ >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
39
37
  /**
40
- * @public
41
38
  * Finds a {@link RegularAtomToken} in the store, without accessing its value.
42
39
  *
43
40
  * In an ephemeral store, this will create a new atom if one does not exist with the given key.
@@ -55,7 +52,6 @@ export function findState<T, K extends Canonical, Key extends K>(
55
52
  key: Key,
56
53
  ): RegularAtomToken<T, K>
57
54
  /**
58
- * @public
59
55
  * Finds a {@link WritableSelectorToken} in the store, without accessing its value.
60
56
  *
61
57
  * In an ephemeral store, this will create a new selector if one does not exist with the given key.
@@ -73,7 +69,6 @@ export function findState<T, K extends Canonical, Key extends K>(
73
69
  key: Key,
74
70
  ): WritableSelectorToken<T, K>
75
71
  /**
76
- * @public
77
72
  * Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
78
73
  *
79
74
  * In an ephemeral store, this will create a new selector if one does not exist with the given key.
@@ -91,7 +86,6 @@ export function findState<T, K extends Canonical, Key extends K>(
91
86
  key: Key,
92
87
  ): ReadonlySelectorToken<T, K>
93
88
  /**
94
- * @public
95
89
  * Finds a {@link WritableToken} in the store, without accessing its value.
96
90
  *
97
91
  * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
@@ -109,7 +103,6 @@ export function findState<T, K extends Canonical, Key extends K>(
109
103
  key: Key,
110
104
  ): WritableToken<T, K>
111
105
  /**
112
- * @public
113
106
  * Finds a {@link MutableAtomToken} in the store, without accessing its value.
114
107
  *
115
108
  * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
@@ -130,7 +123,7 @@ export function findState<T, K extends Canonical, Key extends K>(
130
123
 
131
124
  export function findState(
132
125
  token: ReadableFamilyToken<any, any>,
133
- key: Json.Serializable,
126
+ key: Canonical,
134
127
  ): ReadableToken<any> {
135
128
  const state = findInStore(IMPLICIT.STORE, token, key)
136
129
  return state
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
5
5
 
6
6
  /**
7
- * @public
8
7
  * Read or compute the current value of a state
9
8
  * @param token - The token of the state to get
10
9
  * @return The current value of the state
@@ -14,7 +13,6 @@ import type { ReadableFamilyToken, ReadableToken } from "."
14
13
  export function getState<T>(token: ReadableToken<T>): T
15
14
 
16
15
  /**
17
- * @public
18
16
  * Read or compute the current value of a state
19
17
  * @param token - The token of a state family
20
18
  * @param key - The unique key of the state to get