atom.io 0.35.0 → 0.36.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/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 +100 -78
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +180 -163
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +5 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +2 -3
- package/dist/introspection/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 +38 -39
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +15 -16
- 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.js.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 +7 -8
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- 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 +9 -2
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +3 -0
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +6 -6
- 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/create-regular-atom.ts +5 -5
- package/src/internal/atom/dispose-atom.ts +1 -0
- package/src/internal/atom/has-role.ts +12 -0
- package/src/internal/atom/index.ts +1 -0
- package/src/internal/caching.ts +38 -16
- 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 +37 -16
- 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 +10 -18
- package/src/internal/molecule.ts +1 -0
- package/src/internal/mutable/create-mutable-atom-family.ts +40 -22
- 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 +31 -38
- package/src/internal/mutable/tracker.ts +86 -104
- package/src/internal/mutable/transceiver.ts +37 -9
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
- package/src/internal/selector/create-writable-held-selector.ts +3 -3
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/selector/dispose-selector.ts +9 -9
- package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
- package/src/internal/set-state/set-atom.ts +15 -22
- package/src/internal/set-state/set-into-store.ts +5 -4
- package/src/internal/store/counterfeit.ts +3 -4
- package/src/internal/store/deposit.ts +8 -11
- package/src/internal/store/store.ts +7 -7
- package/src/internal/store/withdraw.ts +8 -12
- package/src/internal/subscribe/subscribe-in-store.ts +2 -2
- package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +3 -3
- package/src/internal/transaction/act-upon-store.ts +2 -2
- package/src/internal/transaction/apply-transaction.ts +2 -2
- package/src/internal/transaction/build-transaction.ts +2 -2
- package/src/internal/transaction/create-transaction.ts +3 -3
- package/src/internal/transaction/index.ts +2 -2
- package/src/internal/transaction/is-root-store.ts +4 -2
- package/src/internal/utility-types.ts +1 -1
- package/src/introspection/attach-introspection-states.ts +3 -3
- package/src/introspection/attach-transaction-index.ts +4 -4
- package/src/introspection/attach-transaction-logs.ts +4 -4
- package/src/introspection/auditor.ts +3 -3
- package/src/json/index.ts +0 -2
- package/src/main/atom.ts +24 -36
- package/src/main/dispose-state.ts +6 -5
- package/src/main/find-state.ts +3 -4
- package/src/main/get-state.ts +6 -5
- package/src/main/join.ts +2 -2
- package/src/main/logger.ts +7 -7
- package/src/main/reset-state.ts +3 -3
- package/src/main/set-state.ts +3 -3
- package/src/main/subscribe.ts +3 -3
- package/src/main/tokens.ts +8 -14
- package/src/main/transaction.ts +17 -13
- package/src/main/validators.ts +1 -1
- package/src/react/use-json.ts +14 -24
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime/shared-room-store.ts +11 -22
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -17
- package/src/realtime-client/pull-mutable-atom.ts +7 -14
- package/src/realtime-client/push-state.ts +6 -5
- package/src/realtime-client/server-action.ts +5 -4
- 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-react/use-server-action.ts +2 -2
- 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 +14 -1
- package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
- package/src/eslint-plugin/walk.ts +0 -81
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -27
- package/src/json/select-json-family.ts +0 -55
- package/src/json/select-json.ts +0 -19
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import type { Json } from "atom.io/json"
|
|
2
2
|
|
|
3
|
-
export interface Transceiver<
|
|
3
|
+
export interface Transceiver<
|
|
4
|
+
V,
|
|
5
|
+
S extends Json.Serializable,
|
|
6
|
+
J extends Json.Serializable,
|
|
7
|
+
> {
|
|
4
8
|
do: (update: S) => number | `OUT_OF_RANGE` | null
|
|
5
9
|
undo: (update: S) => void
|
|
6
10
|
subscribe: (key: string, fn: (update: S) => void) => () => void
|
|
7
11
|
cacheUpdateNumber: number
|
|
8
12
|
getUpdateNumber: (update: S) => number
|
|
13
|
+
view: () => V
|
|
14
|
+
toJSON: () => J
|
|
9
15
|
}
|
|
10
16
|
|
|
17
|
+
// biome-ignore format: intersection
|
|
18
|
+
export type TransceiverConstructor<
|
|
19
|
+
J extends Json.Serializable,
|
|
20
|
+
T extends Transceiver<any, any, J>
|
|
21
|
+
> =
|
|
22
|
+
& ( new () => T )
|
|
23
|
+
& { fromJSON: (json: J) => T }
|
|
24
|
+
|
|
11
25
|
export function isTransceiver(
|
|
12
26
|
value: unknown,
|
|
13
|
-
): value is Transceiver<Json.Serializable> {
|
|
27
|
+
): value is Transceiver<any, Json.Serializable, Json.Serializable> {
|
|
14
28
|
return (
|
|
15
29
|
typeof value === `object` &&
|
|
16
30
|
value !== null &&
|
|
@@ -22,17 +36,27 @@ export function isTransceiver(
|
|
|
22
36
|
|
|
23
37
|
export type TransceiverMode = `playback` | `record` | `transaction`
|
|
24
38
|
|
|
25
|
-
export type
|
|
26
|
-
|
|
39
|
+
export type ViewOf<T> = T extends Transceiver<infer V, any, any> ? V : T
|
|
40
|
+
|
|
41
|
+
export type SignalFrom<T extends Transceiver<any, any, any>> =
|
|
42
|
+
T extends Transceiver<any, infer S, any> ? S : never
|
|
43
|
+
|
|
44
|
+
export type AsJSON<T extends Transceiver<any, any, any>> = T extends Transceiver<
|
|
45
|
+
any,
|
|
46
|
+
any,
|
|
47
|
+
infer J
|
|
27
48
|
>
|
|
28
|
-
?
|
|
49
|
+
? J
|
|
29
50
|
: never
|
|
30
51
|
|
|
52
|
+
export type ConstructorOf<T extends Transceiver<any, any, any>> =
|
|
53
|
+
TransceiverConstructor<AsJSON<T>, T>
|
|
54
|
+
|
|
31
55
|
/*
|
|
32
56
|
A transceiver may also keep a list of updates that have been applied to it.
|
|
33
57
|
This is useful for undo/redo functionality, especially in the context of
|
|
34
|
-
revising history. It is a good idea to accept a cache limit in your
|
|
35
|
-
constructor, and overwrite old updates. Here's an example of how we
|
|
58
|
+
revising history. It is a good idea to accept a cache limit in your
|
|
59
|
+
constructor, and overwrite old updates. Here's an example of how we
|
|
36
60
|
might set that up:
|
|
37
61
|
|
|
38
62
|
myTransceiver = Transceiver {
|
|
@@ -48,7 +72,7 @@ myTransceiver = Transceiver {
|
|
|
48
72
|
|
|
49
73
|
CONFIRM/NO-OP
|
|
50
74
|
Update `27=del:"x"` is passed to myTransceiver.do:
|
|
51
|
-
- [updateNumber = 27, update = `del:"x"`]
|
|
75
|
+
- [updateNumber = 27, update = `del:"x"`]
|
|
52
76
|
- updateOffset = updateNumber - cacheUpdateNumber // 0
|
|
53
77
|
- eventOffset < 1 // true (we're validating the past)
|
|
54
78
|
- |eventOffset| < cacheLimit // true (we remember this update)
|
|
@@ -75,7 +99,7 @@ Update `29=del:"x"` is passed to myTransceiver.do:
|
|
|
75
99
|
- eventOffset === 1 // false (we're NOT ready to apply this update)
|
|
76
100
|
- updateIdx := cacheIdx + updateOffset // 3
|
|
77
101
|
- updateIdx %= cacheLimit // 0
|
|
78
|
-
- cache[updateIdx] = update // cache = <{ 0 => del:"x" }>
|
|
102
|
+
- cache[updateIdx] = update // cache = <{ 0 => del:"x" }>
|
|
79
103
|
- expectedUpdateNumber = cacheUpdateNumber + 1 // 28
|
|
80
104
|
- return expectedUpdateNumber // 🤨👂
|
|
81
105
|
|
|
@@ -110,3 +134,7 @@ Update `24=add:"z"` is passed to myTransceiver.do:
|
|
|
110
134
|
- return `OUT_OF_RANGE` // 😵💫👂
|
|
111
135
|
|
|
112
136
|
*/
|
|
137
|
+
|
|
138
|
+
// The function wants a constructor C
|
|
139
|
+
// - that has a static fromJSON(json) returning an instance of C
|
|
140
|
+
// - and whose instances have toJSON() whose return type matches fromJSON's param
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
7
|
import type { ReadonlyHeldSelector } from ".."
|
|
8
|
-
import {
|
|
8
|
+
import { writeToCache } from "../caching"
|
|
9
9
|
import { newest } from "../lineage"
|
|
10
10
|
import type { Store } from "../store"
|
|
11
11
|
import { Subject } from "../subject"
|
|
@@ -34,7 +34,7 @@ export const createReadonlyHeldSelector = <T extends object>(
|
|
|
34
34
|
}
|
|
35
35
|
innerTarget.selectorAtoms.delete(key)
|
|
36
36
|
options.get({ get, find, json }, constant)
|
|
37
|
-
|
|
37
|
+
writeToCache(newest(store), key, constant, subject)
|
|
38
38
|
covered.clear()
|
|
39
39
|
return constant
|
|
40
40
|
}
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
7
|
import type { ReadonlyPureSelector } from ".."
|
|
8
|
-
import {
|
|
8
|
+
import { writeToCache } from "../caching"
|
|
9
9
|
import { newest } from "../lineage"
|
|
10
10
|
import type { Store } from "../store"
|
|
11
11
|
import { Subject } from "../subject"
|
|
@@ -34,7 +34,7 @@ export const createReadonlyPureSelector = <T>(
|
|
|
34
34
|
}
|
|
35
35
|
innerTarget.selectorAtoms.delete(key)
|
|
36
36
|
const value = options.get({ get, find, json })
|
|
37
|
-
const cached =
|
|
37
|
+
const cached = writeToCache(innerTarget, key, value, subject)
|
|
38
38
|
store.logger.info(`✨`, type, key, `=`, cached)
|
|
39
39
|
covered.clear()
|
|
40
40
|
return cached
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
7
|
import type { WritableHeldSelector } from ".."
|
|
8
|
-
import {
|
|
8
|
+
import { writeToCache } from "../caching"
|
|
9
9
|
import { newest } from "../lineage"
|
|
10
10
|
import { markDone } from "../operation"
|
|
11
11
|
import { become } from "../set-state"
|
|
@@ -39,7 +39,7 @@ export const createWritableHeldSelector = <T extends object>(
|
|
|
39
39
|
}
|
|
40
40
|
innerTarget.selectorAtoms.delete(key)
|
|
41
41
|
getFn(getterToolkit, constant)
|
|
42
|
-
|
|
42
|
+
writeToCache(innerTarget, key, constant, subject)
|
|
43
43
|
store.logger.info(`✨`, type, key, `=`, constant)
|
|
44
44
|
covered.clear()
|
|
45
45
|
return constant
|
|
@@ -50,7 +50,7 @@ export const createWritableHeldSelector = <T extends object>(
|
|
|
50
50
|
const oldValue = getSelf(options.get, innerTarget)
|
|
51
51
|
const newValue = become(next)(oldValue)
|
|
52
52
|
store.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)
|
|
53
|
-
|
|
53
|
+
writeToCache(innerTarget, key, newValue, subject)
|
|
54
54
|
markDone(innerTarget, key)
|
|
55
55
|
if (isRootStore(innerTarget)) {
|
|
56
56
|
subject.next({ newValue, oldValue })
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
7
|
import type { WritablePureSelector } from ".."
|
|
8
|
-
import {
|
|
8
|
+
import { writeToCache } from "../caching"
|
|
9
9
|
import { newest } from "../lineage"
|
|
10
10
|
import { markDone } from "../operation"
|
|
11
11
|
import { become } from "../set-state"
|
|
@@ -39,7 +39,7 @@ export const createWritablePureSelector = <T>(
|
|
|
39
39
|
}
|
|
40
40
|
innerTarget.selectorAtoms.delete(key)
|
|
41
41
|
const value = getFn(getterToolkit)
|
|
42
|
-
const cached =
|
|
42
|
+
const cached = writeToCache(innerTarget, key, value, subject)
|
|
43
43
|
store.logger.info(`✨`, type, key, `=`, cached)
|
|
44
44
|
covered.clear()
|
|
45
45
|
return value
|
|
@@ -50,7 +50,7 @@ export const createWritablePureSelector = <T>(
|
|
|
50
50
|
const oldValue = getSelf(options.get, innerTarget)
|
|
51
51
|
const newValue = become(next)(oldValue)
|
|
52
52
|
store.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`)
|
|
53
|
-
|
|
53
|
+
writeToCache(innerTarget, options.key, newValue, subject)
|
|
54
54
|
markDone(innerTarget, options.key)
|
|
55
55
|
if (isRootStore(innerTarget)) {
|
|
56
56
|
subject.next({ newValue, oldValue })
|
|
@@ -8,9 +8,8 @@ export function disposeSelector(
|
|
|
8
8
|
selectorToken: SelectorToken<unknown>,
|
|
9
9
|
): void {
|
|
10
10
|
const target = newest(store)
|
|
11
|
-
const { key, type } = selectorToken
|
|
12
|
-
|
|
13
|
-
if (!selector.family) {
|
|
11
|
+
const { key, type, family: familyMeta } = selectorToken
|
|
12
|
+
if (!familyMeta) {
|
|
14
13
|
store.logger.error(
|
|
15
14
|
`❌`,
|
|
16
15
|
type,
|
|
@@ -18,9 +17,9 @@ export function disposeSelector(
|
|
|
18
17
|
`Standalone selectors cannot be disposed.`,
|
|
19
18
|
)
|
|
20
19
|
} else {
|
|
21
|
-
const molecule = target.molecules.get(
|
|
20
|
+
const molecule = target.molecules.get(familyMeta.subKey)
|
|
22
21
|
if (molecule) {
|
|
23
|
-
target.moleculeData.delete(
|
|
22
|
+
target.moleculeData.delete(familyMeta.subKey, familyMeta.key)
|
|
24
23
|
}
|
|
25
24
|
let familyToken: SelectorFamilyToken<any, any>
|
|
26
25
|
switch (selectorToken.type) {
|
|
@@ -28,7 +27,7 @@ export function disposeSelector(
|
|
|
28
27
|
{
|
|
29
28
|
target.writableSelectors.delete(key)
|
|
30
29
|
familyToken = {
|
|
31
|
-
key:
|
|
30
|
+
key: familyMeta.key,
|
|
32
31
|
type: `writable_held_selector_family`,
|
|
33
32
|
}
|
|
34
33
|
const family = withdraw(store, familyToken)
|
|
@@ -43,7 +42,7 @@ export function disposeSelector(
|
|
|
43
42
|
{
|
|
44
43
|
target.writableSelectors.delete(key)
|
|
45
44
|
familyToken = {
|
|
46
|
-
key:
|
|
45
|
+
key: familyMeta.key,
|
|
47
46
|
type: `writable_pure_selector_family`,
|
|
48
47
|
}
|
|
49
48
|
const family = withdraw(store, familyToken)
|
|
@@ -58,7 +57,7 @@ export function disposeSelector(
|
|
|
58
57
|
{
|
|
59
58
|
target.readonlySelectors.delete(key)
|
|
60
59
|
familyToken = {
|
|
61
|
-
key:
|
|
60
|
+
key: familyMeta.key,
|
|
62
61
|
type: `readonly_held_selector_family`,
|
|
63
62
|
}
|
|
64
63
|
const family = withdraw(store, familyToken)
|
|
@@ -73,7 +72,7 @@ export function disposeSelector(
|
|
|
73
72
|
{
|
|
74
73
|
target.readonlySelectors.delete(key)
|
|
75
74
|
familyToken = {
|
|
76
|
-
key:
|
|
75
|
+
key: familyMeta.key,
|
|
77
76
|
type: `readonly_pure_selector_family`,
|
|
78
77
|
}
|
|
79
78
|
const family = withdraw(store, familyToken)
|
|
@@ -89,6 +88,7 @@ export function disposeSelector(
|
|
|
89
88
|
target.valueMap.delete(key)
|
|
90
89
|
target.selectorAtoms.delete(key)
|
|
91
90
|
target.selectorGraph.delete(key)
|
|
91
|
+
target.moleculeData.delete(familyMeta.key, familyMeta.subKey)
|
|
92
92
|
store.logger.info(`🔥`, selectorToken.type, key, `deleted`)
|
|
93
93
|
if (isChildStore(target) && target.transactionMeta.phase === `building`) {
|
|
94
94
|
target.transactionMeta.update.updates.push({
|
|
@@ -4,11 +4,18 @@ import type { Store } from "../store"
|
|
|
4
4
|
import { setAtom } from "./set-atom"
|
|
5
5
|
|
|
6
6
|
function resetAtom(store: Store, state: Atom<any>) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
switch (state.type) {
|
|
8
|
+
case `mutable_atom`:
|
|
9
|
+
setAtom(store, state, new state.class())
|
|
10
|
+
return
|
|
11
|
+
case `atom`: {
|
|
12
|
+
let def = state.default
|
|
13
|
+
if (def instanceof Function) {
|
|
14
|
+
def = def()
|
|
15
|
+
}
|
|
16
|
+
setAtom(store, state, def)
|
|
17
|
+
}
|
|
10
18
|
}
|
|
11
|
-
setAtom(store, state, def)
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
export function resetAtomOrSelector(
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { KeyedStateUpdate } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { Atom, Store } from ".."
|
|
4
|
-
import {
|
|
3
|
+
import type { Atom, MutableAtom, Store } from ".."
|
|
4
|
+
import { hasRole } from "../atom/has-role"
|
|
5
|
+
import { writeToCache } from "../caching"
|
|
5
6
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
6
7
|
import { isTransceiver, type Transceiver } from "../mutable"
|
|
7
8
|
import { markDone } from "../operation"
|
|
8
9
|
import { isChildStore } from "../transaction/is-root-store"
|
|
9
10
|
import { become } from "./become"
|
|
10
|
-
import { copyMutableIfNeeded } from "./copy-mutable-if-needed"
|
|
11
11
|
import { emitUpdate } from "./emit-update"
|
|
12
12
|
import { evictDownStream } from "./evict-downstream"
|
|
13
13
|
|
|
@@ -16,16 +16,10 @@ export const setAtom = <T>(
|
|
|
16
16
|
atom: Atom<T>,
|
|
17
17
|
next: T | ((oldValue: T) => T),
|
|
18
18
|
): void => {
|
|
19
|
-
const oldValue = readOrComputeValue(target, atom)
|
|
20
|
-
let newValue = oldValue
|
|
21
|
-
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
22
|
-
const { parent } = target
|
|
23
|
-
const copiedValue = copyMutableIfNeeded(target, atom, parent)
|
|
24
|
-
newValue = copiedValue
|
|
25
|
-
}
|
|
26
|
-
newValue = become(next)(newValue)
|
|
19
|
+
const oldValue = readOrComputeValue(target, atom, `mut`)
|
|
20
|
+
let newValue = become(next)(oldValue)
|
|
27
21
|
target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)
|
|
28
|
-
newValue =
|
|
22
|
+
newValue = writeToCache(target, atom.key, newValue, atom.subject)
|
|
29
23
|
markDone(target, atom.key)
|
|
30
24
|
evictDownStream(target, atom)
|
|
31
25
|
const update = { oldValue, newValue }
|
|
@@ -57,16 +51,15 @@ export const setAtom = <T>(
|
|
|
57
51
|
update.newValue,
|
|
58
52
|
`)`,
|
|
59
53
|
)
|
|
60
|
-
} else if (atom
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)
|
|
67
|
-
transceiver = copiedValue
|
|
68
|
-
}
|
|
54
|
+
} else if (hasRole(atom, `tracker:signal`)) {
|
|
55
|
+
const key = atom.key.slice(1)
|
|
56
|
+
const mutable = target.atoms.get(key) as MutableAtom<
|
|
57
|
+
Transceiver<unknown, any, any>
|
|
58
|
+
>
|
|
59
|
+
const transceiver = readOrComputeValue(target, mutable, `mut`)
|
|
69
60
|
const accepted = transceiver.do(update.newValue) === null
|
|
70
|
-
if (accepted
|
|
61
|
+
if (accepted === true) {
|
|
62
|
+
evictDownStream(target, mutable)
|
|
63
|
+
}
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -38,9 +38,10 @@ export function setIntoStore<T, New extends T>(
|
|
|
38
38
|
if (params.length === 2) {
|
|
39
39
|
token = params[0]
|
|
40
40
|
value = params[1]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (token.family) {
|
|
42
|
+
// biome-ignore lint/style/noNonNullAssertion: this token belongs to a family
|
|
43
|
+
family = getFamilyOfToken(store, token)!
|
|
44
|
+
key = parseJson(token.family.subKey)
|
|
44
45
|
token = findInStore(store, family, key)
|
|
45
46
|
}
|
|
46
47
|
} else {
|
|
@@ -71,7 +72,7 @@ export function setIntoStore<T, New extends T>(
|
|
|
71
72
|
if (rejectionTime) {
|
|
72
73
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
73
74
|
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
74
|
-
()
|
|
75
|
+
function waitUntilOperationCloseToSetState() {
|
|
75
76
|
unsubscribe()
|
|
76
77
|
store.logger.info(
|
|
77
78
|
`🟢`,
|
|
@@ -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 { Transceiver } from "../mutable"
|
|
@@ -32,11 +32,10 @@ export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
|
32
32
|
} as const
|
|
33
33
|
|
|
34
34
|
export function counterfeit<
|
|
35
|
-
T extends Transceiver<any>,
|
|
36
|
-
J extends Json.Serializable,
|
|
35
|
+
T extends Transceiver<any, any, any>,
|
|
37
36
|
K extends Canonical,
|
|
38
37
|
Key extends K,
|
|
39
|
-
>(token: MutableAtomFamilyToken<T,
|
|
38
|
+
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
|
|
40
39
|
|
|
41
40
|
export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
42
41
|
token: RegularAtomFamilyToken<T, K>,
|
|
@@ -20,13 +20,13 @@ import type {
|
|
|
20
20
|
WritablePureSelectorToken,
|
|
21
21
|
WritableToken,
|
|
22
22
|
} from "atom.io"
|
|
23
|
-
import type { Canonical
|
|
23
|
+
import type { Canonical } from "atom.io/json"
|
|
24
24
|
|
|
25
25
|
import type {
|
|
26
26
|
Atom,
|
|
27
27
|
AtomFamily,
|
|
28
28
|
AtomIOInternalResource,
|
|
29
|
-
|
|
29
|
+
Fn,
|
|
30
30
|
MutableAtom,
|
|
31
31
|
MutableAtomFamily,
|
|
32
32
|
ReadableFamily,
|
|
@@ -47,9 +47,9 @@ import type {
|
|
|
47
47
|
import type { Transaction } from "../transaction"
|
|
48
48
|
|
|
49
49
|
export function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>
|
|
50
|
-
export function deposit<T extends Transceiver<any>>(
|
|
51
|
-
state: MutableAtom<T
|
|
52
|
-
): MutableAtomToken<T
|
|
50
|
+
export function deposit<T extends Transceiver<any, any, any>>(
|
|
51
|
+
state: MutableAtom<T>,
|
|
52
|
+
): MutableAtomToken<T>
|
|
53
53
|
export function deposit<T>(state: Atom<T>): AtomToken<T>
|
|
54
54
|
export function deposit<T>(
|
|
55
55
|
state: WritablePureSelector<T>,
|
|
@@ -65,10 +65,9 @@ export function deposit<T, K extends Canonical>(
|
|
|
65
65
|
state: RegularAtomFamily<T, K>,
|
|
66
66
|
): RegularAtomFamilyToken<T, K>
|
|
67
67
|
export function deposit<
|
|
68
|
-
T extends Transceiver<any>,
|
|
69
|
-
J extends Json.Serializable,
|
|
68
|
+
T extends Transceiver<any, any, any>,
|
|
70
69
|
K extends Canonical,
|
|
71
|
-
>(state: MutableAtomFamily<T,
|
|
70
|
+
>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, K>
|
|
72
71
|
export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
|
|
73
72
|
export function deposit<T>(
|
|
74
73
|
state: WritablePureSelectorFamily<T, any>,
|
|
@@ -86,9 +85,7 @@ export function deposit<T>(
|
|
|
86
85
|
state: ReadableFamily<T, any>,
|
|
87
86
|
): ReadableFamilyToken<T, any>
|
|
88
87
|
|
|
89
|
-
export function deposit<T extends
|
|
90
|
-
state: Transaction<T>,
|
|
91
|
-
): TransactionToken<T>
|
|
88
|
+
export function deposit<T extends Fn>(state: Transaction<T>): TransactionToken<T>
|
|
92
89
|
export function deposit<M extends TimelineManageable>(
|
|
93
90
|
state: Timeline<M>,
|
|
94
91
|
): TimelineToken<M>
|
|
@@ -35,7 +35,7 @@ import type {
|
|
|
35
35
|
TransactionProgress,
|
|
36
36
|
} from "../transaction"
|
|
37
37
|
import { isRootStore } from "../transaction"
|
|
38
|
-
import type {
|
|
38
|
+
import type { Fn } from "../utility-types"
|
|
39
39
|
import { CircularBuffer } from "./circular-buffer"
|
|
40
40
|
|
|
41
41
|
export class Store implements Lineage {
|
|
@@ -70,18 +70,18 @@ export class Store implements Lineage {
|
|
|
70
70
|
makeContentKey: (...keys) => keys.sort().join(`:`),
|
|
71
71
|
},
|
|
72
72
|
)
|
|
73
|
-
public trackers: Map<string, Tracker<Transceiver<any>>> = new Map()
|
|
73
|
+
public trackers: Map<string, Tracker<Transceiver<any, any, any>>> = new Map()
|
|
74
74
|
public families: Map<
|
|
75
75
|
string,
|
|
76
76
|
| HeldSelectorFamily<any, any>
|
|
77
|
-
| MutableAtomFamily<any, any
|
|
77
|
+
| MutableAtomFamily<any, any>
|
|
78
78
|
| PureSelectorFamily<any, any>
|
|
79
79
|
| RegularAtomFamily<any, any>
|
|
80
80
|
> = new Map()
|
|
81
81
|
public joins: Map<string, Join<any, any, any, any, any, any>> = new Map()
|
|
82
82
|
|
|
83
|
-
public transactions: Map<string, Transaction<
|
|
84
|
-
public transactionMeta: TransactionEpoch | TransactionProgress<
|
|
83
|
+
public transactions: Map<string, Transaction<Fn>> = new Map()
|
|
84
|
+
public transactionMeta: TransactionEpoch | TransactionProgress<Fn> = {
|
|
85
85
|
epoch: new Map<string, number>(),
|
|
86
86
|
actionContinuities: new Junction({
|
|
87
87
|
between: [`continuity`, `action`],
|
|
@@ -250,8 +250,8 @@ export type StoreEventCarrier = {
|
|
|
250
250
|
selectorCreation: Subject<SelectorToken<unknown>>
|
|
251
251
|
selectorDisposal: Subject<SelectorToken<unknown>>
|
|
252
252
|
timelineCreation: Subject<TimelineToken<unknown>>
|
|
253
|
-
transactionCreation: Subject<TransactionToken<
|
|
254
|
-
transactionApplying: StatefulSubject<TransactionProgress<
|
|
253
|
+
transactionCreation: Subject<TransactionToken<Fn>>
|
|
254
|
+
transactionApplying: StatefulSubject<TransactionProgress<Fn> | null>
|
|
255
255
|
operationClose: Subject<OperationProgress>
|
|
256
256
|
moleculeCreation: Subject<MoleculeCreation>
|
|
257
257
|
moleculeDisposal: Subject<MoleculeDisposal>
|
|
@@ -32,13 +32,13 @@ import type {
|
|
|
32
32
|
WritableSelectorToken,
|
|
33
33
|
WritableToken,
|
|
34
34
|
} from "atom.io"
|
|
35
|
-
import type { Canonical
|
|
35
|
+
import type { Canonical } from "atom.io/json"
|
|
36
36
|
|
|
37
37
|
import type {
|
|
38
38
|
Atom,
|
|
39
39
|
AtomFamily,
|
|
40
40
|
AtomIOInternalResource,
|
|
41
|
-
|
|
41
|
+
Fn,
|
|
42
42
|
HeldSelector,
|
|
43
43
|
HeldSelectorFamily,
|
|
44
44
|
MutableAtom,
|
|
@@ -76,10 +76,10 @@ export function withdraw<T>(
|
|
|
76
76
|
store: Store,
|
|
77
77
|
token: RegularAtomToken<T>,
|
|
78
78
|
): RegularAtom<T>
|
|
79
|
-
export function withdraw<T extends Transceiver<any>>(
|
|
79
|
+
export function withdraw<T extends Transceiver<any, any, any>>(
|
|
80
80
|
store: Store,
|
|
81
81
|
token: MutableAtomToken<T, any>,
|
|
82
|
-
): MutableAtom<T
|
|
82
|
+
): MutableAtom<T>
|
|
83
83
|
export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
|
|
84
84
|
export function withdraw<T>(
|
|
85
85
|
store: Store,
|
|
@@ -128,13 +128,9 @@ export function withdraw<T, K extends Canonical>(
|
|
|
128
128
|
token: RegularAtomFamilyToken<T, K>,
|
|
129
129
|
): RegularAtomFamily<T, K>
|
|
130
130
|
export function withdraw<
|
|
131
|
-
T extends Transceiver<any>,
|
|
132
|
-
J extends Json.Serializable,
|
|
131
|
+
T extends Transceiver<any, any, any>,
|
|
133
132
|
K extends Canonical,
|
|
134
|
-
>(
|
|
135
|
-
store: Store,
|
|
136
|
-
token: MutableAtomFamilyToken<T, J, K>,
|
|
137
|
-
): MutableAtomFamily<T, J, K>
|
|
133
|
+
>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>
|
|
138
134
|
export function withdraw<T, K extends Canonical>(
|
|
139
135
|
store: Store,
|
|
140
136
|
token: AtomFamilyToken<T, K>,
|
|
@@ -184,10 +180,10 @@ export function withdraw<T, K extends Canonical>(
|
|
|
184
180
|
token: WritableFamilyToken<T, K>,
|
|
185
181
|
): WritableFamily<T, K>
|
|
186
182
|
|
|
187
|
-
export function withdraw<T extends
|
|
183
|
+
export function withdraw<T extends Fn>(
|
|
188
184
|
store: Store,
|
|
189
185
|
token: TransactionToken<T>,
|
|
190
|
-
): Transaction<T extends
|
|
186
|
+
): Transaction<T extends Fn ? T : never>
|
|
191
187
|
export function withdraw<T>(
|
|
192
188
|
store: Store,
|
|
193
189
|
token: TimelineToken<T>,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
TransactionUpdateHandler,
|
|
8
8
|
UpdateHandler,
|
|
9
9
|
} from "atom.io"
|
|
10
|
-
import type {
|
|
10
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
11
11
|
import {
|
|
12
12
|
arbitrary,
|
|
13
13
|
subscribeToState,
|
|
@@ -21,7 +21,7 @@ export function subscribeInStore<T>(
|
|
|
21
21
|
handleUpdate: UpdateHandler<T>,
|
|
22
22
|
key?: string,
|
|
23
23
|
): () => void
|
|
24
|
-
export function subscribeInStore<F extends
|
|
24
|
+
export function subscribeInStore<F extends Fn>(
|
|
25
25
|
store: Store,
|
|
26
26
|
token: TransactionToken<F>,
|
|
27
27
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TransactionToken, TransactionUpdateHandler } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Fn, Store } from ".."
|
|
4
4
|
import { withdraw } from ".."
|
|
5
5
|
|
|
6
|
-
export const subscribeToTransaction = <F extends
|
|
6
|
+
export const subscribeToTransaction = <F extends Fn>(
|
|
7
7
|
store: Store,
|
|
8
8
|
token: TransactionToken<F>,
|
|
9
9
|
key: string,
|
|
@@ -23,7 +23,7 @@ import { getUpdateToken } from "../mutable"
|
|
|
23
23
|
import { type Store, withdraw } from "../store"
|
|
24
24
|
import { Subject } from "../subject"
|
|
25
25
|
import { isChildStore } from "../transaction"
|
|
26
|
-
import type { Flat,
|
|
26
|
+
import type { Flat, Fn } from "../utility-types"
|
|
27
27
|
|
|
28
28
|
export type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<
|
|
29
29
|
StateUpdate<TokenType<ManagedAtom>> & {
|
|
@@ -40,7 +40,7 @@ export type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
|
|
|
40
40
|
atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[]
|
|
41
41
|
}
|
|
42
42
|
export type TimelineTransactionUpdate = Flat<
|
|
43
|
-
TransactionUpdate<
|
|
43
|
+
TransactionUpdate<Fn> & {
|
|
44
44
|
key: string
|
|
45
45
|
type: `transaction_update`
|
|
46
46
|
timestamp: number
|
|
@@ -340,7 +340,7 @@ function addAtomFamilyToTimeline(
|
|
|
340
340
|
function joinTransaction(
|
|
341
341
|
store: Store,
|
|
342
342
|
tl: Timeline<any>,
|
|
343
|
-
txUpdateInProgress: TransactionUpdate<
|
|
343
|
+
txUpdateInProgress: TransactionUpdate<Fn>,
|
|
344
344
|
) {
|
|
345
345
|
const currentTxKey = txUpdateInProgress.key
|
|
346
346
|
const currentTxInstanceId = txUpdateInProgress.id
|
|
@@ -3,9 +3,9 @@ import type { TransactionToken } from "atom.io"
|
|
|
3
3
|
import { NotFoundError } from "../not-found-error"
|
|
4
4
|
import type { Store } from "../store"
|
|
5
5
|
import { withdraw } from "../store"
|
|
6
|
-
import type {
|
|
6
|
+
import type { Fn } from "../utility-types"
|
|
7
7
|
|
|
8
|
-
export function actUponStore<F extends
|
|
8
|
+
export function actUponStore<F extends Fn>(
|
|
9
9
|
store: Store,
|
|
10
10
|
token: TransactionToken<F>,
|
|
11
11
|
id: string,
|
|
@@ -2,11 +2,11 @@ import { ingestTransactionUpdate } from "../ingest-updates"
|
|
|
2
2
|
import { newest } from "../lineage"
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
import { withdraw } from "../store"
|
|
5
|
-
import type {
|
|
5
|
+
import type { Fn } from "../utility-types"
|
|
6
6
|
import { isChildStore, isRootStore } from "./is-root-store"
|
|
7
7
|
import { setEpochNumberOfAction } from "./set-epoch-number"
|
|
8
8
|
|
|
9
|
-
export const applyTransaction = <F extends
|
|
9
|
+
export const applyTransaction = <F extends Fn>(
|
|
10
10
|
output: ReturnType<F>,
|
|
11
11
|
store: Store,
|
|
12
12
|
): void => {
|
|
@@ -16,7 +16,7 @@ import { newest } from "../lineage"
|
|
|
16
16
|
import { getJsonToken } from "../mutable"
|
|
17
17
|
import { resetInStore, setIntoStore } from "../set-state"
|
|
18
18
|
import type { Store } from "../store"
|
|
19
|
-
import type {
|
|
19
|
+
import type { Fn } from "../utility-types"
|
|
20
20
|
import type { TransactionProgress } from "."
|
|
21
21
|
import { actUponStore, getEpochNumberOfAction } from "."
|
|
22
22
|
import type { ChildStore, RootStore } from "./is-root-store"
|
|
@@ -66,7 +66,7 @@ export const buildTransaction = (
|
|
|
66
66
|
miscResources: new LazyMap(parent.miscResources),
|
|
67
67
|
}
|
|
68
68
|
const epoch = getEpochNumberOfAction(store, key)
|
|
69
|
-
const transactionMeta: TransactionProgress<
|
|
69
|
+
const transactionMeta: TransactionProgress<Fn> = {
|
|
70
70
|
phase: `building`,
|
|
71
71
|
update: {
|
|
72
72
|
type: `transaction_update`,
|