atom.io 0.33.21 → 0.34.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 (54) hide show
  1. package/dist/eslint-plugin/index.js +1 -2
  2. package/dist/eslint-plugin/index.js.map +1 -1
  3. package/dist/internal/index.d.ts +10 -6
  4. package/dist/internal/index.d.ts.map +1 -1
  5. package/dist/internal/index.js +1262 -1253
  6. package/dist/internal/index.js.map +1 -1
  7. package/dist/json/index.d.ts +3 -0
  8. package/dist/json/index.d.ts.map +1 -1
  9. package/dist/json/index.js.map +1 -1
  10. package/dist/main/index.d.ts +405 -23
  11. package/dist/main/index.d.ts.map +1 -1
  12. package/dist/main/index.js +107 -11
  13. package/dist/main/index.js.map +1 -1
  14. package/dist/realtime-client/index.js +6 -10
  15. package/dist/realtime-client/index.js.map +1 -1
  16. package/dist/realtime-server/index.js +1 -1
  17. package/dist/realtime-server/index.js.map +1 -1
  18. package/dist/realtime-testing/index.d.ts.map +1 -1
  19. package/dist/realtime-testing/index.js +0 -1
  20. package/dist/realtime-testing/index.js.map +1 -1
  21. package/package.json +6 -6
  22. package/src/internal/atom/create-regular-atom.ts +6 -7
  23. package/src/internal/caching.ts +9 -9
  24. package/src/internal/future.ts +3 -0
  25. package/src/internal/get-state/read-or-compute-value.ts +12 -7
  26. package/src/internal/join/create-join.ts +27 -0
  27. package/src/internal/join/index.ts +1 -0
  28. package/src/internal/junction.ts +2 -0
  29. package/src/internal/mutable/create-mutable-atom.ts +2 -4
  30. package/src/internal/selector/create-readonly-held-selector.ts +10 -0
  31. package/src/internal/selector/create-readonly-pure-selector.ts +13 -4
  32. package/src/internal/selector/create-writable-held-selector.ts +11 -2
  33. package/src/internal/selector/create-writable-pure-selector.ts +11 -1
  34. package/src/internal/selector/trace-selector-atoms.ts +18 -40
  35. package/src/internal/selector/update-selector-atoms.ts +5 -5
  36. package/src/internal/set-state/evict-downstream.ts +2 -2
  37. package/src/internal/set-state/reset-atom-or-selector.ts +3 -3
  38. package/src/internal/store/store.ts +0 -1
  39. package/src/internal/subscribe/subscribe-to-root-atoms.ts +42 -38
  40. package/src/internal/subscribe/subscribe-to-state.ts +23 -11
  41. package/src/json/index.ts +3 -0
  42. package/src/main/atom.ts +54 -13
  43. package/src/main/dispose-state.ts +8 -2
  44. package/src/main/find-state.ts +44 -14
  45. package/src/main/get-state.ts +2 -2
  46. package/src/main/index.ts +8 -0
  47. package/src/main/join.ts +79 -22
  48. package/src/main/realm.ts +50 -4
  49. package/src/main/selector.ts +116 -6
  50. package/src/main/subscribe.ts +31 -1
  51. package/src/main/timeline.ts +17 -0
  52. package/src/main/transaction.ts +39 -3
  53. package/src/realtime-client/realtime-client-stores/client-sync-store.ts +2 -2
  54. package/src/realtime-testing/setup-realtime-test.tsx +0 -5
@@ -3,13 +3,13 @@ import type {
3
3
  MutableAtomToken,
4
4
  ReadableFamilyToken,
5
5
  ReadableToken,
6
- ReadonlyPureSelectorFamilyToken,
7
- ReadonlyPureSelectorToken,
6
+ ReadonlySelectorFamilyToken,
7
+ ReadonlySelectorToken,
8
8
  RegularAtomFamilyToken,
9
9
  RegularAtomToken,
10
10
  WritableFamilyToken,
11
- WritablePureSelectorFamilyToken,
12
- WritablePureSelectorToken,
11
+ WritableSelectorFamilyToken,
12
+ WritableSelectorToken,
13
13
  WritableToken,
14
14
  } from "atom.io"
