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
@@ -46,44 +46,52 @@ import type {
46
46
  } from ".."
47
47
  import type { Transaction } from "../transaction"
48
48
 
49
- export function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>
49
+ export function deposit<T, E>(
50
+ state: RegularAtom<T, E>,
51
+ ): RegularAtomToken<T, Canonical, E>
50
52
  export function deposit<T extends Transceiver<any, any, any>>(
51
53
  state: MutableAtom<T>,
52
54
  ): MutableAtomToken<T>
53
- export function deposit<T>(state: Atom<T>): AtomToken<T>
54
- export function deposit<T>(
55
- state: WritablePureSelector<T>,
56
- ): WritablePureSelectorToken<T>
57
- export function deposit<T>(
58
- state: ReadonlyPureSelector<T>,
59
- ): ReadonlyPureSelectorToken<T>
60
- export function deposit<T>(state: Selector<T>): SelectorToken<T>
61
- export function deposit<T>(state: WritableState<T>): WritableToken<T>
62
- export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
55
+ export function deposit<T, E>(state: Atom<T, E>): AtomToken<T, Canonical, E>
56
+ export function deposit<T, E>(
57
+ state: WritablePureSelector<T, E>,
58
+ ): WritablePureSelectorToken<T, any, E>
59
+ export function deposit<T, E>(
60
+ state: ReadonlyPureSelector<T, E>,
61
+ ): ReadonlyPureSelectorToken<T, any, E>
62
+ export function deposit<T, E>(state: Selector<T, E>): SelectorToken<T, any, E>
63
+ export function deposit<T, E>(
64
+ state: WritableState<T, E>,
65
+ ): WritableToken<T, any, E>
66
+ export function deposit<T, E>(
67
+ state: ReadableState<T, E>,
68
+ ): ReadableToken<T, any, E>
63
69
 
64
- export function deposit<T, K extends Canonical>(
65
- state: RegularAtomFamily<T, K>,
66
- ): RegularAtomFamilyToken<T, K>
70
+ export function deposit<T, K extends Canonical, E>(
71
+ state: RegularAtomFamily<T, K, E>,
72
+ ): RegularAtomFamilyToken<T, K, E>
67
73
  export function deposit<
68
74
  T extends Transceiver<any, any, any>,
69
75
  K extends Canonical,
