atom.io 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint-plugin/index.d.ts +2 -18
- package/dist/eslint-plugin/index.d.ts.map +1 -1
- package/dist/eslint-plugin/index.js +4 -141
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +47 -41
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +95 -78
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +2 -10
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -31
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +24 -23
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +9 -9
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/realtime/index.d.ts +4 -4
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +2 -6
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +2 -2
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +2 -2
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +18 -18
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +5 -9
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +5 -5
- package/src/eslint-plugin/index.ts +0 -1
- package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
- package/src/eslint-plugin/rules/index.ts +0 -1
- package/src/internal/atom/dispose-atom.ts +1 -0
- package/src/internal/families/find-in-store.ts +4 -5
- package/src/internal/families/get-family-of-token.ts +4 -5
- package/src/internal/families/init-family-member.ts +3 -4
- package/src/internal/families/seek-in-store.ts +4 -5
- package/src/internal/get-state/read-or-compute-value.ts +14 -2
- package/src/internal/index.ts +19 -21
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
- package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/join-internal.ts +3 -14
- package/src/internal/molecule.ts +1 -0
- package/src/internal/mutable/create-mutable-atom-family.ts +37 -20
- package/src/internal/mutable/create-mutable-atom.ts +16 -12
- package/src/internal/mutable/get-json-family.ts +7 -6
- package/src/internal/mutable/get-json-token.ts +6 -13
- package/src/internal/mutable/get-update-family.ts +7 -8
- package/src/internal/mutable/get-update-token.ts +5 -9
- package/src/internal/mutable/tracker-family.ts +10 -13
- package/src/internal/mutable/tracker.ts +66 -90
- package/src/internal/mutable/transceiver.ts +35 -8
- package/src/internal/selector/dispose-selector.ts +9 -9
- package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
- package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/store/counterfeit.ts +3 -4
- package/src/internal/store/deposit.ts +7 -9
- package/src/internal/store/store.ts +2 -2
- package/src/internal/store/withdraw.ts +7 -11
- package/src/json/index.ts +0 -2
- package/src/main/atom.ts +24 -36
- package/src/main/dispose-state.ts +4 -4
- package/src/main/find-state.ts +3 -4
- package/src/main/join.ts +2 -2
- package/src/main/logger.ts +7 -7
- package/src/main/tokens.ts +9 -11
- package/src/main/transaction.ts +11 -5
- package/src/main/validators.ts +1 -1
- package/src/react/use-json.ts +15 -25
- package/src/realtime/shared-room-store.ts +11 -22
- package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
- package/src/realtime-client/pull-mutable-atom.ts +5 -9
- package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
- package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
- package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
- package/src/realtime-server/realtime-mutable-provider.ts +2 -3
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -15
- package/src/transceivers/set-rtx/set-rtx.ts +1 -1
- package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
- package/src/eslint-plugin/walk.ts +0 -81
- package/src/json/select-json-family.ts +0 -55
- package/src/json/select-json.ts +0 -19
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
WritablePureSelectorToken,
|
|
17
17
|
WritableToken,
|
|
18
18
|
} from "atom.io"
|
|
19
|
-
import type { Canonical
|
|
19
|
+
import type { Canonical } from "atom.io/json"
|
|
20
20
|
import { stringifyJson } from "atom.io/json"
|
|
21
21
|
|
|
22
22
|
import type { Molecule, ReadableState } from ".."
|
|
@@ -25,15 +25,14 @@ import type { Transceiver } from "../mutable"
|
|
|
25
25
|
import { deposit, type Store } from "../store"
|
|
26
26
|
|
|
27
27
|
export function seekInStore<
|
|
28
|
-
T extends Transceiver<any>,
|
|
29
|
-
J extends Json.Serializable,
|
|
28
|
+
T extends Transceiver<any, any>,
|
|
30
29
|
K extends Canonical,
|
|
31
30
|
Key extends K,
|
|
32
31
|
>(
|
|
33
32
|
store: Store,
|
|
34
|
-
token: MutableAtomFamilyToken<T,
|
|
33
|
+
token: MutableAtomFamilyToken<T, K>,
|
|
35
34
|
key: Key,
|
|
36
|
-
): MutableAtomToken<T,
|
|
35
|
+
): MutableAtomToken<T, K> | undefined
|
|
37
36
|
|
|
38
37
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
39
38
|
store: Store,
|
|
@@ -16,8 +16,7 @@ export const readOrComputeValue = <T>(
|
|
|
16
16
|
case `writable_pure_selector`:
|
|
17
17
|
target.logger.info(`🧮`, state.type, state.key, `computing value`)
|
|
18
18
|
return state.get()
|
|
19
|
-
case `atom`:
|
|
20
|
-
case `mutable_atom`: {
|
|
19
|
+
case `atom`: {
|
|
21
20
|
const def = state.default
|
|
22
21
|
let defaultValue: T
|
|
23
22
|
if (def instanceof Function) {
|
|
@@ -40,5 +39,18 @@ export const readOrComputeValue = <T>(
|
|
|
40
39
|
)
|
|
41
40
|
return cachedValue
|
|
42
41
|
}
|
|
42
|
+
case `mutable_atom`: {
|
|
43
|
+
const Ctor = state.class
|
|
44
|
+
const instance = new Ctor()
|
|
45
|
+
const cachedValue = cacheValue(target, state.key, instance, state.subject)
|
|
46
|
+
target.logger.info(
|
|
47
|
+
`💁`,
|
|
48
|
+
`mutable_atom`,
|
|
49
|
+
state.key,
|
|
50
|
+
`could not find cached value; using default`,
|
|
51
|
+
instance,
|
|
52
|
+
)
|
|
53
|
+
return cachedValue
|
|
54
|
+
}
|
|
43
55
|
}
|
|
44
56
|
}
|
package/src/internal/index.ts
CHANGED
|
@@ -16,9 +16,9 @@ import type {
|
|
|
16
16
|
WritablePureSelectorFamilyToken,
|
|
17
17
|
WritablePureSelectorToken,
|
|
18
18
|
} from "atom.io"
|
|
19
|
-
import type { Canonical
|
|
19
|
+
import type { Canonical } from "atom.io/json"
|
|
20
20
|
|
|
21
|
-
import type { Transceiver } from "./mutable"
|
|
21
|
+
import type { ConstructorOf, Transceiver } from "./mutable"
|
|
22
22
|
import type { Store } from "./store"
|
|
23
23
|
import type { Subject } from "./subject"
|
|
24
24
|
import type { Timeline } from "./timeline"
|
|
@@ -69,20 +69,16 @@ export type RegularAtom<T> = Flat<
|
|
|
69
69
|
cleanup?: () => void
|
|
70
70
|
}
|
|
71
71
|
>
|
|
72
|
-
export type MutableAtom<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
type: `mutable_atom`
|
|
79
|
-
default: () => T
|
|
80
|
-
cleanup?: () => void
|
|
81
|
-
}
|
|
72
|
+
export type MutableAtom<T extends Transceiver<any, any>> = Flat<
|
|
73
|
+
AtomIOState & {
|
|
74
|
+
type: `mutable_atom`
|
|
75
|
+
class: ConstructorOf<T>
|
|
76
|
+
cleanup?: () => void
|
|
77
|
+
}
|
|
82
78
|
>
|
|
83
79
|
export type Atom<T> =
|
|
84
80
|
| RegularAtom<T>
|
|
85
|
-
| (T extends Transceiver<any> ? MutableAtom<T
|
|
81
|
+
| (T extends Transceiver<any, any> ? MutableAtom<T> : never)
|
|
86
82
|
|
|
87
83
|
export type WritableHeldSelector<T> = Flat<
|
|
88
84
|
AtomIOState & {
|
|
@@ -141,23 +137,25 @@ export type RegularAtomFamily<T, K extends Canonical> =
|
|
|
141
137
|
|
|
142
138
|
// biome-ignore format: intersection
|
|
143
139
|
export type MutableAtomFamily<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
K extends Canonical,
|
|
140
|
+
// C extends TransceiverConstructor<any,any>,
|
|
141
|
+
T extends Transceiver<any,any>,
|
|
142
|
+
K extends Canonical,
|
|
147
143
|
> =
|
|
148
144
|
& Flat<
|
|
149
|
-
&
|
|
150
|
-
& MutableAtomFamilyToken<T, J, K>
|
|
145
|
+
& MutableAtomFamilyToken<T, K>
|
|
151
146
|
& {
|
|
152
147
|
install: (store: Store) => void
|
|
153
148
|
internalRoles: string[] | undefined
|
|
154
|
-
subject: Subject<
|
|
149
|
+
subject: Subject<
|
|
150
|
+
| StateCreation<MutableAtomToken<T>>
|
|
151
|
+
| StateDisposal<MutableAtomToken<T>>
|
|
152
|
+
>
|
|
155
153
|
}
|
|
156
154
|
>
|
|
157
|
-
& ((key: K) => MutableAtomToken<T
|
|
155
|
+
& ((key: K) => MutableAtomToken<T>)
|
|
158
156
|
|
|
159
157
|
export type AtomFamily<T, K extends Canonical = Canonical> =
|
|
160
|
-
| MutableAtomFamily<T extends Transceiver<any> ? T : never,
|
|
158
|
+
| MutableAtomFamily<T extends Transceiver<any, any> ? T : never, K>
|
|
161
159
|
| RegularAtomFamily<T, K>
|
|
162
160
|
|
|
163
161
|
// biome-ignore format: intersection
|
|
@@ -115,25 +115,28 @@ export function ingestMoleculeTransferEvent(
|
|
|
115
115
|
switch (applying) {
|
|
116
116
|
case `newValue`:
|
|
117
117
|
{
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
for (const newOwner of update.to) {
|
|
119
|
+
claimWithinStore<any, any, any>(
|
|
120
|
+
store,
|
|
121
|
+
newOwner,
|
|
122
|
+
update.key,
|
|
123
|
+
update.exclusive ? `exclusive` : undefined,
|
|
124
|
+
)
|
|
125
|
+
}
|
|
125
126
|
}
|
|
126
127
|
break
|
|
127
128
|
case `oldValue`:
|
|
128
129
|
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
let exclusivity: `exclusive` | undefined = `exclusive`
|
|
131
|
+
for (const previousOwner of update.from) {
|
|
132
|
+
claimWithinStore<any, any, any>(
|
|
133
|
+
store,
|
|
134
|
+
previousOwner,
|
|
135
|
+
update.key,
|
|
136
|
+
exclusivity,
|
|
137
|
+
)
|
|
138
|
+
exclusivity = undefined
|
|
139
|
+
}
|
|
137
140
|
}
|
|
138
141
|
break
|
|
139
142
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { TimelineManageable } from "atom.io"
|
|
2
|
+
|
|
1
3
|
import type { Store } from "../store"
|
|
2
|
-
import type { TimelineSelectorUpdate } from "../timeline"
|
|
4
|
+
import type { TimelineAtomUpdate, TimelineSelectorUpdate } from "../timeline"
|
|
3
5
|
import { ingestAtomUpdate } from "./ingest-atom-update"
|
|
4
6
|
|
|
5
7
|
export function ingestSelectorUpdate(
|
|
@@ -7,10 +9,12 @@ export function ingestSelectorUpdate(
|
|
|
7
9
|
selectorUpdate: TimelineSelectorUpdate<any>,
|
|
8
10
|
store: Store,
|
|
9
11
|
): void {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let updates: Omit<TimelineAtomUpdate<TimelineManageable>, `timestamp`>[]
|
|
13
|
+
if (applying === `newValue`) {
|
|
14
|
+
updates = selectorUpdate.atomUpdates
|
|
15
|
+
} else {
|
|
16
|
+
updates = selectorUpdate.atomUpdates.toReversed()
|
|
17
|
+
}
|
|
14
18
|
for (const atomUpdate of updates) {
|
|
15
19
|
ingestAtomUpdate(applying, atomUpdate, store)
|
|
16
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JoinToken, MutableAtomFamilyToken } from "atom.io"
|
|
2
|
-
import type { SetRTX
|
|
2
|
+
import type { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
3
3
|
|
|
4
4
|
import type { Store } from "../store"
|
|
5
5
|
import { getJoin } from "./get-join"
|
|
@@ -7,7 +7,7 @@ import { getJoin } from "./get-join"
|
|
|
7
7
|
export function getInternalRelationsFromStore(
|
|
8
8
|
token: JoinToken<any, any, any, any, any, any>,
|
|
9
9
|
store: Store,
|
|
10
|
-
): MutableAtomFamilyToken<SetRTX<string>,
|
|
10
|
+
): MutableAtomFamilyToken<SetRTX<string>, string> {
|
|
11
11
|
const myJoin = getJoin(token, store)
|
|
12
12
|
const family = myJoin.core.relatedKeysAtoms
|
|
13
13
|
return family
|
|
@@ -14,7 +14,6 @@ import type {
|
|
|
14
14
|
import { Anarchy } from "atom.io"
|
|
15
15
|
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
16
16
|
import { stringifyJson } from "atom.io/json"
|
|
17
|
-
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
18
17
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
19
18
|
|
|
20
19
|
import { capitalize } from "../capitalize"
|
|
@@ -143,11 +142,7 @@ export class Join<
|
|
|
143
142
|
Content
|
|
144
143
|
>
|
|
145
144
|
public core: {
|
|
146
|
-
relatedKeysAtoms: MutableAtomFamilyToken<
|
|
147
|
-
SetRTX<string>,
|
|
148
|
-
SetRTXJson<string>,
|
|
149
|
-
string
|
|
150
|
-
>
|
|
145
|
+
relatedKeysAtoms: MutableAtomFamilyToken<SetRTX<string>, string>
|
|
151
146
|
}
|
|
152
147
|
public transact(
|
|
153
148
|
toolkit: WriterToolkit,
|
|
@@ -193,17 +188,11 @@ export class Join<
|
|
|
193
188
|
|
|
194
189
|
const aSide: ASide = options.between[0]
|
|
195
190
|
const bSide: BSide = options.between[1]
|
|
196
|
-
const relatedKeysAtoms = createMutableAtomFamily<
|
|
197
|
-
SetRTX<string>,
|
|
198
|
-
SetRTXJson<string>,
|
|
199
|
-
string
|
|
200
|
-
>(
|
|
191
|
+
const relatedKeysAtoms = createMutableAtomFamily<SetRTX<string>, string>(
|
|
201
192
|
store,
|
|
202
193
|
{
|
|
203
194
|
key: `${options.key}/relatedKeys`,
|
|
204
|
-
|
|
205
|
-
fromJson: (json) => SetRTX.fromJSON(json),
|
|
206
|
-
toJson: (set) => set.toJSON(),
|
|
195
|
+
class: SetRTX,
|
|
207
196
|
},
|
|
208
197
|
[`join`, `relations`],
|
|
209
198
|
)
|
package/src/internal/molecule.ts
CHANGED
|
@@ -7,30 +7,33 @@ import type {
|
|
|
7
7
|
StateCreation,
|
|
8
8
|
StateDisposal,
|
|
9
9
|
} from "atom.io"
|
|
10
|
-
import type { Canonical
|
|
11
|
-
import {
|
|
10
|
+
import type { Canonical } from "atom.io/json"
|
|
11
|
+
import { stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
createWritablePureSelectorFamily,
|
|
15
|
+
type MutableAtomFamily,
|
|
16
|
+
prettyPrintTokenType,
|
|
17
|
+
} from ".."
|
|
14
18
|
import { newest } from "../lineage"
|
|
15
19
|
import { createMutableAtom } from "../mutable"
|
|
16
20
|
import type { Store } from "../store"
|
|
17
21
|
import { Subject } from "../subject"
|
|
18
22
|
import { FamilyTracker } from "./tracker-family"
|
|
19
|
-
import type { Transceiver } from "./transceiver"
|
|
23
|
+
import type { AsJSON, Transceiver } from "./transceiver"
|
|
20
24
|
|
|
21
25
|
export function createMutableAtomFamily<
|
|
22
|
-
T extends Transceiver<any>,
|
|
23
|
-
J extends Json.Serializable,
|
|
26
|
+
T extends Transceiver<any, any>,
|
|
24
27
|
K extends Canonical,
|
|
25
28
|
>(
|
|
26
29
|
store: Store,
|
|
27
|
-
options: MutableAtomFamilyOptions<T,
|
|
30
|
+
options: MutableAtomFamilyOptions<T, K>,
|
|
28
31
|
internalRoles?: string[],
|
|
29
|
-
): MutableAtomFamilyToken<T,
|
|
30
|
-
const familyToken = {
|
|
32
|
+
): MutableAtomFamilyToken<T, K> {
|
|
33
|
+
const familyToken: MutableAtomFamilyToken<T & Transceiver<any, any>, K> = {
|
|
31
34
|
key: options.key,
|
|
32
35
|
type: `mutable_atom_family`,
|
|
33
|
-
}
|
|
36
|
+
}
|
|
34
37
|
|
|
35
38
|
const existing = store.families.get(options.key)
|
|
36
39
|
if (existing) {
|
|
@@ -45,20 +48,18 @@ export function createMutableAtomFamily<
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
const subject = new Subject<
|
|
48
|
-
StateCreation<MutableAtomToken<T
|
|
51
|
+
StateCreation<MutableAtomToken<T>> | StateDisposal<MutableAtomToken<T>>
|
|
49
52
|
>()
|
|
50
53
|
|
|
51
|
-
const familyFunction = (key: K): MutableAtomToken<T
|
|
54
|
+
const familyFunction = (key: K): MutableAtomToken<T> => {
|
|
52
55
|
const subKey = stringifyJson(key)
|
|
53
56
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
54
57
|
const fullKey = `${options.key}(${subKey})`
|
|
55
58
|
const target = newest(store)
|
|
56
59
|
|
|
57
|
-
const individualOptions: MutableAtomOptions<T
|
|
60
|
+
const individualOptions: MutableAtomOptions<T> = {
|
|
58
61
|
key: fullKey,
|
|
59
|
-
|
|
60
|
-
toJson: options.toJson,
|
|
61
|
-
fromJson: options.fromJson,
|
|
62
|
+
class: options.class,
|
|
62
63
|
}
|
|
63
64
|
if (options.effects) {
|
|
64
65
|
individualOptions.effects = options.effects(key)
|
|
@@ -73,13 +74,29 @@ export function createMutableAtomFamily<
|
|
|
73
74
|
const atomFamily = Object.assign(familyFunction, familyToken, {
|
|
74
75
|
subject,
|
|
75
76
|
install: (s: Store) => createMutableAtomFamily(s, options),
|
|
76
|
-
toJson: options.toJson,
|
|
77
|
-
fromJson: options.fromJson,
|
|
78
77
|
internalRoles,
|
|
79
|
-
}) satisfies MutableAtomFamily<T,
|
|
78
|
+
}) satisfies MutableAtomFamily<T, K>
|
|
80
79
|
|
|
81
80
|
store.families.set(options.key, atomFamily)
|
|
82
|
-
|
|
81
|
+
|
|
82
|
+
createWritablePureSelectorFamily<AsJSON<T>, K>(
|
|
83
|
+
store,
|
|
84
|
+
{
|
|
85
|
+
key: `${options.key}:JSON`,
|
|
86
|
+
get:
|
|
87
|
+
(key) =>
|
|
88
|
+
({ get }) =>
|
|
89
|
+
get(familyToken, key).toJSON(),
|
|
90
|
+
set:
|
|
91
|
+
(key) =>
|
|
92
|
+
({ set }, newValue) => {
|
|
93
|
+
set(familyToken, key, options.class.fromJSON(newValue))
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
[`mutable`, `json`],
|
|
97
|
+
)
|
|
98
|
+
|
|
83
99
|
new FamilyTracker(atomFamily, store)
|
|
100
|
+
|
|
84
101
|
return familyToken
|
|
85
102
|
}
|
|
@@ -4,11 +4,9 @@ import type {
|
|
|
4
4
|
MutableAtomToken,
|
|
5
5
|
UpdateHandler,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import type { Json } from "atom.io/json"
|
|
8
|
-
import { selectJson } from "atom.io/json"
|
|
9
7
|
|
|
10
8
|
import type { MutableAtom } from ".."
|
|
11
|
-
import { resetInStore, setIntoStore } from ".."
|
|
9
|
+
import { createStandaloneSelector, resetInStore, setIntoStore } from ".."
|
|
12
10
|
import { newest } from "../lineage"
|
|
13
11
|
import { deposit, type Store } from "../store"
|
|
14
12
|
import { Subject } from "../subject"
|
|
@@ -16,14 +14,11 @@ import { subscribeToState } from "../subscribe"
|
|
|
16
14
|
import { Tracker } from "./tracker"
|
|
17
15
|
import type { Transceiver } from "./transceiver"
|
|
18
16
|
|
|
19
|
-
export function createMutableAtom<
|
|
20
|
-
T extends Transceiver<any>,
|
|
21
|
-
J extends Json.Serializable,
|
|
22
|
-
>(
|
|
17
|
+
export function createMutableAtom<T extends Transceiver<any, any>>(
|
|
23
18
|
store: Store,
|
|
24
|
-
options: MutableAtomOptions<T
|
|
19
|
+
options: MutableAtomOptions<T>,
|
|
25
20
|
family: FamilyMetadata | undefined,
|
|
26
|
-
): MutableAtomToken<T
|
|
21
|
+
): MutableAtomToken<T> {
|
|
27
22
|
store.logger.info(
|
|
28
23
|
`🔨`,
|
|
29
24
|
`atom`,
|
|
@@ -43,8 +38,11 @@ export function createMutableAtom<
|
|
|
43
38
|
)
|
|
44
39
|
return deposit(existing)
|
|
45
40
|
}
|
|
46
|
-
const subject = new Subject<{
|
|
47
|
-
|
|
41
|
+
const subject = new Subject<{
|
|
42
|
+
newValue: T
|
|
43
|
+
oldValue: T
|
|
44
|
+
}>()
|
|
45
|
+
const newAtom: MutableAtom<T> = {
|
|
48
46
|
...options,
|
|
49
47
|
type,
|
|
50
48
|
install: (s: Store) => {
|
|
@@ -86,7 +84,13 @@ export function createMutableAtom<
|
|
|
86
84
|
|
|
87
85
|
new Tracker(token, store)
|
|
88
86
|
if (!family) {
|
|
89
|
-
|
|
87
|
+
createStandaloneSelector(store, {
|
|
88
|
+
key: `${key}:JSON`,
|
|
89
|
+
get: ({ get }) => get(token).toJSON(),
|
|
90
|
+
set: ({ set }, newValue) => {
|
|
91
|
+
set(token, options.class.fromJSON(newValue))
|
|
92
|
+
},
|
|
93
|
+
})
|
|
90
94
|
}
|
|
91
95
|
store.on.atomCreation.next(token)
|
|
92
96
|
return token
|
|
@@ -7,16 +7,17 @@ import type { Store } from "../store"
|
|
|
7
7
|
import type { Transceiver } from "./transceiver"
|
|
8
8
|
|
|
9
9
|
export const getJsonFamily = <
|
|
10
|
-
Core extends Transceiver<Json.Serializable>,
|
|
11
|
-
SerializableCore extends Json.Serializable,
|
|
10
|
+
Core extends Transceiver<Json.Serializable, Json.Serializable>,
|
|
12
11
|
Key extends Canonical,
|
|
13
12
|
>(
|
|
14
|
-
mutableAtomFamily: MutableAtomFamilyToken<Core,
|
|
13
|
+
mutableAtomFamily: MutableAtomFamilyToken<Core, Key>,
|
|
15
14
|
store: Store,
|
|
16
|
-
): WritablePureSelectorFamily<
|
|
15
|
+
): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key> => {
|
|
17
16
|
const target = newest(store)
|
|
18
17
|
const key = `${mutableAtomFamily.key}:JSON`
|
|
19
|
-
const jsonFamily
|
|
20
|
-
|
|
18
|
+
const jsonFamily = target.families.get(key) as WritablePureSelectorFamily<
|
|
19
|
+
ReturnType<Core[`toJSON`]>,
|
|
20
|
+
Key
|
|
21
|
+
>
|
|
21
22
|
return jsonFamily
|
|
22
23
|
}
|
|
@@ -3,27 +3,20 @@ import type {
|
|
|
3
3
|
WritablePureSelectorFamilyToken,
|
|
4
4
|
WritablePureSelectorToken,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import type { Json } from "atom.io/json"
|
|
7
6
|
|
|
8
7
|
import { findInStore } from "../families"
|
|
9
8
|
import { newest } from "../lineage"
|
|
10
9
|
import { type Store, withdraw } from "../store"
|
|
11
|
-
import type { Transceiver } from "./transceiver"
|
|
10
|
+
import type { AsJSON, Transceiver } from "./transceiver"
|
|
12
11
|
|
|
13
|
-
export const getJsonToken = <
|
|
14
|
-
Core extends Transceiver<any>,
|
|
15
|
-
SerializableCore extends Json.Serializable,
|
|
16
|
-
>(
|
|
12
|
+
export const getJsonToken = <T extends Transceiver<any, any>>(
|
|
17
13
|
store: Store,
|
|
18
|
-
mutableAtomToken: MutableAtomToken<
|
|
19
|
-
): WritablePureSelectorToken<
|
|
14
|
+
mutableAtomToken: MutableAtomToken<T>,
|
|
15
|
+
): WritablePureSelectorToken<AsJSON<T>> => {
|
|
20
16
|
if (mutableAtomToken.family) {
|
|
21
17
|
const target = newest(store)
|
|
22
18
|
const jsonFamilyKey = `${mutableAtomToken.family.key}:JSON`
|
|
23
|
-
const jsonFamilyToken: WritablePureSelectorFamilyToken<
|
|
24
|
-
SerializableCore,
|
|
25
|
-
string
|
|
26
|
-
> = {
|
|
19
|
+
const jsonFamilyToken: WritablePureSelectorFamilyToken<AsJSON<T>, string> = {
|
|
27
20
|
key: jsonFamilyKey,
|
|
28
21
|
type: `writable_pure_selector_family`,
|
|
29
22
|
}
|
|
@@ -32,7 +25,7 @@ export const getJsonToken = <
|
|
|
32
25
|
const jsonToken = findInStore(store, family, subKey)
|
|
33
26
|
return jsonToken
|
|
34
27
|
}
|
|
35
|
-
const token: WritablePureSelectorToken<
|
|
28
|
+
const token: WritablePureSelectorToken<AsJSON<T>> = {
|
|
36
29
|
type: `writable_pure_selector`,
|
|
37
30
|
key: `${mutableAtomToken.key}:JSON`,
|
|
38
31
|
}
|
|
@@ -4,20 +4,19 @@ import type { Json } from "atom.io/json"
|
|
|
4
4
|
import type { AtomFamily } from ".."
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
|
-
import type {
|
|
7
|
+
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
8
8
|
|
|
9
9
|
export const getUpdateFamily = <
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Key extends string,
|
|
10
|
+
T extends Transceiver<Json.Serializable, Json.Serializable>,
|
|
11
|
+
K extends string,
|
|
13
12
|
>(
|
|
14
|
-
mutableAtomFamily: MutableAtomFamilyToken<
|
|
13
|
+
mutableAtomFamily: MutableAtomFamilyToken<T, K>,
|
|
15
14
|
store: Store,
|
|
16
|
-
): AtomFamily<
|
|
15
|
+
): AtomFamily<SignalFrom<T>, K> => {
|
|
17
16
|
const target = newest(store)
|
|
18
17
|
const key = `*${mutableAtomFamily.key}`
|
|
19
|
-
const updateFamily: AtomFamily<
|
|
18
|
+
const updateFamily: AtomFamily<SignalFrom<T>, K> = target.families.get(
|
|
20
19
|
key,
|
|
21
|
-
) as AtomFamily<
|
|
20
|
+
) as AtomFamily<SignalFrom<T>, K>
|
|
22
21
|
return updateFamily
|
|
23
22
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { MutableAtomToken, RegularAtomToken } from "atom.io"
|
|
2
|
-
import type { Json } from "atom.io/json"
|
|
3
2
|
|
|
4
|
-
import type {
|
|
3
|
+
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
5
4
|
|
|
6
|
-
export const getUpdateToken = <
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
>(
|
|
10
|
-
mutableAtomToken: MutableAtomToken<Core, SerializableCore>,
|
|
11
|
-
): RegularAtomToken<Signal<Core>> => {
|
|
5
|
+
export const getUpdateToken = <T extends Transceiver<any, any>>(
|
|
6
|
+
mutableAtomToken: MutableAtomToken<T>,
|
|
7
|
+
): RegularAtomToken<SignalFrom<T>> => {
|
|
12
8
|
const key = `*${mutableAtomToken.key}`
|
|
13
|
-
const updateToken: RegularAtomToken<
|
|
9
|
+
const updateToken: RegularAtomToken<SignalFrom<T>> = { type: `atom`, key }
|
|
14
10
|
if (mutableAtomToken.family) {
|
|
15
11
|
updateToken.family = {
|
|
16
12
|
key: `*${mutableAtomToken.family.key}`,
|
|
@@ -8,24 +8,21 @@ import { Tracker } from "./tracker"
|
|
|
8
8
|
import type { Transceiver } from "./transceiver"
|
|
9
9
|
|
|
10
10
|
export class FamilyTracker<
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
T extends Transceiver<any, any>,
|
|
12
|
+
K extends Canonical,
|
|
13
13
|
> {
|
|
14
|
-
private trackers: Map<
|
|
14
|
+
private trackers: Map<K, Tracker<T>> = new Map()
|
|
15
15
|
|
|
16
16
|
public readonly latestUpdateAtoms: RegularAtomFamily<
|
|
17
|
-
(
|
|
18
|
-
|
|
17
|
+
(T extends Transceiver<infer Signal, any> ? Signal : never) | null,
|
|
18
|
+
K
|
|
19
19
|
>
|
|
20
|
-
public readonly mutableAtoms: MutableAtomFamily<
|
|
20
|
+
public readonly mutableAtoms: MutableAtomFamily<T, K>
|
|
21
21
|
|
|
22
|
-
public constructor(
|
|
23
|
-
mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>,
|
|
24
|
-
store: Store,
|
|
25
|
-
) {
|
|
22
|
+
public constructor(mutableAtoms: MutableAtomFamily<T, K>, store: Store) {
|
|
26
23
|
const updateAtoms = createRegularAtomFamily<
|
|
27
|
-
(
|
|
28
|
-
|
|
24
|
+
(T extends Transceiver<infer Signal, any> ? Signal : never) | null,
|
|
25
|
+
K
|
|
29
26
|
>(
|
|
30
27
|
store,
|
|
31
28
|
{
|
|
@@ -44,7 +41,7 @@ export class FamilyTracker<
|
|
|
44
41
|
const key = parseJson(token.family.subKey)
|
|
45
42
|
switch (type) {
|
|
46
43
|
case `state_creation`:
|
|
47
|
-
this.trackers.set(key, new Tracker<
|
|
44
|
+
this.trackers.set(key, new Tracker<T>(token, store))
|
|
48
45
|
break
|
|
49
46
|
case `state_disposal`:
|
|
50
47
|
{
|