atom.io 0.40.1 → 0.40.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/data/index.d.ts +1 -1
  2. package/dist/data/index.d.ts.map +1 -1
  3. package/dist/data/index.js.map +1 -1
  4. package/dist/internal/index.d.ts +155 -144
  5. package/dist/internal/index.d.ts.map +1 -1
  6. package/dist/internal/index.js +91 -39
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/introspection/index.d.ts +4 -4
  9. package/dist/introspection/index.d.ts.map +1 -1
  10. package/dist/introspection/index.js.map +1 -1
  11. package/dist/main/index.d.ts +80 -56
  12. package/dist/main/index.d.ts.map +1 -1
  13. package/dist/main/index.js.map +1 -1
  14. package/dist/react/index.d.ts +11 -11
  15. package/dist/react/index.d.ts.map +1 -1
  16. package/dist/react/index.js.map +1 -1
  17. package/dist/react-devtools/index.d.ts.map +1 -1
  18. package/dist/react-devtools/index.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/data/struct.ts +2 -2
  21. package/src/internal/atom/create-regular-atom.ts +8 -7
  22. package/src/internal/atom/dispose-atom.ts +6 -3
  23. package/src/internal/atom/has-role.ts +1 -1
  24. package/src/internal/caching.ts +15 -15
  25. package/src/internal/events/ingest-creation-disposal.ts +1 -1
  26. package/src/internal/families/create-readonly-held-selector-family.ts +6 -7
  27. package/src/internal/families/create-readonly-pure-selector-family.ts +23 -17
  28. package/src/internal/families/create-regular-atom-family.ts +17 -15
  29. package/src/internal/families/create-selector-family.ts +9 -9
  30. package/src/internal/families/create-writable-held-selector-family.ts +6 -7
  31. package/src/internal/families/create-writable-pure-selector-family.ts +24 -18
  32. package/src/internal/families/dispose-from-store.ts +10 -7
  33. package/src/internal/families/find-in-store.ts +23 -23
  34. package/src/internal/families/get-family-of-token.ts +17 -17
  35. package/src/internal/families/mint-in-store.ts +11 -11
  36. package/src/internal/families/seek-in-store.ts +26 -26
  37. package/src/internal/get-state/get-fallback.ts +8 -8
  38. package/src/internal/get-state/get-from-store.ts +17 -12
  39. package/src/internal/get-state/read-or-compute-value.ts +78 -14
  40. package/src/internal/get-state/reduce-reference.ts +10 -10
  41. package/src/internal/index.ts +58 -53
  42. package/src/internal/join/join-internal.ts +15 -6
  43. package/src/internal/mutable/create-mutable-atom-family.ts +7 -8
  44. package/src/internal/mutable/get-json-family.ts +3 -2
  45. package/src/internal/mutable/get-update-family.ts +7 -5
  46. package/src/internal/mutable/tracker-family.ts +5 -1
  47. package/src/internal/mutable/tracker.ts +5 -1
  48. package/src/internal/operation.ts +4 -2
  49. package/src/internal/selector/create-readonly-pure-selector.ts +8 -6
  50. package/src/internal/selector/create-standalone-selector.ts +10 -10
  51. package/src/internal/selector/create-writable-pure-selector.ts +9 -7
  52. package/src/internal/selector/dispose-selector.ts +2 -2
  53. package/src/internal/selector/register-selector.ts +2 -2
  54. package/src/internal/selector/trace-selector-atoms.ts +3 -3
  55. package/src/internal/selector/update-selector-atoms.ts +1 -1
  56. package/src/internal/set-state/dispatch-state-update.ts +9 -5
  57. package/src/internal/set-state/evict-downstream.ts +4 -1
  58. package/src/internal/set-state/operate-on-store.ts +16 -10
  59. package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
  60. package/src/internal/set-state/reset-in-store.ts +9 -6
  61. package/src/internal/set-state/set-atom-or-selector.ts +1 -1
  62. package/src/internal/set-state/set-atom.ts +1 -1
  63. package/src/internal/set-state/set-into-store.ts +10 -7
  64. package/src/internal/set-state/set-selector.ts +1 -1
  65. package/src/internal/store/deposit.ts +38 -30
  66. package/src/internal/store/mint-or-counterfeit.ts +23 -23
  67. package/src/internal/store/store.ts +9 -9
  68. package/src/internal/store/withdraw.ts +68 -62
  69. package/src/internal/subscribe/recall-state.ts +4 -1
  70. package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
  71. package/src/internal/subscribe/subscribe-to-state.ts +4 -4
  72. package/src/internal/timeline/create-timeline.ts +5 -5
  73. package/src/internal/utility-types.ts +2 -0
  74. package/src/introspection/attach-atom-index.ts +2 -2
  75. package/src/introspection/attach-selector-index.ts +4 -2
  76. package/src/introspection/attach-timeline-family.ts +13 -11
  77. package/src/introspection/attach-timeline-index.ts +1 -1
  78. package/src/introspection/attach-transaction-index.ts +1 -1
  79. package/src/introspection/attach-transaction-logs.ts +4 -2
  80. package/src/introspection/attach-type-selectors.ts +2 -1
  81. package/src/introspection/index.ts +3 -5
  82. package/src/main/atom.ts +15 -9
  83. package/src/main/events.ts +25 -23
  84. package/src/main/get-state.ts +10 -8
  85. package/src/main/reset-state.ts +4 -4
  86. package/src/main/selector.ts +41 -24
  87. package/src/main/set-state.ts +8 -4
  88. package/src/main/timeline.ts +5 -3
  89. package/src/main/tokens.ts +72 -44
  90. package/src/main/validators.ts +4 -4
  91. package/src/react/parse-state-overloads.ts +10 -10
  92. package/src/react/use-i.ts +6 -6
  93. package/src/react/use-loadable.ts +15 -15
  94. package/src/react/use-o.ts +9 -9
  95. package/src/react-devtools/StateEditor.tsx +5 -3
  96. package/src/react-devtools/StateIndex.tsx +6 -4
  97. package/src/react-devtools/Updates.tsx +1 -1
  98. package/src/react-devtools/store.ts +16 -7