15
15
  import type { Transceiver } from "atom.io/internal"
@@ -18,7 +18,12 @@ import type { Canonical, Json } from "atom.io/json"
18
18
 
19
19
  /**
20
20
  * @public
21
- * Finds a {@link MutableAtomToken} in the store
21
+ * Finds a {@link MutableAtomToken} in the store, without accessing its value.
22
+ *
23
+ * In an ephemeral store, this will create a new atom if one does not exist with the given key.
24
+ *
25
+ * In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
26
+ *
22
27
  * @param token - A {@link MutableAtomFamilyToken}
23
28
  * @param key - The key of the state
24
29
  * @returns
@@ -33,7 +38,12 @@ export function findState<
33
38
  >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
34
39
  /**
35
40
  * @public
36
- * Finds a state in the store
41
+ * Finds a {@link RegularAtomToken} in the store, without accessing its value.
42
+ *
43
+ * In an ephemeral store, this will create a new atom if one does not exist with the given key.
44
+ *
45
+ * In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
46
+ *
37
47
  * @param token - The token of the state family
38
48
  * @param key - The key of the state
39
49
  * @returns
@@ -46,7 +56,12 @@ export function findState<T, K extends Canonical, Key extends K>(
46
56
  ): RegularAtomToken<T, K>
47
57
  /**
48
58
  * @public
49
- * Finds a state in the store
59
+ * Finds a {@link WritableSelectorToken} in the store, without accessing its value.
60
+ *
61
+ * In an ephemeral store, this will create a new selector if one does not exist with the given key.
62
+ *
63
+ * In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
64
+ *
50
65
  * @param token - The token of the state family
51
66
  * @param key - The key of the state
52
67
  * @returns
@@ -54,12 +69,17 @@ export function findState<T, K extends Canonical, Key extends K>(
54
69
  * @overload Writable Selector
55
70
  */
56
71
  export function findState<T, K extends Canonical, Key extends K>(
57
- token: WritablePureSelectorFamilyToken<T, K>,
72
+ token: WritableSelectorFamilyToken<T, K>,
58
73
  key: Key,
59
- ): WritablePureSelectorToken<T, K>
74
+ ): WritableSelectorToken<T, K>
60
75
  /**
61
76
  * @public
62
- * Finds a state in the store
77
+ * Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
78
+ *
79
+ * In an ephemeral store, this will create a new selector if one does not exist with the given key.
80
+ *
81
+ * In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
82
+ *
63
83
  * @param token - The token of the state family
64
84
  * @param key - The key of the state
65
85
  * @returns
@@ -67,12 +87,17 @@ export function findState<T, K extends Canonical, Key extends K>(
67
87
  * @overload Readonly Selector
68
88
  */
