atom.io 0.37.0 → 0.37.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.
- package/dist/internal/index.d.ts +10 -9
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +21 -9
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/internal/atom/dispose-atom.ts +13 -7
- package/src/internal/families/create-regular-atom-family.ts +4 -1
- package/src/internal/get-state/get-from-store.ts +19 -6
- package/src/internal/index.ts +17 -29
- package/src/internal/mutable/create-mutable-atom-family.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.1",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"tsdown": "0.14.1",
|
|
100
100
|
"tsx": "4.20.4",
|
|
101
101
|
"typescript": "5.9.2",
|
|
102
|
-
"vite": "7.1.
|
|
102
|
+
"vite": "7.1.3",
|
|
103
103
|
"vite-tsconfig-paths": "5.1.4",
|
|
104
104
|
"vitest": "3.2.4",
|
|
105
105
|
"zod": "3.25.76",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { AtomDisposalEvent, AtomToken } from "atom.io"
|
|
1
|
+
import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { Store } from ".."
|
|
3
|
+
import type { Store, Subject } from ".."
|
|
4
4
|
import { getUpdateToken, isChildStore, newest, withdraw } from ".."
|
|
5
|
+
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
5
6
|
|
|
6
|
-
export function disposeAtom(store: Store, atomToken: AtomToken<
|
|
7
|
+
export function disposeAtom(store: Store, atomToken: AtomToken<any>): void {
|
|
7
8
|
const target = newest(store)
|
|
8
9
|
const { key, family } = atomToken
|
|
9
10
|
const atom = withdraw(target, atomToken)
|
|
@@ -12,9 +13,14 @@ export function disposeAtom(store: Store, atomToken: AtomToken<unknown>): void {
|
|
|
12
13
|
} else {
|
|
13
14
|
atom.cleanup?.()
|
|
14
15
|
const lastValue = store.valueMap.get(atom.key)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
// biome-ignore lint/style/noNonNullAssertion: family has been verified
|
|
17
|
+
const familyToken = getFamilyOfToken(store, atomToken)!
|
|
18
|
+
const atomFamily = withdraw(store, familyToken)
|
|
19
|
+
const subject = atomFamily.subject as Subject<
|
|
20
|
+
StateLifecycleEvent<AtomToken<any>>
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
const disposal: AtomDisposalEvent<AtomToken<any>> = {
|
|
18
24
|
type: `state_disposal`,
|
|
19
25
|
subType: `atom`,
|
|
20
26
|
token: atomToken,
|
|
@@ -22,7 +28,7 @@ export function disposeAtom(store: Store, atomToken: AtomToken<unknown>): void {
|
|
|
22
28
|
timestamp: Date.now(),
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
subject.next(disposal)
|
|
26
32
|
|
|
27
33
|
const isChild = isChildStore(target)
|
|
28
34
|
|
|
@@ -61,12 +61,15 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const atomFamily = Object.assign(familyFunction, familyToken, {
|
|
64
|
+
default: options.default,
|
|
64
65
|
subject,
|
|
65
66
|
install: (s: Store) => createRegularAtomFamily(s, options),
|
|
66
67
|
internalRoles,
|
|
67
68
|
}) satisfies RegularAtomFamily<T, K>
|
|
68
69
|
|
|
69
70
|
store.families.set(options.key, atomFamily)
|
|
70
|
-
|
|
71
|
+
if (options.default instanceof Function === false) {
|
|
72
|
+
store.defaults.set(options.key, options.default)
|
|
73
|
+
}
|
|
71
74
|
return familyToken
|
|
72
75
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
2
|
-
import type
|
|
2
|
+
import { type Canonical, parseJson } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import { findInStore } from "../families"
|
|
5
5
|
import type { Store } from "../store"
|
|
@@ -47,9 +47,23 @@ export function getFromStore(
|
|
|
47
47
|
: `No previous disposal trace was found.`,
|
|
48
48
|
)
|
|
49
49
|
switch (family.type) {
|
|
50
|
-
case `
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
case `mutable_atom_family`: {
|
|
51
|
+
if (store.defaults.has(family.key)) {
|
|
52
|
+
return store.defaults.get(family.key)
|
|
53
|
+
}
|
|
54
|
+
const mutableFamily = withdraw(store, family)
|
|
55
|
+
const defaultValue = new mutableFamily.class()
|
|
56
|
+
store.defaults.set(family.key, defaultValue)
|
|
57
|
+
return defaultValue
|
|
58
|
+
}
|
|
59
|
+
case `atom_family`: {
|
|
60
|
+
if (store.defaults.has(family.key)) {
|
|
61
|
+
return store.defaults.get(token.family.key)
|
|
62
|
+
}
|
|
63
|
+
const defaultValue = withdraw(store, family).default(parseJson(subKey))
|
|
64
|
+
store.defaults.set(family.key, defaultValue)
|
|
65
|
+
return defaultValue
|
|
66
|
+
}
|
|
53
67
|
case `readonly_pure_selector_family`:
|
|
54
68
|
case `writable_pure_selector_family`:
|
|
55
69
|
case `readonly_held_selector_family`:
|
|
@@ -57,8 +71,7 @@ export function getFromStore(
|
|
|
57
71
|
if (store.defaults.has(family.key)) {
|
|
58
72
|
return store.defaults.get(token.family.key)
|
|
59
73
|
}
|
|
60
|
-
|
|
61
|
-
const defaultValue = withdraw(store, family).default(subKey)
|
|
74
|
+
const defaultValue = withdraw(store, family).default(parseJson(subKey))
|
|
62
75
|
store.defaults.set(family.key, defaultValue)
|
|
63
76
|
return defaultValue
|
|
64
77
|
}
|
package/src/internal/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
AtomToken,
|
|
3
2
|
FamilyMetadata,
|
|
4
3
|
MutableAtomFamilyToken,
|
|
5
4
|
MutableAtomToken,
|
|
@@ -9,8 +8,6 @@ import type {
|
|
|
9
8
|
ReadonlyPureSelectorToken,
|
|
10
9
|
RegularAtomFamilyToken,
|
|
11
10
|
RegularAtomToken,
|
|
12
|
-
StateCreationEvent,
|
|
13
|
-
StateDisposalEvent,
|
|
14
11
|
StateLifecycleEvent,
|
|
15
12
|
StateUpdate,
|
|
16
13
|
WritableHeldSelectorFamilyToken,
|
|
@@ -131,23 +128,26 @@ export type ReadableState<T> = Atom<T> | Selector<T>
|
|
|
131
128
|
|
|
132
129
|
// biome-ignore format: intersection
|
|
133
130
|
export type RegularAtomFamily<T, K extends Canonical> =
|
|
134
|
-
&
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
& Flat<
|
|
132
|
+
& RegularAtomFamilyToken<T, K>
|
|
133
|
+
& {
|
|
134
|
+
default: T | ((key: K) => T)
|
|
135
|
+
install: (store: Store) => void
|
|
136
|
+
internalRoles: string[] | undefined
|
|
137
|
+
subject: Subject<StateLifecycleEvent<RegularAtomToken<T>>>
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
& ((key: K) => RegularAtomToken<T>)
|
|
141
141
|
|
|
142
142
|
// biome-ignore format: intersection
|
|
143
143
|
export type MutableAtomFamily<
|
|
144
|
-
// C extends TransceiverConstructor<any,any>,
|
|
145
144
|
T extends Transceiver<any, any, any>,
|
|
146
145
|
K extends Canonical,
|
|
147
146
|
> =
|
|
148
147
|
& Flat<
|
|
149
148
|
& MutableAtomFamilyToken<T, K>
|
|
150
149
|
& {
|
|
150
|
+
class: ConstructorOf<T>
|
|
151
151
|
install: (store: Store) => void
|
|
152
152
|
internalRoles: string[] | undefined
|
|
153
153
|
subject: Subject<StateLifecycleEvent<MutableAtomToken<T>>>
|
|
@@ -167,13 +167,10 @@ export type WritablePureSelectorFamily<T, K extends Canonical> =
|
|
|
167
167
|
default: (key: K) => T,
|
|
168
168
|
install: (store: Store) => void
|
|
169
169
|
internalRoles: string[] | undefined
|
|
170
|
-
subject: Subject<
|
|
171
|
-
| StateCreationEvent<WritablePureSelectorToken<T>>
|
|
172
|
-
| StateDisposalEvent<WritablePureSelectorToken<T>>
|
|
173
|
-
>
|
|
170
|
+
subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T>>>
|
|
174
171
|
}
|
|
175
172
|
>
|
|
176
|
-
|
|
173
|
+
& ((key: K) => WritablePureSelectorToken<T>)
|
|
177
174
|
|
|
178
175
|
// biome-ignore format: intersection
|
|
179
176
|
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
@@ -183,13 +180,10 @@ export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
|
183
180
|
default: (key: K) => T,
|
|
184
181
|
install: (store: Store) => void
|
|
185
182
|
internalRoles: string[] | undefined
|
|
186
|
-
subject: Subject<
|
|
187
|
-
| StateCreationEvent<WritableHeldSelectorToken<T>>
|
|
188
|
-
| StateDisposalEvent<WritableHeldSelectorToken<T>>
|
|
189
|
-
>
|
|
183
|
+
subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T>>>
|
|
190
184
|
}
|
|
191
185
|
>
|
|
192
|
-
|
|
186
|
+
& ((key: K) => WritableHeldSelectorToken<T>)
|
|
193
187
|
|
|
194
188
|
// biome-ignore format: intersection
|
|
195
189
|
export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
@@ -199,10 +193,7 @@ export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
|
199
193
|
default: (key: K) => T,
|
|
200
194
|
install: (store: Store) => void
|
|
201
195
|
internalRoles: string[] | undefined
|
|
202
|
-
subject: Subject<
|
|
203
|
-
| StateCreationEvent<ReadonlyPureSelectorToken<T>>
|
|
204
|
-
| StateDisposalEvent<ReadonlyPureSelectorToken<T>>
|
|
205
|
-
>
|
|
196
|
+
subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T>>>
|
|
206
197
|
}
|
|
207
198
|
>
|
|
208
199
|
& ((key: K) => ReadonlyPureSelectorToken<T>)
|
|
@@ -215,10 +206,7 @@ export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
|
215
206
|
default: (key: K) => T,
|
|
216
207
|
install: (store: Store) => void
|
|
217
208
|
internalRoles: string[] | undefined
|
|
218
|
-
subject: Subject<
|
|
219
|
-
| StateCreationEvent<ReadonlyHeldSelectorToken<T>>
|
|
220
|
-
| StateDisposalEvent<ReadonlyHeldSelectorToken<T>>
|
|
221
|
-
>
|
|
209
|
+
subject: Subject<StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>>
|
|
222
210
|
}
|
|
223
211
|
>
|
|
224
212
|
& ((key: K) => ReadonlyHeldSelectorToken<T>)
|