@@ -4,7 +4,10 @@ import type { Store, Subject } from ".."
4
4
  import { getUpdateToken, hasRole, isChildStore, newest, withdraw } from ".."
5
5
  import { getFamilyOfToken } from "../families/get-family-of-token"
6
6
 
7
- export function disposeAtom(store: Store, atomToken: AtomToken<any>): void {
7
+ export function disposeAtom(
8
+ store: Store,
9
+ atomToken: AtomToken<any, any, any>,
10
+ ): void {
8
11
  const target = newest(store)
9
12
  const { key, family } = atomToken
10
13
  const atom = withdraw(target, atomToken)
@@ -16,10 +19,10 @@ export function disposeAtom(store: Store, atomToken: AtomToken<any>): void {
16
19
  const familyToken = getFamilyOfToken(store, atomToken)
17
20
  const atomFamily = withdraw(store, familyToken)
18
21
  const subject = atomFamily.subject as Subject<
19
- StateLifecycleEvent<AtomToken<any>>
22
+ StateLifecycleEvent<AtomToken<any, any, any>>
20
23
  >
21
24
 
22
- const disposalEvent: AtomDisposalEvent<AtomToken<any>> = {
25
+ const disposalEvent: AtomDisposalEvent<AtomToken<any, any, any>> = {
23
26
  type: `state_disposal`,
24
27
  subType: `atom`,
25
28
  token: atomToken,
@@ -3,7 +3,7 @@ import type { Atom } from ".."
3
3
  export const INTERNAL_ROLES = [`tracker:signal`] as const
4
4
  export type internalRole = (typeof INTERNAL_ROLES)[number]
5
5
 
6
- export function hasRole(atom: Atom<any>, role: internalRole): boolean {
6
+ export function hasRole(atom: Atom<any, any>, role: internalRole): boolean {
7
7
  if (`internalRoles` in atom === false) {
8
8
  return false
9
9
  }
@@ -7,21 +7,21 @@ import {
7
7
  } from "./set-state/evict-downstream"
8
8
  import type { Store } from "./store"
9
9
 
10
- export function writeToCache<T>(
10
+ export function writeToCache<T, E>(
11
11
  target: Store,
12
- state: ReadableState<T>,
13
- value: T,
14
- ): T
15
- export function writeToCache<T extends Promise<any>>(
12
+ state: ReadableState<T, E>,
13
+ value: E | T,
14
+ ): E | T
15
+ export function writeToCache<T extends Promise<any>, E>(
16
16
  target: Store,
17
- state: ReadableState<T>,
17
+ state: ReadableState<T, E>,
18
18
  value: T,
19
- ): Future<Awaited<T>>
20
- export function writeToCache<T>(
19
+ ): Future<Awaited<E | T>>
20
+ export function writeToCache<T, E>(
21
21
  target: Store,
22
- state: ReadableState<T>,
23
- value: T,
24
- ): Future<T> | T {
22
+ state: ReadableState<T, E>,
23
+ value: E | T,
24
+ ): E | Future<E | T> | T {
25
25
  const { key, subject, type } = state
26
26
  const currentValue = target.valueMap.get(key)
27
27
  if (currentValue instanceof Future && !currentValue.done) {
@@ -74,13 +74,13 @@ export function writeToCache<T>(
74
74
  * @param mut - whether the value is intended to be mutable
75
75
  * @returns the state's current value
76
76
  */
77
- export function readFromCache<T>(
77
+ export function readFromCache<T, E>(
78
78
  target: Store,
79
- state: ReadableState<T>,
79
+ state: ReadableState<T, E>,
80
80
  mut: `mut` | undefined,
81
- ): T {
81
+ ): E | T {
82
82
  target.logger.info(`📖`, state.type, state.key, `reading cached value`)
83
- let value = target.valueMap.get(state.key) as T
83
+ let value = target.valueMap.get(state.key) as E | T
84
84
 
85
85
  const mayNeedToBeCopied =
86
86
  mut === `mut` && state.type === `mutable_atom` && isChildStore(target)
@@ -37,7 +37,7 @@ export function ingestCreationEvent(
37
37
 
38
38
  export function ingestDisposalEvent(
39
39
  store: Store,
40
- event: StateDisposalEvent<ReadableToken<any>>,
40
+ event: StateDisposalEvent<ReadableToken<any, any, any>>,
41
41
  applying: `newValue` | `oldValue`,
42
42
  ): void {
43
43
  switch (applying) {
@@ -44,13 +44,13 @@ export function createReadonlyHeldSelectorFamily<
44
44
  StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>
45
45
  >()
46
46
 
47
- const familyFunction = (key: K): ReadonlyHeldSelectorToken<T> => {
47
+ const create = (key: K): ReadonlyHeldSelectorToken<T> => {
48
48
  const subKey = stringifyJson(key)
49
49
  const family: FamilyMetadata = { key: familyKey, subKey }
50
50
  const fullKey = `${familyKey}(${subKey})`
51
51
  const target = newest(store)
52
52
 
53
- const token = createReadonlyHeldSelector(
53
+ return createReadonlyHeldSelector(
54
54
  target,
55
55
  {
56
56
  key: fullKey,
@@ -59,17 +59,16 @@ export function createReadonlyHeldSelectorFamily<
59
59
  },
60
60
  family,
61
61
  )
62
-
63
- // subject.next({ type: `state_creation`, token, timestamp: Date.now() })
64
- return token
65
62
  }
66
63
 
67
- const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
64
+ const readonlySelectorFamily: ReadonlyHeldSelectorFamily<T, K> = {
65
+ ...familyToken,
66
+ create,
68
67
  internalRoles,
69
68
  subject,
70
69
  install: (s: RootStore) => createReadonlyHeldSelectorFamily(s, options),
71
70
  default: options.const,
72
- }) satisfies ReadonlyHeldSelectorFamily<T, K>
71
+ }
73
72
 
74
73
  store.families.set(familyKey, readonlySelectorFamily)
75
74
  return familyToken
@@ -4,6 +4,7 @@ import type {
4
4
  getState,
5
5
  ReadonlyPureSelectorFamilyOptions,
6
6
  ReadonlyPureSelectorFamilyToken,
7
+ ReadonlyPureSelectorOptions,
7
8
  ReadonlyPureSelectorToken,
8
9
  StateLifecycleEvent,
9
10
  } from "atom.io"
@@ -17,18 +18,18 @@ import { newest } from "../lineage"
17
18
  import { createReadonlyPureSelector } from "../selector"
18
19
  import { Subject } from "../subject"
19
20
 
20
- export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
21
+ export function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(
21
22
  store: RootStore,
22
- options: ReadonlyPureSelectorFamilyOptions<T, K>,
23
+ options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
23
24
  internalRoles?: string[],
24
- ): ReadonlyPureSelectorFamilyToken<T, K> {
25
+ ): ReadonlyPureSelectorFamilyToken<T, K, E> {
25
26
  const familyKey = options.key
26
27
  const type = `readonly_pure_selector_family`
27
28
 
28
29
  const familyToken = {
29
30
  key: familyKey,
30
31
  type,
31
- } as const satisfies ReadonlyPureSelectorFamilyToken<T, K>
32
+ } as const satisfies ReadonlyPureSelectorFamilyToken<T, K, E>
32
33
 
33
34
  const existing = store.families.get(familyKey)
34
35
  if (existing) {
@@ -41,29 +42,34 @@ export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
41
42
  }
42
43
 
43
44
  const subject = new Subject<
44
- StateLifecycleEvent<ReadonlyPureSelectorToken<T>>
45
+ StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>
45
46
  >()
46
47
 
47
- const familyFunction = (key: K): ReadonlyPureSelectorToken<T> => {
48
+ const create = <Key extends K>(
49
+ key: Key,
50
+ ): ReadonlyPureSelectorToken<T, Key, E> => {
48
51
  const subKey = stringifyJson(key)
49
- const family: FamilyMetadata = { key: familyKey, subKey }
52
+ const family: FamilyMetadata<Key> = { key: familyKey, subKey }
50
53
  const fullKey = `${familyKey}(${subKey})`
51
54
  const target = newest(store)
55
+ const individualOptions: ReadonlyPureSelectorOptions<T, E> = {
56
+ key: fullKey,
57
+ get: options.get(key),
58
+ }
59
+ if (options.catch) {
60
+ individualOptions.catch = options.catch
61
+ }
52
62
 
53
- const token = createReadonlyPureSelector(
63
+ return createReadonlyPureSelector<T, Key, E>(
54
64
  target,
55
- {
56
- key: fullKey,
57
- get: options.get(key),
58
- },
65
+ individualOptions,
59
66
  family,
60
67
  )
61
-
62
- // subject.next({ type: `state_creation`, token, timestamp: Date.now() })
63
- return token
64
68
  }
65
69
 
66
- const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
70
+ const readonlySelectorFamily: ReadonlyPureSelectorFamily<T, K, E> = {
71
+ ...familyToken,
72
+ create,
67
73
  internalRoles,
68
74
  subject,
69
75
  install: (s: RootStore) => createReadonlyPureSelectorFamily(s, options),
@@ -77,7 +83,7 @@ export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
77
83
  json: (token) => getJsonToken(store, token),
78
84
  })
79
85
  },
80
- }) satisfies ReadonlyPureSelectorFamily<T, K>
86
+ }
81
87
 
82
88
  store.families.set(familyKey, readonlySelectorFamily)
83
89
  return familyToken
@@ -16,15 +16,15 @@ import { isFn } from "../is-fn"
16
16
  import { newest } from "../lineage"
17
17
  import { Subject } from "../subject"
18
18
 
19
- export function createRegularAtomFamily<T, K extends Canonical>(
19
+ export function createRegularAtomFamily<T, K extends Canonical, E>(
20
20
  store: RootStore,
21
- options: RegularAtomFamilyOptions<T, K>,
21
+ options: RegularAtomFamilyOptions<T, K, E>,
22
22
  internalRoles?: string[],
23
- ): RegularAtomFamilyToken<T, K> {
24
- const familyToken = {
23
+ ): RegularAtomFamilyToken<T, K, E> {
24
+ const familyToken: RegularAtomFamilyToken<T, K, E> = {
25
25
  key: options.key,
26
26
  type: `atom_family`,
27
- } as const satisfies RegularAtomFamilyToken<T, K>
27
+ }
28
28
 
29
29
  const existing = store.families.get(options.key)
30
30
  if (existing) {
@@ -36,35 +36,37 @@ export function createRegularAtomFamily<T, K extends Canonical>(
36
36
  )
37
37
  }
38
38
 
39
- const subject = new Subject<StateLifecycleEvent<RegularAtomToken<T>>>()
39
+ const subject = new Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>()
40
40
 
41
- const familyFunction = (key: K): RegularAtomToken<any> => {
41
+ const create = <Key extends K>(key: Key): RegularAtomToken<T, Key, E> => {
42
42
  const subKey = stringifyJson(key)
43
- const family: FamilyMetadata = { key: options.key, subKey }
43
+ const family: FamilyMetadata<Key> = { key: options.key, subKey }
44
44
  const fullKey = `${options.key}(${subKey})`
45
45
  const target = newest(store)
46
46
 
47
47
  const def = options.default
48
- const individualOptions: RegularAtomOptions<T> = {
48
+ const individualOptions: RegularAtomOptions<T, E> = {
49
49
  key: fullKey,
50
50
  default: isFn(def) ? () => def(key) : def,
51
51
  }
52
52
  if (options.effects) {
53
53
  individualOptions.effects = options.effects(key)
54
54
  }
55
+ if (options.catch) {
56
+ individualOptions.catch = options.catch
57
+ }
55
58
 
56
- const token = createRegularAtom(target, individualOptions, family)
57
-
58
- // subject.next({ type: `state_creation`, token, timestamp: Date.now() })
59
- return token
59
+ return createRegularAtom(target, individualOptions, family)
60
60
  }
61
61
 
62
- const atomFamily = Object.assign(familyFunction, familyToken, {
62
+ const atomFamily: RegularAtomFamily<T, K, E> = {
63
+ ...familyToken,
64
+ create,
63
65
  default: options.default,
64
66
  subject,
65
67
  install: (s: RootStore) => createRegularAtomFamily(s, options),
66
68
  internalRoles,
67
- }) satisfies RegularAtomFamily<T, K>
69
+ }
68
70
 
69
71
  store.families.set(options.key, atomFamily)
70
72
  if (isFn(options.default) === false) {
@@ -25,22 +25,22 @@ export function createSelectorFamily<T extends object, K extends Canonical>(
25
25
  store: RootStore,
26
26
  options: ReadonlyHeldSelectorFamilyOptions<T, K>,
27
27
  ): ReadonlyHeldSelectorFamilyToken<T, K>
28
- export function createSelectorFamily<T, K extends Canonical>(
28
+ export function createSelectorFamily<T, K extends Canonical, E>(
29
29
  store: RootStore,
30
- options: WritablePureSelectorFamilyOptions<T, K>,
31
- ): WritablePureSelectorFamilyToken<T, K>
32
- export function createSelectorFamily<T, K extends Canonical>(
30
+ options: WritablePureSelectorFamilyOptions<T, K, E>,
31
+ ): WritablePureSelectorFamilyToken<T, K, E>
32
+ export function createSelectorFamily<T, K extends Canonical, E>(
33
33
  store: RootStore,
34
- options: ReadonlyPureSelectorFamilyOptions<T, K>,
35
- ): ReadonlyPureSelectorFamilyToken<T, K>
34
+ options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
35
+ ): ReadonlyPureSelectorFamilyToken<T, K, E>
36
36
  export function createSelectorFamily(
37
37
  store: RootStore,
38
38
  options:
39
39
  | ReadonlyHeldSelectorFamilyOptions<any, any>
40
- | ReadonlyPureSelectorFamilyOptions<any, any>
40
+ | ReadonlyPureSelectorFamilyOptions<any, any, any>
41
41
  | WritableHeldSelectorFamilyOptions<any, any>
42
- | WritablePureSelectorFamilyOptions<any, any>,
43
- ): SelectorFamilyToken<any, any> {
42
+ | WritablePureSelectorFamilyOptions<any, any, any>,
43
+ ): SelectorFamilyToken<any, any, any> {
44
44
  const isWritable = `set` in options
45
45
  const isHeld = `const` in options
46
46
 
@@ -44,13 +44,13 @@ export function createWritableHeldSelectorFamily<
44
44
  StateLifecycleEvent<WritableHeldSelectorToken<T>>
45
45
  >()
46
46
 
47
- const familyFunction = (key: K): WritableHeldSelectorToken<T> => {
47
+ const create = (key: K): WritableHeldSelectorToken<T> => {
48
48
  const subKey = stringifyJson(key)
49
49
  const family: FamilyMetadata = { key: familyKey, subKey }
50
50
  const fullKey = `${familyKey}(${subKey})`
51
51
  const target = newest(store)
52
52
 
53
- const token = createWritableHeldSelector(
53
+ return createWritableHeldSelector(
54
54
  target,
55
55
  {
56
56
  key: fullKey,
@@ -60,17 +60,16 @@ export function createWritableHeldSelectorFamily<
60
60
  },
61
61
  family,
62
62
  )
63
-
64
- // subject.next({ type: `state_creation`, token, timestamp: Date.now() })
65
- return token
66
63
  }
67
64
 
68
- const selectorFamily = Object.assign(familyFunction, familyToken, {
65
+ const selectorFamily: WritableHeldSelectorFamily<T, K> = {
66
+ ...familyToken,
67
+ create,
69
68
  internalRoles,
70
69
  subject,
71
70
  install: (s: RootStore) => createWritableHeldSelectorFamily(s, options),
72
71
  default: options.const,
73
- }) satisfies WritableHeldSelectorFamily<T, K>
72
+ }
74
73
 
75
74
  store.families.set(familyKey, selectorFamily)
76
75
  return familyToken
@@ -5,6 +5,7 @@ import type {
5
5
  StateLifecycleEvent,
6
6
  WritablePureSelectorFamilyOptions,
7
7
  WritablePureSelectorFamilyToken,
8
+ WritablePureSelectorOptions,
8
9
  WritablePureSelectorToken,
9
10
  } from "atom.io"
10
11
  import { PRETTY_TOKEN_TYPES } from "atom.io"
@@ -18,18 +19,18 @@ import { createWritablePureSelector } from "../selector"
18
19
  import type { Store } from "../store"
19
20
  import { Subject } from "../subject"
20
21
 
21
- export function createWritablePureSelectorFamily<T, K extends Canonical>(
22
+ export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
22
23
  store: Store,
23
- options: WritablePureSelectorFamilyOptions<T, K>,
24
+ options: WritablePureSelectorFamilyOptions<T, K, E>,
24
25
  internalRoles?: string[],
25
- ): WritablePureSelectorFamilyToken<T, K> {
26
+ ): WritablePureSelectorFamilyToken<T, K, E> {
26
27
  const familyKey = options.key
27
28
  const type = `writable_pure_selector_family`
28
29
 
29
30
  const familyToken = {
30
31
  key: familyKey,
31
32
  type,
32
- } as const satisfies WritablePureSelectorFamilyToken<T, K>
33
+ } as const satisfies WritablePureSelectorFamilyToken<T, K, E>
33
34
 
34
35
  const existing = store.families.get(familyKey)
35
36
  if (existing) {
@@ -41,30 +42,35 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
41
42
  )
42
43
  }
43
44
  const subject = new Subject<
44
- StateLifecycleEvent<WritablePureSelectorToken<T>>
45
+ StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>
45
46
  >()
46
47
 
47
- const familyFunction = (key: K): WritablePureSelectorToken<T> => {
48
+ const create = <Key extends K>(
49
+ key: Key,
50
+ ): WritablePureSelectorToken<T, Key, E> => {
48
51
  const subKey = stringifyJson(key)
49
- const family: FamilyMetadata = { key: familyKey, subKey }
52
+ const family: FamilyMetadata<Key> = { key: familyKey, subKey }
50
53
  const fullKey = `${familyKey}(${subKey})`
51
54
  const target = newest(store)
55
+ const individualOptions: WritablePureSelectorOptions<T, E> = {
56
+ key: fullKey,
57
+ get: options.get(key),
58
+ set: options.set(key),
59
+ }
60
+ if (options.catch) {
61
+ individualOptions.catch = options.catch
62
+ }
52
63
 
53
- const token = createWritablePureSelector(
64
+ return createWritablePureSelector<T, Key, E>(
54
65
  target,
55
- {
56
- key: fullKey,
57
- get: options.get(key),
58
- set: options.set(key),
59
- },
66
+ individualOptions,
60
67
  family,
61
68
  )
62
-
63
- // subject.next({ type: `state_creation`, token, timestamp: Date.now() })
64
- return token
65
69
  }
66
70
 
67
- const selectorFamily = Object.assign(familyFunction, familyToken, {
71
+ const selectorFamily: WritablePureSelectorFamily<T, K, E> = {
72
+ ...familyToken,
73
+ create,
68
74
  internalRoles,
69
75
  subject,
70
76
  install: (s: RootStore) => createWritablePureSelectorFamily(s, options),
@@ -78,7 +84,7 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
78
84
  json: (token) => getJsonToken(store, token),
79
85
  })
80
86
  },
81
- }) satisfies WritablePureSelectorFamily<T, K>
87
+ }
82
88
 
83
89
  store.families.set(familyKey, selectorFamily)
84
90
  return familyToken
@@ -6,28 +6,31 @@ import { disposeSelector } from "../selector"
6
6
  import { type Store, withdraw } from "../store"
7
7
  import { findInStore } from "./find-in-store"
8
8
 
9
- export function disposeFromStore(store: Store, token: ReadableToken<any>): void
9
+ export function disposeFromStore(
10
+ store: Store,
11
+ token: ReadableToken<any, any, any>,
12
+ ): void
10
13
 
11
14
  export function disposeFromStore<K extends Canonical, Key extends K>(
12
15
  store: Store,
13
- token: ReadableFamilyToken<any, K>,
16
+ token: ReadableFamilyToken<any, K, any>,
14
17
  key: Key,
15
18
  ): void
16
19
 
17
20
  export function disposeFromStore<K extends Canonical, Key extends K>(
18
21
  store: Store,
19
22
  ...params:
20
- | [token: ReadableFamilyToken<any, K>, key: Key]
21
- | [token: ReadableToken<any>]
23
+ | [token: ReadableFamilyToken<any, K, any>, key: Key]
24
+ | [token: ReadableToken<any, any, any>]
22
25
  ): void
23
26
 
24
27
  export function disposeFromStore(
25
28
  store: Store,
26
29
  ...params:
27
- | [token: ReadableFamilyToken<any, any>, key: Canonical]
28
- | [token: ReadableToken<any>]
30
+ | [token: ReadableFamilyToken<any, any, any>, key: Canonical]
31
+ | [token: ReadableToken<any, any, any>]
29
32
  ): void {
30
- let token: ReadableToken<any>
33
+ let token: ReadableToken<any, any, any>
31
34
  if (params.length === 1) {
32
35
  token = params[0]
33
36
  } else {
@@ -38,53 +38,53 @@ export function findInStore<
38
38
  key: Key,
39
39
  ): MutableAtomToken<T, K>
40
40
 
41
- export function findInStore<T, K extends Canonical, Key extends K>(
41
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
42
42
  store: Store,
43
- familyToken: RegularAtomFamilyToken<T, K>,
43
+ familyToken: RegularAtomFamilyToken<T, K, E>,
44
44
  key: Key,
45
- ): RegularAtomToken<T, K>
45
+ ): RegularAtomToken<T, K, E>
46
46
 
47
- export function findInStore<T, K extends Canonical, Key extends K>(
47
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
48
48
  store: Store,
49
- familyToken: AtomFamilyToken<T, K>,
49
+ familyToken: AtomFamilyToken<T, K, E>,
50
50
  key: Key,
51
- ): AtomToken<T, K>
51
+ ): AtomToken<T, K, E>
52
52
 
53
- export function findInStore<T, K extends Canonical, Key extends K>(
53
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
54
54
  store: Store,
55
- familyToken: WritablePureSelectorFamilyToken<T, K>,
55
+ familyToken: WritablePureSelectorFamilyToken<T, K, E>,
56
56
  key: Key,
57
- ): WritablePureSelectorToken<T, K>
57
+ ): WritablePureSelectorToken<T, K, E>
58
58
 
59
- export function findInStore<T, K extends Canonical, Key extends K>(
59
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
60
60
  store: Store,
61
- familyToken: ReadonlyPureSelectorFamilyToken<T, K>,
61
+ familyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,
62
62
  key: Key,
63
- ): ReadonlyPureSelectorToken<T, K>
63
+ ): ReadonlyPureSelectorToken<T, K, E>
64
64
 
65
- export function findInStore<T, K extends Canonical, Key extends K>(
65
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
66
66
  store: Store,
67
- familyToken: SelectorFamilyToken<T, K>,
67
+ familyToken: SelectorFamilyToken<T, K, E>,
68
68
  key: Key,
69
- ): SelectorToken<T, K>
69
+ ): SelectorToken<T, K, E>
70
70
 
71
- export function findInStore<T, K extends Canonical, Key extends K>(
71
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
72
72
  store: Store,
73
- familyToken: WritableFamilyToken<T, K>,
73
+ familyToken: WritableFamilyToken<T, K, E>,
74
74
  key: Key,
75
- ): WritableToken<T, K>
75
+ ): WritableToken<T, K, E>
76
76
 
77
- export function findInStore<T, K extends Canonical, Key extends K>(
77
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
78
78
  store: Store,
79
- familyToken: ReadableFamilyToken<T, K>,
79
+ familyToken: ReadableFamilyToken<T, K, E>,
80
80
  key: Key,
81
- ): ReadableToken<T, K>
81
+ ): ReadableToken<T, K, E>
82
82
 
83
83
  export function findInStore(
84
84
  store: Store,
85
- familyToken: ReadableFamilyToken<any, any>,
85
+ familyToken: ReadableFamilyToken<any, any, any>,
86
86
  key: Canonical,
87
- ): ReadableToken<any> {
87
+ ): ReadableToken<any, any, any> {
88
88
  const family = withdraw(store, familyToken)
89
89
  const existingStateToken = seekInStore(store, familyToken, key)
90
90
  if (existingStateToken) {
@@ -24,35 +24,35 @@ export function getFamilyOfToken<
24
24
  K extends Canonical,
25
25
  >(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>
26
26
 
27
- export function getFamilyOfToken<T, K extends Canonical>(
27
+ export function getFamilyOfToken<T, K extends Canonical, E>(
28
28
  store: Store,
29
- token: RegularAtomToken<T, K>,
30
- ): RegularAtomFamily<T, K>
29
+ token: RegularAtomToken<T, K, E>,
30
+ ): RegularAtomFamily<T, K, E>
31
31
 
32
- export function getFamilyOfToken<T, K extends Canonical>(
32
+ export function getFamilyOfToken<T, K extends Canonical, E>(
33
33
  store: Store,
34
- token: WritablePureSelectorToken<T, K>,
35
- ): WritablePureSelectorFamily<T, K>
34
+ token: WritablePureSelectorToken<T, K, E>,
35
+ ): WritablePureSelectorFamily<T, K, E>
36
36
 
37
- export function getFamilyOfToken<T, K extends Canonical>(
37
+ export function getFamilyOfToken<T, K extends Canonical, E>(
38
38
  store: Store,
39
- token: ReadonlyPureSelectorToken<T, K>,
40
- ): ReadonlyPureSelectorFamily<T, K>
39
+ token: ReadonlyPureSelectorToken<T, K, E>,
40
+ ): ReadonlyPureSelectorFamily<T, K, E>
41
41
 
42
- export function getFamilyOfToken<T, K extends Canonical>(
42
+ export function getFamilyOfToken<T, K extends Canonical, E>(
43
43
  store: Store,
44
- token: WritableToken<T, K>,
45
- ): WritableFamily<T, K>
44
+ token: WritableToken<T, K, E>,
45
+ ): WritableFamily<T, K, E>
46
46
 
47
- export function getFamilyOfToken<T, K extends Canonical>(
47
+ export function getFamilyOfToken<T, K extends Canonical, E>(
48
48
  store: Store,
49
- token: ReadableToken<T, K>,
50
- ): ReadableFamily<T, K>
49
+ token: ReadableToken<T, K, E>,
50
+ ): ReadableFamily<T, K, E>
51
51
 
52
52
  export function getFamilyOfToken(
53
53
  store: Store,
54
- token: ReadableToken<any, any>,
55
- ): ReadableFamily<any, any> {
54
+ token: ReadableToken<any, any, any>,
55
+ ): ReadableFamily<any, any, any> {
56
56
  return withdraw(store, {
57
57
  // biome-ignore lint/style/noNonNullAssertion: family is required
58
58
  key: token.family!.key,