69
89
  export function findState<T, K extends Canonical, Key extends K>(
70
- token: ReadonlyPureSelectorFamilyToken<T, K>,
90
+ token: ReadonlySelectorFamilyToken<T, K>,
71
91
  key: Key,
72
- ): ReadonlyPureSelectorToken<T, K>
92
+ ): ReadonlySelectorToken<T, K>
73
93
  /**
74
94
  * @public
75
- * Finds a state in the store
95
+ * Finds a {@link WritableToken} in the store, without accessing its value.
96
+ *
97
+ * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
98
+ *
99
+ * In an immortal store, a "counterfeit" token will be returned in this case and a warning will be logged.
100
+ *
76
101
  * @param token - The token of the state family
77
102
  * @param key - The key of the state
78
103
  * @returns
@@ -85,7 +110,12 @@ export function findState<T, K extends Canonical, Key extends K>(
85
110
  ): WritableToken<T, K>
86
111
  /**
87
112
  * @public
88
- * Finds a {@link ReadableToken} in the store
113
+ * Finds a {@link MutableAtomToken} in the store, without accessing its value.
114
+ *
115
+ * In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
116
+ *
117
+ * In an immortal store, a "counterfeit" token will be returned in this case and a warning will be logged.
118
+ *
89
119
  * @param token - A {@link ReadableFamilyToken}
90
120
  * @param key - The key of the state
91
121
  * @returns
@@ -5,7 +5,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
5
5
 
6
6
  /**
7
7
  * @public
8
- * Get the current value of a state
8
+ * Read or compute the current value of a state
9
9
  * @param token - The token of the state to get
10
10
  * @return The current value of the state
11
11
  * @overload Default
@@ -15,7 +15,7 @@ export function getState<T>(token: ReadableToken<T>): T
15
15
 
16
16
  /**
17
17
  * @public
18
- * Get the current value of a state family
18
+ * Read or compute the current value of a state
19
19
  * @param token - The token of a state family
20
20
  * @param key - The unique key of the state to get
21
21
  * @return The current value of the state
package/src/main/index.ts CHANGED
@@ -189,4 +189,12 @@ export type FamilyMetadata<K extends Canonical = any> = {
189
189
  subKey: stringified<K>
190
190
  }
191
191
 
192
+ /**
193
+ * @public
194
+ * Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}.
195
+ *
196
+ * When a Promise is cached as the value of a state in atom.io, that state will be automatically set to the resolved value of the Promise when it is resolved.
197
+ *
198
+ * As a result, we consider any state that can be a set to a Promise to be a "loadable" state, whose value may or may not be a Promise at any given time.
199
+ */
192
200
  export type Loadable<T> = Promise<T> | T
package/src/main/join.ts CHANGED
@@ -1,36 +1,46 @@
1
1
  import type { MutableAtomFamilyToken, ReadonlyPureSelectorToken } from "atom.io"
2
2
  import type {
3
+ Flat,
3
4
  Junction,
4
5
  JunctionEntriesBase,
5
6
  JunctionSchemaBase,
6
7
  Refinement,
7
- Store,
8
8
  } from "atom.io/internal"
9
9
  import {
10
+ createJoin,
10
11
  editRelationsInStore,
11
12
  findRelationsInStore,
12
13
  getInternalRelationsFromStore,
13
14
  IMPLICIT,
14
- Join,
15
15
  } from "atom.io/internal"
16
16
  import type { Json } from "atom.io/json"
17
17
  import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
18
18
 
19
- export interface JoinOptions<
19
+ /** @public */
20
+ // biome-ignore format: intersection
21
+ export type JoinOptions<
20
22
  ASide extends string,
21
23
  AType extends string,
22
24
  BSide extends string,
23
25
  BType extends string,
24
26
  Cardinality extends `1:1` | `1:n` | `n:n`,
25
27
  Content extends Json.Object | null,
26
- > extends JunctionSchemaBase<ASide, BSide>,
27
- Partial<JunctionEntriesBase<AType, BType, Content>> {
28
- readonly key: string
29
- readonly cardinality: Cardinality
30
- readonly isAType: Refinement<string, AType>
31
- readonly isBType: Refinement<string, BType>
32
- }
28
+ > =
29
+ Flat<
30
+ & JunctionSchemaBase<ASide, BSide>
31
+ & {
32
+ /** Unique identifier of the join */
33
+ readonly key: string
34
+ /** How many relations are allowed in each direction? */
35
+ readonly cardinality: Cardinality
36
+ /** Type guard for the type of the left side */
37
+ readonly isAType: Refinement<string, AType>
38
+ /** Type guard for the type of the right side */
39
+ readonly isBType: Refinement<string, BType>
40
+ }
41
+ > & Partial<JunctionEntriesBase<AType, BType, Content>>
33
42
 
43
+ /** @public */
34
44
  export type JoinToken<
35
45
  ASide extends string,
36
46
  AType extends string,
@@ -39,16 +49,38 @@ export type JoinToken<
39
49
  Cardinality extends `1:1` | `1:n` | `n:n`,
40
50
  Content extends Json.Object | null = null,