70
76
  >(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, K>
71
- export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
72
- export function deposit<T>(
73
- state: WritablePureSelectorFamily<T, any>,
74
- ): WritablePureSelectorFamilyToken<T, any>
75
- export function deposit<T>(
76
- state: ReadonlyPureSelectorFamily<T, any>,
77
- ): ReadonlyPureSelectorFamilyToken<T, any>
78
- export function deposit<T>(
79
- state: SelectorFamily<T, any>,
80
- ): SelectorFamilyToken<T, any>
81
- export function deposit<T>(
82
- state: WritableFamily<T, any>,
83
- ): WritableFamilyToken<T, any>
84
- export function deposit<T>(
85
- state: ReadableFamily<T, any>,
86
- ): ReadableFamilyToken<T, any>
77
+ export function deposit<T, E>(
78
+ state: AtomFamily<T, any, E>,
79
+ ): AtomFamilyToken<T, any, E>
80
+ export function deposit<T, E>(
81
+ state: WritablePureSelectorFamily<T, any, E>,
82
+ ): WritablePureSelectorFamilyToken<T, any, E>
83
+ export function deposit<T, E>(
84
+ state: ReadonlyPureSelectorFamily<T, any, E>,
85
+ ): ReadonlyPureSelectorFamilyToken<T, any, E>
86
+ export function deposit<T, E>(
87
+ state: SelectorFamily<T, any, E>,
88
+ ): SelectorFamilyToken<T, any, E>
89
+ export function deposit<T, E>(
90
+ state: WritableFamily<T, any, E>,
91
+ ): WritableFamilyToken<T, any, E>
92
+ export function deposit<T, E>(
93
+ state: ReadableFamily<T, any, E>,
94
+ ): ReadableFamilyToken<T, any, E>
87
95
 
88
96
  export function deposit<T extends Fn>(state: Transaction<T>): TransactionToken<T>
89
97
  export function deposit<M extends TimelineManageable>(
@@ -39,53 +39,53 @@ export function mint<
39
39
  Key extends K,
40
40
  >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
41
41
 
42
- export function mint<T, K extends Canonical, Key extends K>(
43
- token: RegularAtomFamilyToken<T, K>,
42
+ export function mint<T, K extends Canonical, Key extends K, E>(
43
+ token: RegularAtomFamilyToken<T, K, E>,
44
44
  key: Key,
45
45
  counterfeit?: typeof COUNTERFEIT,
46
- ): RegularAtomToken<T>
46
+ ): RegularAtomToken<T, Key, E>
47
47
 
48
- export function mint<T, K extends Canonical, Key extends K>(
49
- token: AtomFamilyToken<T, K>,
48
+ export function mint<T, K extends Canonical, Key extends K, E>(
49
+ token: AtomFamilyToken<T, K, E>,
50
50
  key: Key,
51
51
  counterfeit?: typeof COUNTERFEIT,
52
- ): AtomToken<T>
52
+ ): AtomToken<T, Key, E>
53
53
 
54
- export function mint<T, K extends Canonical, Key extends K>(
55
- token: WritablePureSelectorFamilyToken<T, K>,
54
+ export function mint<T, K extends Canonical, Key extends K, E>(
55
+ token: WritablePureSelectorFamilyToken<T, K, E>,
56
56
  key: Key,
57
57
  counterfeit?: typeof COUNTERFEIT,
58
- ): WritablePureSelectorToken<T>
58
+ ): WritablePureSelectorToken<T, Key, E>
59
59
 
60
- export function mint<T, K extends Canonical, Key extends K>(
61
- token: ReadonlyPureSelectorFamilyToken<T, K>,
60
+ export function mint<T, K extends Canonical, Key extends K, E>(
61
+ token: ReadonlyPureSelectorFamilyToken<T, K, E>,
62
62
  key: Key,
63
63
  counterfeit?: typeof COUNTERFEIT,
64
- ): ReadonlyPureSelectorToken<T>
64
+ ): ReadonlyPureSelectorToken<T, Key, E>
65
65
 
66
- export function mint<T, K extends Canonical, Key extends K>(
67
- token: SelectorFamilyToken<T, K>,
66
+ export function mint<T, K extends Canonical, Key extends K, E>(
67
+ token: SelectorFamilyToken<T, K, E>,
68
68
  key: Key,
69
69
  counterfeit?: typeof COUNTERFEIT,
70
- ): SelectorToken<T>
70
+ ): SelectorToken<T, Key, E>
71
71
 
72
- export function mint<T, K extends Canonical, Key extends K>(
73
- token: WritableFamilyToken<T, K>,
72
+ export function mint<T, K extends Canonical, Key extends K, E>(
73
+ token: WritableFamilyToken<T, K, E>,
74
74
  key: Key,
75
75
  counterfeit?: typeof COUNTERFEIT,
76
- ): WritableToken<T>
76
+ ): WritableToken<T, Key, E>
77
77
 
78
- export function mint<T, K extends Canonical, Key extends K>(
79
- token: ReadableFamilyToken<T, K>,
78
+ export function mint<T, K extends Canonical, Key extends K, E>(
79
+ token: ReadableFamilyToken<T, K, E>,
80
80
  key: Key,
81
81
  counterfeit?: typeof COUNTERFEIT,
82
- ): ReadableToken<T>
82
+ ): ReadableToken<T, Key, E>
83
83
 
84
84
  export function mint(
85
- token: ReadableFamilyToken<any, any>,
85
+ token: ReadableFamilyToken<any, any, any>,
86
86
  key: Canonical,
87
87
  counterfeit?: typeof COUNTERFEIT,
88
- ): ReadableToken<any> {
88
+ ): ReadableToken<any, any, any> {
89
89
  const subKey = stringifyJson(key)
90
90
  const fullKey = `${token.key}(${subKey})`
91
91
  const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
@@ -47,9 +47,9 @@ export class Store implements Lineage {
47
47
  public valueMap: Map<string, any> = new Map()
48
48
  public defaults: Map<string, any> = new Map()
49
49
 
50
- public atoms: Map<string, Atom<any>> = new Map()
51
- public writableSelectors: Map<string, WritableSelector<any>> = new Map()
52
- public readonlySelectors: Map<string, ReadonlySelector<any>> = new Map()
50
+ public atoms: Map<string, Atom<any, any>> = new Map()
51
+ public writableSelectors: Map<string, WritableSelector<any, any>> = new Map()
52
+ public readonlySelectors: Map<string, ReadonlySelector<any, any>> = new Map()
53
53
 
54
54
  public atomsThatAreDefault: Set<string> = new Set()
55
55
  public selectorAtoms: Junction<`selectorKey`, string, `atomKey`, string> =
@@ -77,8 +77,8 @@ export class Store implements Lineage {
77
77
  string,
78
78
  | HeldSelectorFamily<any, any>
79
79
  | MutableAtomFamily<any, any>
80
- | PureSelectorFamily<any, any>
81
- | RegularAtomFamily<any, any>
80
+ | PureSelectorFamily<any, any, any>
81
+ | RegularAtomFamily<any, any, any>
82
82
  > = new Map()
83
83
  public joins: Map<string, Join<any, any, any, any, any, any>> = new Map()
84
84
 
@@ -247,10 +247,10 @@ export class Store implements Lineage {
247
247
  }
248
248
 
249
249
  export type StoreEventCarrier = {
250
- atomCreation: Subject<AtomToken<unknown>>
251
- atomDisposal: Subject<AtomToken<unknown>>
252
- selectorCreation: Subject<SelectorToken<unknown>>
253
- selectorDisposal: Subject<SelectorToken<unknown>>
250
+ atomCreation: Subject<AtomToken<unknown, any, any>>
251
+ atomDisposal: Subject<AtomToken<unknown, any, any>>
252
+ selectorCreation: Subject<SelectorToken<unknown, any, any>>
253
+ selectorDisposal: Subject<SelectorToken<unknown, any, any>>
254
254
  timelineCreation: Subject<TimelineToken<unknown>>
255
255
  transactionCreation: Subject<TransactionToken<Fn>>
256
256
  transactionApplying: StatefulSubject<TransactionProgress<Fn> | null>
@@ -72,15 +72,18 @@ import type { Timeline } from "../timeline"
72
72
  import type { Transaction } from "../transaction"
73
73
  import type { Store } from "./store"
74
74
 
75
- export function withdraw<T>(
75
+ export function withdraw<T, E>(
76
76
  store: Store,
77
- token: RegularAtomToken<T>,
78
- ): RegularAtom<T>
77
+ token: RegularAtomToken<T, any, E>,
78
+ ): RegularAtom<T, E>
79
79
  export function withdraw<T extends Transceiver<any, any, any>>(
80
80
  store: Store,
81
81
  token: MutableAtomToken<T, any>,
82
82
  ): MutableAtom<T>
83
- export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
83
+ export function withdraw<T, E>(
84
+ store: Store,
85
+ token: AtomToken<T, any, E>,
86
+ ): Atom<T, E>
84
87
  export function withdraw<T>(
85
88
  store: Store,
86
89
  token: WritableHeldSelectorToken<T>,
@@ -89,52 +92,55 @@ export function withdraw<T>(
89
92
  store: Store,
90
93
  token: ReadonlyHeldSelectorToken<T>,
91
94
  ): ReadonlyHeldSelector<T>
92
- export function withdraw<T>(
95
+ export function withdraw<T, E>(
93
96
  store: Store,
94
- token: WritablePureSelectorToken<T>,
95
- ): WritablePureSelector<T>
96
- export function withdraw<T>(
97
+ token: WritablePureSelectorToken<T, any, E>,
98
+ ): WritablePureSelector<T, E>
99
+ export function withdraw<T, E>(
97
100
  store: Store,
98
- token: ReadonlyPureSelectorToken<T>,
99
- ): ReadonlyPureSelector<T>
100
- export function withdraw<T>(
101
+ token: ReadonlyPureSelectorToken<T, any, E>,
102
+ ): ReadonlyPureSelector<T, E>
103
+ export function withdraw<T, E>(
101
104
  store: Store,
102
- token: ReadonlySelectorToken<T>,
103
- ): ReadonlySelector<T>
104
- export function withdraw<T>(
105
+ token: ReadonlySelectorToken<T, any, E>,
106
+ ): ReadonlySelector<T, E>
107
+ export function withdraw<T, E>(
105
108
  store: Store,
106
- token: WritableSelectorToken<T>,
107
- ): WritableSelector<T>
109
+ token: WritableSelectorToken<T, any, E>,
110
+ ): WritableSelector<T, E>
108
111
  export function withdraw<T>(
109
112
  store: Store,
110
113
  token: HeldSelectorToken<T>,
111
114
  ): HeldSelector<T>
112
- export function withdraw<T>(
115
+ export function withdraw<T, E>(
113
116
  store: Store,
114
- token: PureSelectorToken<T>,
115
- ): PureSelector<T>
116
- export function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>
117
- export function withdraw<T>(
117
+ token: PureSelectorToken<T, any, E>,
118
+ ): PureSelector<T, E>
119
+ export function withdraw<T, E>(
118
120
  store: Store,
119
- token: WritableToken<T>,
120
- ): WritableState<T>
121
- export function withdraw<T>(
121
+ token: SelectorToken<T, any, E>,
122
+ ): Selector<T, E>
123
+ export function withdraw<T, E>(
122
124
  store: Store,
123
- token: ReadableToken<T>,
124
- ): ReadableState<T>
125
+ token: WritableToken<T, any, E>,
126
+ ): WritableState<T, E>
127
+ export function withdraw<T, E>(
128
+ store: Store,
129
+ token: ReadableToken<T, any, E>,
130
+ ): ReadableState<T, E>
125
131
 
126
- export function withdraw<T, K extends Canonical>(
132
+ export function withdraw<T, K extends Canonical, E>(
127
133
  store: Store,
128
- token: RegularAtomFamilyToken<T, K>,
129
- ): RegularAtomFamily<T, K>
134
+ token: RegularAtomFamilyToken<T, K, E>,
135
+ ): RegularAtomFamily<T, K, E>
130
136
  export function withdraw<
131
137
  T extends Transceiver<any, any, any>,
132
138
  K extends Canonical,
133
139
  >(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>
134
- export function withdraw<T, K extends Canonical>(
140
+ export function withdraw<T, K extends Canonical, E>(
135
141
  store: Store,
136
- token: AtomFamilyToken<T, K>,
137
- ): AtomFamily<T, K>
142
+ token: AtomFamilyToken<T, K, E>,
143
+ ): AtomFamily<T, K, E>
138
144
  export function withdraw<T, K extends Canonical>(
139
145
  store: Store,
140
146
  token: ReadonlyHeldSelectorFamilyToken<T, K>,
@@ -143,42 +149,42 @@ export function withdraw<T, K extends Canonical>(
143
149
  store: Store,
144
150
  token: WritableHeldSelectorFamilyToken<T, K>,
145
151
  ): WritableHeldSelectorFamily<T, K>
146
- export function withdraw<T, K extends Canonical>(
152
+ export function withdraw<T, K extends Canonical, E>(
147
153
  store: Store,
148
- token: ReadonlyPureSelectorFamilyToken<T, K>,
149
- ): ReadonlyPureSelectorFamily<T, K>
150
- export function withdraw<T, K extends Canonical>(
154
+ token: ReadonlyPureSelectorFamilyToken<T, K, E>,
155
+ ): ReadonlyPureSelectorFamily<T, K, E>
156
+ export function withdraw<T, K extends Canonical, E>(
151
157
  store: Store,
152
- token: WritablePureSelectorFamilyToken<T, K>,
153
- ): WritablePureSelectorFamily<T, K>
154
- export function withdraw<T, K extends Canonical>(
158
+ token: WritablePureSelectorFamilyToken<T, K, E>,
159
+ ): WritablePureSelectorFamily<T, K, E>
160
+ export function withdraw<T, K extends Canonical, E>(
155
161
  store: Store,
156
- token: ReadonlySelectorFamilyToken<T, K>,
157
- ): ReadonlySelectorFamily<T, K>
158
- export function withdraw<T, K extends Canonical>(
162
+ token: ReadonlySelectorFamilyToken<T, K, E>,
163
+ ): ReadonlySelectorFamily<T, K, E>
164
+ export function withdraw<T, K extends Canonical, E>(
159
165
  store: Store,
160
- token: WritableSelectorFamilyToken<T, K>,
161
- ): WritableSelectorFamily<T, K>
166
+ token: WritableSelectorFamilyToken<T, K, E>,
167
+ ): WritableSelectorFamily<T, K, E>
162
168
  export function withdraw<T, K extends Canonical>(
163
169
  store: Store,
164
170
  token: HeldSelectorFamilyToken<T, K>,
165
171
  ): HeldSelectorFamily<T, K>
166
- export function withdraw<T, K extends Canonical>(
172
+ export function withdraw<T, K extends Canonical, E>(
167
173
  store: Store,
168
- token: PureSelectorFamilyToken<T, K>,
169
- ): PureSelectorFamily<T, K>
170
- export function withdraw<T, K extends Canonical>(
174
+ token: PureSelectorFamilyToken<T, K, E>,
175
+ ): PureSelectorFamily<T, K, E>
176
+ export function withdraw<T, K extends Canonical, E>(
171
177
  store: Store,
172
- token: SelectorFamilyToken<T, K>,
173
- ): SelectorFamily<T, K>
174
- export function withdraw<T, K extends Canonical>(
178
+ token: SelectorFamilyToken<T, K, E>,
179
+ ): SelectorFamily<T, K, E>
180
+ export function withdraw<T, K extends Canonical, E>(
175
181
  store: Store,
176
- token: WritableFamilyToken<T, K>,
177
- ): WritableFamily<T, K>
178
- export function withdraw<T, K extends Canonical>(
182
+ token: WritableFamilyToken<T, K, E>,
183
+ ): WritableFamily<T, K, E>
184
+ export function withdraw<T, K extends Canonical, E>(
179
185
  store: Store,
180
- token: ReadableFamilyToken<T, K>,
181
- ): ReadableFamily<T, K>
186
+ token: ReadableFamilyToken<T, K, E>,
187
+ ): ReadableFamily<T, K, E>
182
188
 
183
189
  export function withdraw<T extends Fn>(
184
190
  store: Store,
@@ -189,14 +195,14 @@ export function withdraw<T>(
189
195
  token: TimelineToken<T>,
190
196
  ): Timeline<T extends TimelineManageable ? T : never>
191
197
 
192
- export function withdraw<T>(
198
+ export function withdraw<T, E>(
193
199
  store: Store,
194
- token: WritableToken<T>,
195
- ): WritableState<T>
196
- export function withdraw<T>(
200
+ token: WritableToken<T, any, E>,
201
+ ): WritableState<T, E>
202
+ export function withdraw<T, E>(
197
203
  store: Store,
198
- token: ReadableToken<T>,
199
- ): ReadableState<T>
204
+ token: ReadableToken<T, any, E>,
205
+ ): ReadableState<T, E>
200
206
 
201
207
  export function withdraw(
202
208
  store: Store,
@@ -2,7 +2,10 @@ import type { ReadableState } from ".."
2
2
  import { newest } from "../lineage"
3
3
  import type { Store } from "../store"
4
4
 
5
- export const recallState = <T>(store: Store, state: ReadableState<T>): T => {
5
+ export const recallState = <T, E>(
6
+ store: Store,
7
+ state: ReadableState<T, E>,
8
+ ): T => {
6
9
  const target = newest(store)
7
10
  if (target.operation.open) {
8
11
  return target.operation.prev.get(state.key)
@@ -5,8 +5,8 @@ import { recallState } from "./recall-state"
5
5
 
6
6
  export const subscribeToRootDependency = (
7
7
  target: Store,
8
- selector: Selector<any>,
9
- atom: Atom<any>,
8
+ selector: Selector<any, any>,
9
+ atom: Atom<any, any>,
10
10
  ): (() => void) => {
11
11
  return atom.subject.subscribe(
12
12
  `${selector.type}:${selector.key}`,
@@ -7,11 +7,11 @@ import type { Store } from "../store"
7
7
  import { withdraw } from "../store"
8
8
  import { subscribeToRootDependency } from "./subscribe-to-root-atoms"
9
9
 
10
- export function subscribeToState<T>(
10
+ export function subscribeToState<T, E>(
11
11
  store: Store,
12
- token: ReadableToken<T>,
12
+ token: ReadableToken<T, any, E>,
13
13
  key: string,
14
- handleUpdate: UpdateHandler<T>,
14
+ handleUpdate: UpdateHandler<E | T>,
15
15
  ): () => void {
16
16
  function safelyHandleUpdate(update: StateUpdate<any>): void {
17
17
  if (store.operation.open) {
@@ -33,7 +33,7 @@ export function subscribeToState<T>(
33
33
  state.type === `writable_pure_selector` ||
34
34
  state.type === `readonly_pure_selector`
35
35
  const rootSubs = new Map<string, () => void>()
36
- let updateHandler: UpdateHandler<T> = safelyHandleUpdate
36
+ let updateHandler: UpdateHandler<E | T> = safelyHandleUpdate
37
37
  if (isSelector) {
38
38
  readOrComputeValue(store, state)
39
39
  for (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {
@@ -63,7 +63,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
63
63
  case `atom`:
64
64
  case `mutable_atom`:
65
65
  {
66
- const atomToken: AtomToken<ManagedAtom> = initialTopic
66
+ const atomToken: AtomToken<any, any, any> = initialTopic
67
67
  const atomKey = atomToken.key
68
68
  let existingTimelineKey = target.timelineTopics.getRelatedKey(atomKey)
69
69
  if (`family` in atomToken) {
@@ -95,7 +95,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
95
95
  case `atom_family`:
96
96
  case `mutable_atom_family`:
97
97
  {
98
- const familyToken: AtomFamilyToken<any, any> = initialTopic
98
+ const familyToken: AtomFamilyToken<any, any, any> = initialTopic
99
99
  const familyKey = familyToken.key
100
100
  const existingTimelineKey =
101
101
  target.timelineTopics.getRelatedKey(familyKey)
@@ -125,7 +125,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
125
125
 
126
126
  function addAtomToTimeline(
127
127
  store: Store,
128
- atomToken: AtomToken<any>,
128
+ atomToken: AtomToken<any, any, any>,
129
129
  tl: Timeline<any>,
130
130
  ): void {
131
131
  reduceReference(store, atomToken)
@@ -214,7 +214,7 @@ function addAtomToTimeline(
214
214
 
215
215
  function addAtomFamilyToTimeline(
216
216
  store: Store,
217
- atomFamilyToken: AtomFamilyToken<any, any>,
217
+ atomFamilyToken: AtomFamilyToken<any, any, any>,
218
218
  tl: Timeline<any>,
219
219
  ): void {
220
220
  const family = withdraw(store, atomFamilyToken)
@@ -283,7 +283,7 @@ function joinTransaction(
283
283
  function buildSelectorUpdate(
284
284
  store: Store,
285
285
  tl: Timeline<any>,
286
- atomToken: AtomToken<any>,
286
+ atomToken: AtomToken<any, any, any>,
287
287
  eventOrUpdate: StateCreationEvent<any> | StateUpdate<any>,
288
288
  currentSelectorToken: WritablePureSelectorToken<any>,
289
289
  currentSelectorTime: number,
@@ -1,5 +1,7 @@
1
1
  export type Fn = (...parameters: any[]) => any
2
2
 
3
+ export type Ctor<T> = new (...args: any[]) => T
4
+
3
5
  export type Flat<R extends { [K in PropertyKey]: any }> = {
4
6
  [K in keyof R]: R[K]
5
7
  }
@@ -8,10 +8,10 @@ import {
8
8
 
9
9
  import type { WritableTokenIndex } from "."
10
10
 
11
- export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>
11
+ export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown, any, unknown>>
12
12
 
13
13
  export const attachAtomIndex = (store: Store): AtomToken<AtomTokenIndex> => {
14
- return createRegularAtom<AtomTokenIndex>(
14
+ return createRegularAtom<AtomTokenIndex, never, never>(
15
15
  store,
16
16
  {
17
17
  key: `🔍 Atom Token Index`,
@@ -8,12 +8,14 @@ import {
8
8
 
9
9
  import type { WritableTokenIndex } from "."
10
10
 
11
- export type SelectorTokenIndex = WritableTokenIndex<SelectorToken<unknown>>
11
+ export type SelectorTokenIndex = WritableTokenIndex<
12
+ SelectorToken<unknown, any, any>
13
+ >
12
14
 
13
15
  export const attachSelectorIndex = (
14
16
  store: Store,
15
17
  ): AtomToken<SelectorTokenIndex> => {
16
- return createRegularAtom<SelectorTokenIndex>(
18
+ return createRegularAtom<SelectorTokenIndex, never, never>(
17
19
  store,
18
20
  {
19
21
  key: `🔍 Selector Token Index`,
@@ -11,7 +11,8 @@ export const attachTimelineFamily = (
11
11
  ): ReadonlyPureSelectorFamilyToken<Timeline<any>, string> => {
12
12
  const findTimelineLogState__INTERNAL = createRegularAtomFamily<
13
13
  Timeline<any>,
14
- string
14
+ string,
15
+ never
15
16
  >(store, {
16
17
  key: `🔍 Timeline Update Log (Internal)`,
17
18
  default: (key) =>
@@ -36,15 +37,16 @@ export const attachTimelineFamily = (
36
37
  },
37
38
  ],
38
39
  })
39
- const findTimelineLogState = createSelectorFamily<Timeline<any>, string>(
40
- store,
41
- {
42
- key: `🔍 Timeline Update Log`,
43
- get:
44
- (key) =>
45
- ({ get }) =>
46
- get(findTimelineLogState__INTERNAL, key),
47
- },
48
- )
40
+ const findTimelineLogState = createSelectorFamily<
41
+ Timeline<any>,
42
+ string,
43
+ never
44
+ >(store, {
45
+ key: `🔍 Timeline Update Log`,
46
+ get:
47
+ (key) =>
48
+ ({ get }) =>
49
+ get(findTimelineLogState__INTERNAL, key),
50
+ })
49
51
  return findTimelineLogState
50
52
  }
@@ -5,7 +5,7 @@ import { createRegularAtom } from "atom.io/internal"
5
5
  export const attachTimelineIndex = (
6
6
  store: Store,
7
7
  ): AtomToken<TimelineToken<any>[]> => {
8
- return createRegularAtom<TimelineToken<any>[]>(
8
+ return createRegularAtom<TimelineToken<any>[], never, never>(
9
9
  store,
10
10
  {
11
11
  key: `🔍 Timeline Token Index`,
@@ -5,7 +5,7 @@ import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
5
5
  export const attachTransactionIndex = (
6
6
  store: Store,
7
7
  ): AtomToken<TransactionToken<Fn>[]> => {
8
- return createRegularAtom<TransactionToken<Fn>[]>(
8
+ return createRegularAtom<TransactionToken<Fn>[], never, never>(
9
9
  store,
10
10
  {
11
11
  key: `🔍 Transaction Token Index`,
@@ -14,7 +14,8 @@ export const attachTransactionLogs = (
14
14
  > => {
15
15
  const transactionUpdateLogAtoms = createRegularAtomFamily<
16
16
  TransactionOutcomeEvent<TransactionToken<any>>[],
17
- string
17
+ string,
18
+ never
18
19
  >(store, {
19
20
  key: `🔍 Transaction Update Log (Internal)`,
20
21
  default: () => [],
@@ -31,7 +32,8 @@ export const attachTransactionLogs = (
31
32
  })
32
33
  const findTransactionUpdateLogState = createSelectorFamily<
33
34
  TransactionOutcomeEvent<TransactionToken<any>>[],
34
- string
35
+ string,
36
+ never
35
37
  >(store, {
36
38
  key: `🔍 Transaction Update Log`,
37
39
  get:
@@ -9,7 +9,8 @@ export const attachTypeSelectors = (
9
9
  ): ReadonlyPureSelectorFamilyToken<Loadable<string>, string> => {
10
10
  const typeSelectors = createReadonlyPureSelectorFamily<
11
11
  Loadable<string>,
12
- string
12
+ string,
13
+ never
13
14
  >(store, {
14
15
  key: `🔍 State Type`,
15
16
  get:
@@ -6,12 +6,10 @@ export * from "./differ"
6
6
  export * from "./refinery"
7
7
  export * from "./sprawl"
8
8
 
9
- export type FamilyNode<Token extends ReadableToken<unknown>> = {
9
+ export type FamilyNode<Token extends ReadableToken<unknown, any, any>> = {
10
10
  key: string
11
11
  familyMembers: Map<string, Token>
12
12
  }
13
13
 
14
- export type WritableTokenIndex<Token extends ReadableToken<unknown>> = Map<
15
- string,
16
- FamilyNode<Token> | Token
17
- >
14
+ export type WritableTokenIndex<Token extends ReadableToken<unknown, any, any>> =
15
+ Map<string, FamilyNode<Token> | Token>