41
51
  > = {
52
+ /** Unique identifier of the join */
42
53
  key: string
54
+ /** Discriminator */
43
55
  type: `join`
56
+ /** How many relations are allowed in each direction? */
44
57
  cardinality: Cardinality
58
+ /** Name of the join's left side */
45
59
  a: ASide
60
+ /** Name of the join's right side */
46
61
  b: BSide
62
+ /** Never present. This is a marker that preserves the type of the left side's keys */
47
63
  __aType?: AType
64
+ /** Never present. This is a marker that preserves the type of the right side's keys */
48
65
  __bType?: BType
66
+ /** Never present. This is a marker that preserves the type of the data present for each relation */
49
67
  __content?: Content
50
68
  }
51
69
 
70
+ /**
71
+ * @public
72
+ * Create a join, an interface for managing relations between two sets of keys.
73
+ *
74
+ * Use joins when it is important to view relationships from either side.
75
+ *
76
+ * Under the hood, joins coordinate changes of multiple atoms to support that the desired relationships stay consistent.
77
+ *
78
+ * @param options - {@link JoinOptions}
79
+ * @param defaultContent - (undefined)
80
+ * @returns
81
+ * A reference to the join created: a {@link JoinToken}
82
+ * @overload No Content
83
+ */
52
84
  export function join<
53
85
  const ASide extends string,
54
86
  const AType extends string,
@@ -58,7 +90,6 @@ export function join<
58
90
  >(
59
91
  options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
60
92
  defaultContent?: undefined,
61
- store?: Store,
62
93
  ): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
63
94
  export function join<
64
95
  const ASide extends string,
@@ -70,8 +101,21 @@ export function join<
70
101
  >(
71
102
  options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
72
103
  defaultContent: Content,
73
- store?: Store,
74
104
  ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
105
+ /**
106
+ * @public
107
+ * Create a join, an interface for managing relations between two sets of keys.
108
+ *
109
+ * Use joins when it is important to view relationships from either side.
110
+ *
111
+ * Under the hood, joins coordinate changes of multiple atoms to support that the desired relationships stay consistent.
112
+ *
113
+ * @param options - {@link JoinOptions}
114
+ * @param defaultContent - The default value for the content of each relation
115
+ * @returns
116
+ * A reference to the join created: a {@link JoinToken}
117
+ * @overload With Content
118
+ */
75
119
  export function join<
76
120
  ASide extends string,
77
121
  AType extends string,
@@ -82,19 +126,11 @@ export function join<
82
126
  >(
83
127
  options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
84
128
  defaultContent: Content | undefined,
85
- store: Store = IMPLICIT.STORE,
86
129
  ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
87
- store.joins.set(options.key, new Join(options, defaultContent, store))
88
- const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
89
- key: options.key,
90
- type: `join`,
91
- a: options.between[0],
92
- b: options.between[1],
93
- cardinality: options.cardinality,
94
- }
95
- return token
130
+ return createJoin(IMPLICIT.STORE, options, defaultContent)
96
131
  }
97
132
 
133
+ /** @public */
98
134
  export type JoinStates<
99
135
  ASide extends string,
100
136
  AType extends string,
@@ -176,6 +212,15 @@ export type JoinStates<
176
212
  }
177
213
  : never
178
214
 
215
+ /**
216
+ * @public
217
+ * Find the current value of a relation owned by a {@link join}
218
+ * @param token - The token of the join
219
+ * @param key - The key of the relation to find
220
+ * @returns
221
+ * A {@link JoinStates} interface to access the relation
222
+ * @overload Default
223
+ */
179
224
  export function findRelations<
180
225
  ASide extends string,
181
226
  AType extends string,
@@ -190,6 +235,12 @@ export function findRelations<
190
235
  return findRelationsInStore(token, key, IMPLICIT.STORE)
191
236
  }
192
237
 
238
+ /**
239
+ * @public
240
+ * Change one or multiple relations owned by a {@link join}
241
+ * @param token - The token of the join
242
+ * @param change - A function that takes a {@link Junction} interface to edit the relations
243
+ */
193
244
  export function editRelations<
194
245
  ASide extends string,
195
246
  AType extends string,
@@ -204,6 +255,12 @@ export function editRelations<
204
255
  editRelationsInStore(token, change, IMPLICIT.STORE)
205
256
  }
206
257
 
258
+ /**
259
+ * @public
260
+ * @param token - The token of the join
261
+ * @returns
262
+ * A {@link MutableAtomFamilyToken} to access the internal relations
263
+ */
207
264
  export function getInternalRelations<
208
265
  ASide extends string,
209
266
  AType extends string,
package/src/main/realm.ts CHANGED
@@ -14,10 +14,21 @@ export type Claim<K extends Canonical> = K & { [$claim]?: true }
14
14
 
15
15
  export class Realm<H extends Hierarchy> {
16
16
  public store: Store
17
+ /**
18
+ * @param store - The store to which the realm will be attached
19
+ */
17
20
  public constructor(store: Store = IMPLICIT.STORE) {
18
21
  this.store = store
19
22
  makeRootMoleculeInStore(`root`, store)
20
23
  }
24
+ /**
25
+ * Make space for a new subject of the realm
26
+ * @param provenance - A key for an owner {@link Above} the new subject in the realm's {@link Hierarchy}
27
+ * @param key - A unique identifier for the new subject
28
+ * @param attachmentStyle - The attachment style of new subject to its owner(s). `any` means that if any owners remain, the subject will be retained. `all` means that the subject be retained only if all owners remain .
29
+ * @returns
30
+ * The subject's key, given status as a true {@link Claim}
31
+ */
21
32
  public allocate<V extends Vassal<H>, A extends Above<V, H>>(
22
33
  provenance: A,
23
34
  key: V,
@@ -30,6 +41,14 @@ export class Realm<H extends Hierarchy> {
30
41
  attachmentStyle,
31
42
  )
32
43
  }
44
+ /**
45
+ * Fuse two reagents into a compound
46
+ * @param type - the name of the compound that is being fused
47
+ * @param reagentA - the left reagent of the compound
48
+ * @param reagentB - the right reagent of the compound
49
+ * @returns
50
+ * The compound's key, given status as a true {@link Claim}
51
+ */
33
52
  public fuse<
34
53
  C extends CompoundFrom<H>,
35
54
  T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
@@ -42,10 +61,21 @@ export class Realm<H extends Hierarchy> {
42
61
  ): Claim<CompoundTypedKey<T, A, B>> {
43
62
  return fuseWithinStore<H, C, T, A, B>(this.store, type, reagentA, reagentB)
44
63
  }
45
-
64
+ /**
65
+ * Remove a subject from the realm
66
+ * @param claim - The subject to be deallocated
67
+ */
46
68
  public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
47
69
  deallocateFromStore<H, V>(this.store, claim)
48
70
  }
71
+ /**
72
+ * Transfer a subject of the realm from one owner to another
73
+ * @param newProvenance - A key for an owner {@link Above} the new subject in the realm's {@link Hierarchy}
74
+ * @param claim - The subject to be claimed
75
+ * @param exclusive - Whether the subjects previous owners should be detached from it
76
+ * @returns
77
+ * The subject's key, given status as a true {@link Claim}
78
+ */
49
79
  public claim<
50
80
  V extends Exclude<Vassal<H>, CompoundTypedKey>,
51
81
  A extends Above<V, H>,
@@ -58,11 +88,19 @@ export class Anarchy {
58
88
  public store: Store
59
89
  public realm: Realm<any>
60
90
 
91
+ /**
92
+ * @param store - The store to which the anarchy-realm will be attached
93
+ */
61
94
  public constructor(store: Store = IMPLICIT.STORE) {
62
95
  this.store = store
63
96
  this.realm = new Realm(store)
64
97
  }
65
-
98
+ /**
99
+ * Declare a new entity
100
+ * @param provenance - A key for an owner of the entity
101
+ * @param key - A unique identifier for the new entity
102
+ * @param attachmentStyle - The attachment style of new entity to its owner(s). `any` means that if any owners remain, the subject will be retained. `all` means that the subject be retained only if all owners remain .
103
+ */
66
104
  public allocate(
67
105
  provenance: Canonical,
68
106
  key: Canonical,
@@ -75,11 +113,19 @@ export class Anarchy {
75
113
  attachmentStyle,
76
114
  )
77
115
  }
78
-
116
+ /**
117
+ * Remove an entity
118
+ * @param key - The entity to be deallocated
119
+ */
79
120
  public deallocate(key: Canonical): void {
80
121
  deallocateFromStore<any, any>(this.store, key)
81
122
  }
82
-
123
+ /**
124
+ * Transfer an entity from one owner to another
125
+ * @param newProvenance - A key for an owner of the entity
126
+ * @param key - The entity to be claimed
127
+ * @param exclusive - Whether the entity's previous owners should be detached from it
128
+ */
83
129
  public claim(
84
130
  newProvenance: Canonical,
85
131
  key: Canonical,
@@ -14,23 +14,35 @@ import type {
14
14
  import type { Read, Write } from "./transaction"
15
15
 
16
16
  export type WritablePureSelectorOptions<T> = {
17
+ /** The unique identifier of the selector */
17
18
  key: string
19
+ /** For each instantiated selector, a function that computes its value */
18
20
  get: Read<() => T>
21
+ /** For each instantiated selector, a function that sets its value */
19
22
  set: Write<(newValue: T) => void>
20
23
  }
21
24
  export type ReadonlyPureSelectorOptions<T> = {
25
+ /** The unique identifier of the selector */
22
26
  key: string
27
+ /** For each instantiated selector, a function that computes its value */
23
28
  get: Read<() => T>
24
29
  }
25
30
  export type ReadonlyHeldSelectorOptions<T extends object> = {
31
+ /** The unique identifier of the selector */
26
32
  key: string
33
+ /** For each instantiated selector, a constant reference to a value that will not be replaced */
27
34
  const: T
35
+ /** For each instantiated selector, a function that computes its value */
28
36
  get: Read<(permanent: T) => void>
29
37
  }
30
38
  export type WritableHeldSelectorOptions<T extends object> = {
39
+ /** The unique identifier of the selector */
31
40
  key: string
41
+ /** For each instantiated selector, a constant reference to a value that will not be replaced */
32
42
  const: T
43
+ /** For each instantiated selector, a function that computes its value */
33
44
  get: Read<(permanent: T) => void>
45
+ /** For each instantiated selector, a function that sets its value */
34
46
  set: Write<(newValue: T) => void>
35
47
  }
36
48
 
@@ -44,7 +56,7 @@ export type WritableHeldSelectorOptions<T extends object> = {
44
56
  * The reference to that object is permanent and will not be replaced.
45
57
  *
46
58
  * A writable selector can be "set" to a new value.
47
- * It is advised to set its dependencies to values
59
+ * It is strongly advised to set its dependencies to values
48
60
  * that would produce the new value of the selector.
49
61
  *
50
62
  * @param options - {@link WritableHeldSelectorOptions}.
@@ -55,7 +67,6 @@ export type WritableHeldSelectorOptions<T extends object> = {
55
67
  export function selector<T extends object>(
56
68
  options: WritableHeldSelectorOptions<T>,
57
69
  ): WritableHeldSelectorToken<T>
58
-
59
70
  /**
60
71
  * @public
61
72
  * Declare a selector. The value of a selector should depend
@@ -75,7 +86,6 @@ export function selector<T extends object>(
75
86
  export function selector<T extends object>(
76
87
  options: ReadonlyHeldSelectorOptions<T>,
77
88
  ): ReadonlyHeldSelectorToken<T>
78
-
79
89
  /**
80
90
  * @public
81
91
  * Declare a selector. The value of a selector should depend
@@ -85,7 +95,7 @@ export function selector<T extends object>(
85
95
  * in order to be garbage collected when a root atom of the selector is set.
86
96
  *
87
97
  * A writable selector can be "set" to a new value.
88
- * It is advised to set its dependencies to values
98
+ * It is strongly advised to set its dependencies to values
89
99
  * that would produce the new value of the selector.
90
100
  *
91
101
  * @param options - {@link TransientWritableSelectorOptions}.
@@ -96,7 +106,6 @@ export function selector<T extends object>(
96
106
  export function selector<T>(
97
107
  options: WritablePureSelectorOptions<T>,
98
108
  ): WritablePureSelectorToken<T>
99
-
100
109
  /**
101
110
  * @public
102
111
  * Declare a selector. The value of a selector should depend
@@ -115,7 +124,6 @@ export function selector<T>(
115
124
  export function selector<T>(
116
125
  options: ReadonlyPureSelectorOptions<T>,
117
126
  ): ReadonlyPureSelectorToken<T>
118
-
119
127
  export function selector(
120
128
  options:
121
129
  | ReadonlyHeldSelectorOptions<any>
@@ -130,55 +138,87 @@ export function selector(
130
138
  return createStandaloneSelector(IMPLICIT.STORE, options)
131
139
  }
132
140
 
141
+ /** @public */
133
142
  export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
143
+ /** The unique identifier of the family */
134
144
  key: string
145
+ /** For each instantiated family member, a function that computes its value */
135
146
  get: (key: K) => Read<() => T>
147
+ /** For each instantiated family member, a function that sets its value */
136
148
  set: (key: K) => Write<(newValue: T) => void>
137
149
  }
150
+ /** @public */
138
151
  export type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
152
+ /** The unique identifier of the family */
139
153
  key: string
154
+ /** For each instantiated family member, a function that computes its value */
140
155
  get: (key: K) => Read<() => T>
141
156
  }
157
+ /** @public */
142
158
  export type WritableHeldSelectorFamilyOptions<
143
159
  T extends object,
144
160
  K extends Canonical,
145
161
  > = {
162
+ /** The unique identifier of the family */
146
163
  key: string
164
+ /** For each instantiated family member, a constant reference to a value that will not be replaced */
147
165
  const: (key: K) => T
166
+ /** For each instantiated family member, a function that computes its value */
148
167
  get: (key: K) => Read<(permanent: T) => void>
168
+ /** For each instantiated family member, a function that sets its value */
149
169
  set: (key: K) => Write<(newValue: T) => void>
150
170
  }
171
+ /** @public */
151
172
  export type ReadonlyHeldSelectorFamilyOptions<
152
173
  T extends object,
153
174
  K extends Canonical,
154
175
  > = {
176
+ /** The unique identifier of the family */
155
177
  key: string
178
+ /** For each instantiated family member, a constant reference to a value that will not be replaced */
156
179
  const: (key: K) => T
180
+ /** For each instantiated family member, a function that computes its value */
157
181
  get: (key: K) => Read<(permanent: T) => void>
158
182
  }
159
183
 
160
184
  export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
185
+ /** The unique identifier of the family */
161
186
  key: string
187
+ /** Discriminator */
162
188
  type: `writable_pure_selector_family`
189
+ /** Never present. This is a marker that preserves the type of the value of each family member */
163
190
  __T?: T
191
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
164
192
  __K?: K
165
193
  }
166
194
  export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
195
+ /** The unique identifier of the family */
167
196
  key: string
197
+ /** Discriminator */
168
198
  type: `readonly_pure_selector_family`
199
+ /** Never present. This is a marker that preserves the type of the value of each family member */
169
200
  __T?: T
201
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
170
202
  __K?: K
171
203
  }
172
204
  export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
205
+ /** The unique identifier of the family */
173
206
  key: string
207
+ /** Discriminator */
174
208
  type: `writable_held_selector_family`
209
+ /** Never present. This is a marker that preserves the type of the value of each family member */
175
210
  __T?: T
211
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
176
212
  __K?: K
177
213
  }
178
214
  export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
215
+ /** The unique identifier of the family */
179
216
  key: string
217
+ /** Discriminator */
180
218
  type: `readonly_held_selector_family`
219
+ /** Never present. This is a marker that preserves the type of the value of each family member */
181
220
  __T?: T
221
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
182
222
  __K?: K
183
223
  }
184
224
 
@@ -200,15 +240,85 @@ export type SelectorFamilyToken<T, K extends Canonical> =
200
240
  | HeldSelectorFamilyToken<T, K>
201
241
  | PureSelectorFamilyToken<T, K>
202
242
 
243
+ /**
244
+ * @public
245
+ * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
246
+ *
247
+ * The value of a held selector should depend on the value of atoms or other selectors in the store,
248
+ * and should be recycled when a root atom of the selector is set.
249
+ *
250
+ * A held selector's value must be some object.
251
+ * The reference to that object is permanent and will not be replaced.
252
+ *
253
+ * A writable selector can be "set" to a new value.
254
+ * It is advised to set its dependencies to values
255
+ * that would produce the new value of the selector.
256
+ *
257
+ * @param options - {@link WritableHeldSelectorFamilyOptions}.
258
+ * @returns
259
+ * A reference to the selector family created: a {@link WritableHeldSelectorFamilyToken}
260
+ * @overload WritableHeld
261
+ */
203
262
  export function selectorFamily<T extends object, K extends Canonical>(
204
263
  options: WritableHeldSelectorFamilyOptions<T, K>,
205
264
  ): WritableHeldSelectorFamilyToken<T, K>
265
+ /**
266
+ * @public
267
+ * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
268
+ *
269
+ * The value of a held selector should depend on the value of atoms or other selectors in the store,
270
+ * and should be recycled when a root atom of the selector is set.
271
+ *
272
+ * A held selector's value must be some object.
273
+ * The reference to that object is permanent and will not be replaced.
274
+ *
275
+ * A readonly selector can be "gotten" but not "set".
276
+ *
277
+ * @param options - {@link ReadonlyHeldSelectorFamilyOptions}.
278
+ * @returns
279
+ * A reference to the selector family created: a {@link ReadonlyHeldSelectorFamilyToken}
280
+ * @overload ReadonlyHeld
281
+ */
206
282
  export function selectorFamily<T extends object, K extends Canonical>(
207
283
  options: ReadonlyHeldSelectorFamilyOptions<T, K>,
208
284
  ): ReadonlyHeldSelectorFamilyToken<T, K>
285
+ /**
286
+ * @public
287
+ * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
288
+ *
289
+ * The value of a selector should depend on the value of atoms or other selectors in the store.
290
+ *
291
+ * A pure selector's current value is evicted from the store
292
+ * in order to be garbage collected when a root atom of the selector is set.
293
+ *
294
+ * A writable selector can be "set" to a new value.
295
+ * It is advised to set its dependencies to values
296
+ * that would produce the new value of the selector.
297
+ *
298
+ * @param options - {@link TransientWritableSelectorFamilyOptions}.
299
+ * @returns
300
+ * A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
301
+ * @overload WritablePure
302
+ */
209
303
  export function selectorFamily<T, K extends Canonical>(
210
304
  options: WritablePureSelectorFamilyOptions<T, K>,
211
305
  ): WritablePureSelectorFamilyToken<T, K>
306
+ /**
307
+ * @public
308
+ * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
309
+ *
310
+ * The value of a selector should depend on the value of atoms or other selectors in the store.
311
+ *
312
+ * A pure selector's current value is evicted from the store
313
+ * in order to be garbage collected when a root atom of the selector is set.
314
+ *
315
+ * A readonly selector can be "gotten" but not "set".
316
+ *
317
+ * @param options - {@link ReadonlyPureSelectorFamilyOptions}.
318
+ * @returns
319
+ * A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
320
+ * @overload ReadonlyPure
321
+ */
212
322
  export function selectorFamily<T, K extends Canonical>(
213
323
  options: ReadonlyPureSelectorFamilyOptions<T, K>,
214
324
  ): ReadonlyPureSelectorFamilyToken<T, K>