atom.io 0.36.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/internal/index.d.ts +83 -67
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +98 -98
- 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/main/index.d.ts +27 -29
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +8 -9
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- 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/react-devtools/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 +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- 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 +3 -3
- package/src/internal/atom/create-regular-atom.ts +5 -5
- 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 +1 -1
- package/src/internal/families/get-family-of-token.ts +1 -1
- package/src/internal/families/init-family-member.ts +1 -1
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/read-or-compute-value.ts +29 -20
- package/src/internal/index.ts +8 -8
- package/src/internal/join/join-internal.ts +7 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-json-token.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/get-update-token.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +27 -31
- package/src/internal/mutable/tracker.ts +29 -23
- package/src/internal/mutable/transceiver.ts +11 -10
- 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/set-state/set-atom.ts +15 -22
- package/src/internal/set-state/set-into-store.ts +5 -4
- package/src/internal/store/counterfeit.ts +1 -1
- package/src/internal/store/deposit.ts +7 -8
- package/src/internal/store/store.ts +6 -6
- package/src/internal/store/withdraw.ts +8 -8
- 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/main/atom.ts +4 -4
- package/src/main/dispose-state.ts +4 -3
- package/src/main/find-state.ts +1 -1
- package/src/main/get-state.ts +6 -5
- 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 +6 -10
- package/src/main/transaction.ts +13 -15
- package/src/react/use-json.ts +5 -5
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
- package/src/realtime-client/pull-mutable-atom.ts +5 -8
- 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 +1 -1
- package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
- package/src/realtime-react/use-server-action.ts +2 -2
- package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-provider.ts +1 -1
- package/src/transceivers/set-rtx/set-rtx.ts +14 -1
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
|
@@ -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 })
|
|
@@ -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
|
`🟢`,
|
|
@@ -32,7 +32,7 @@ export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
|
32
32
|
} as const
|
|
33
33
|
|
|
34
34
|
export function counterfeit<
|
|
35
|
-
T extends Transceiver<any, any>,
|
|
35
|
+
T extends Transceiver<any, any, any>,
|
|
36
36
|
K extends Canonical,
|
|
37
37
|
Key extends K,
|
|
38
38
|
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
|
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
Atom,
|
|
27
27
|
AtomFamily,
|
|
28
28
|
AtomIOInternalResource,
|
|
29
|
-
|
|
29
|
+
Fn,
|
|
30
30
|
MutableAtom,
|
|
31
31
|
MutableAtomFamily,
|
|
32
32
|
ReadableFamily,
|
|
@@ -47,7 +47,7 @@ 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, any>>(
|
|
50
|
+
export function deposit<T extends Transceiver<any, any, any>>(
|
|
51
51
|
state: MutableAtom<T>,
|
|
52
52
|
): MutableAtomToken<T>
|
|
53
53
|
export function deposit<T>(state: Atom<T>): AtomToken<T>
|
|
@@ -64,9 +64,10 @@ export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
|
|
|
64
64
|
export function deposit<T, K extends Canonical>(
|
|
65
65
|
state: RegularAtomFamily<T, K>,
|
|
66
66
|
): RegularAtomFamilyToken<T, K>
|
|
67
|
-
export function deposit<
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
export function deposit<
|
|
68
|
+
T extends Transceiver<any, any, any>,
|
|
69
|
+
K extends Canonical,
|
|
70
|
+
>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, K>
|
|
70
71
|
export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
|
|
71
72
|
export function deposit<T>(
|
|
72
73
|
state: WritablePureSelectorFamily<T, any>,
|
|
@@ -84,9 +85,7 @@ export function deposit<T>(
|
|
|
84
85
|
state: ReadableFamily<T, any>,
|
|
85
86
|
): ReadableFamilyToken<T, any>
|
|
86
87
|
|
|
87
|
-
export function deposit<T extends
|
|
88
|
-
state: Transaction<T>,
|
|
89
|
-
): TransactionToken<T>
|
|
88
|
+
export function deposit<T extends Fn>(state: Transaction<T>): TransactionToken<T>
|
|
90
89
|
export function deposit<M extends TimelineManageable>(
|
|
91
90
|
state: Timeline<M>,
|
|
92
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,7 +70,7 @@ export class Store implements Lineage {
|
|
|
70
70
|
makeContentKey: (...keys) => keys.sort().join(`:`),
|
|
71
71
|
},
|
|
72
72
|
)
|
|
73
|
-
public trackers: Map<string, Tracker<Transceiver<any, 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>
|
|
@@ -80,8 +80,8 @@ export class Store implements Lineage {
|
|
|
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>
|
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
Atom,
|
|
39
39
|
AtomFamily,
|
|
40
40
|
AtomIOInternalResource,
|
|
41
|
-
|
|
41
|
+
Fn,
|
|
42
42
|
HeldSelector,
|
|
43
43
|
HeldSelectorFamily,
|
|
44
44
|
MutableAtom,
|
|
@@ -76,7 +76,7 @@ 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, any>>(
|
|
79
|
+
export function withdraw<T extends Transceiver<any, any, any>>(
|
|
80
80
|
store: Store,
|
|
81
81
|
token: MutableAtomToken<T, any>,
|
|
82
82
|
): MutableAtom<T>
|
|
@@ -127,10 +127,10 @@ export function withdraw<T, K extends Canonical>(
|
|
|
127
127
|
store: Store,
|
|
128
128
|
token: RegularAtomFamilyToken<T, K>,
|
|
129
129
|
): RegularAtomFamily<T, K>
|
|
130
|
-
export function withdraw<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
): MutableAtomFamily<T, K>
|
|
130
|
+
export function withdraw<
|
|
131
|
+
T extends Transceiver<any, any, any>,
|
|
132
|
+
K extends Canonical,
|
|
133
|
+
>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>
|
|
134
134
|
export function withdraw<T, K extends Canonical>(
|
|
135
135
|
store: Store,
|
|
136
136
|
token: AtomFamilyToken<T, K>,
|
|
@@ -180,10 +180,10 @@ export function withdraw<T, K extends Canonical>(
|
|
|
180
180
|
token: WritableFamilyToken<T, K>,
|
|
181
181
|
): WritableFamily<T, K>
|
|
182
182
|
|
|
183
|
-
export function withdraw<T extends
|
|
183
|
+
export function withdraw<T extends Fn>(
|
|
184
184
|
store: Store,
|
|
185
185
|
token: TransactionToken<T>,
|
|
186
|
-
): Transaction<T extends
|
|
186
|
+
): Transaction<T extends Fn ? T : never>
|
|
187
187
|
export function withdraw<T>(
|
|
188
188
|
store: Store,
|
|
189
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`,
|
|
@@ -8,12 +8,12 @@ import { newest } from "../lineage"
|
|
|
8
8
|
import type { Store } from "../store"
|
|
9
9
|
import { deposit } from "../store"
|
|
10
10
|
import { Subject } from "../subject"
|
|
11
|
-
import type {
|
|
11
|
+
import type { Fn } from "../utility-types"
|
|
12
12
|
import { abortTransaction } from "./abort-transaction"
|
|
13
13
|
import { applyTransaction } from "./apply-transaction"
|
|
14
14
|
import { buildTransaction } from "./build-transaction"
|
|
15
15
|
|
|
16
|
-
export type Transaction<F extends
|
|
16
|
+
export type Transaction<F extends Fn> = {
|
|
17
17
|
key: string
|
|
18
18
|
type: `transaction`
|
|
19
19
|
install: (store: Store) => void
|
|
@@ -21,7 +21,7 @@ export type Transaction<F extends Func> = {
|
|
|
21
21
|
run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function createTransaction<F extends
|
|
24
|
+
export function createTransaction<F extends Fn>(
|
|
25
25
|
store: Store,
|
|
26
26
|
options: TransactionOptions<F>,
|
|
27
27
|
): TransactionToken<F> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ActorToolkit, TransactionUpdate } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Junction } from "../junction"
|
|
4
|
-
import type {
|
|
4
|
+
import type { Fn } from "../utility-types"
|
|
5
5
|
|
|
6
6
|
export * from "./abort-transaction"
|
|
7
7
|
export * from "./act-upon-store"
|
|
@@ -16,7 +16,7 @@ export * from "./set-epoch-number"
|
|
|
16
16
|
export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
|
|
17
17
|
export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
|
|
18
18
|
|
|
19
|
-
export type TransactionProgress<F extends
|
|
19
|
+
export type TransactionProgress<F extends Fn> = {
|
|
20
20
|
phase: `applying` | `building`
|
|
21
21
|
update: TransactionUpdate<F>
|
|
22
22
|
toolkit: ActorToolkit
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { LazyMap } from "../lazy-map"
|
|
1
2
|
import type { Store } from "../store"
|
|
2
|
-
import type {
|
|
3
|
+
import type { Fn } from "../utility-types"
|
|
3
4
|
import type { TransactionEpoch, TransactionProgress } from "."
|
|
4
5
|
|
|
5
6
|
export interface RootStore extends Store {
|
|
@@ -8,9 +9,10 @@ export interface RootStore extends Store {
|
|
|
8
9
|
child: ChildStore | null
|
|
9
10
|
}
|
|
10
11
|
export interface ChildStore extends Store {
|
|
11
|
-
transactionMeta: TransactionProgress<
|
|
12
|
+
transactionMeta: TransactionProgress<Fn>
|
|
12
13
|
parent: ChildStore | RootStore
|
|
13
14
|
child: ChildStore | null
|
|
15
|
+
valueMap: LazyMap<string, any>
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function isRootStore(store: Store): store is RootStore {
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
TransactionToken,
|
|
7
7
|
TransactionUpdate,
|
|
8
8
|
} from "atom.io"
|
|
9
|
-
import type {
|
|
9
|
+
import type { Fn, Store, Timeline } from "atom.io/internal"
|
|
10
10
|
|
|
11
11
|
import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
|
|
12
12
|
import type { SelectorTokenIndex } from "./attach-selector-index"
|
|
@@ -20,9 +20,9 @@ import { attachTypeSelectors } from "./attach-type-selectors"
|
|
|
20
20
|
export type IntrospectionStates = {
|
|
21
21
|
atomIndex: AtomToken<AtomTokenIndex>
|
|
22
22
|
selectorIndex: AtomToken<SelectorTokenIndex>
|
|
23
|
-
transactionIndex: AtomToken<TransactionToken<
|
|
23
|
+
transactionIndex: AtomToken<TransactionToken<Fn>[]>
|
|
24
24
|
transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
|
|
25
|
-
TransactionUpdate<
|
|
25
|
+
TransactionUpdate<Fn>[],
|
|
26
26
|
string
|
|
27
27
|
>
|
|
28
28
|
timelineIndex: AtomToken<TimelineToken<any>[]>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { AtomToken, TransactionToken } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTransactionIndex = (
|
|
6
6
|
store: Store,
|
|
7
|
-
): AtomToken<TransactionToken<
|
|
8
|
-
return createRegularAtom<TransactionToken<
|
|
7
|
+
): AtomToken<TransactionToken<Fn>[]> => {
|
|
8
|
+
return createRegularAtom<TransactionToken<Fn>[]>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Transaction Token Index`,
|
|
12
12
|
default: () => {
|
|
13
|
-
const tokens: TransactionToken<
|
|
13
|
+
const tokens: TransactionToken<Fn>[] = []
|
|
14
14
|
for (const [key] of store.transactions) {
|
|
15
15
|
if (isReservedIntrospectionKey(key)) {
|
|
16
16
|
continue
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ReadonlyPureSelectorFamilyToken, TransactionUpdate } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTransactionLogs = (
|
|
6
6
|
store: Store,
|
|
7
|
-
): ReadonlyPureSelectorFamilyToken<TransactionUpdate<
|
|
7
|
+
): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Fn>[], string> => {
|
|
8
8
|
const transactionUpdateLogAtoms = createRegularAtomFamily<
|
|
9
|
-
TransactionUpdate<
|
|
9
|
+
TransactionUpdate<Fn>[],
|
|
10
10
|
string
|
|
11
11
|
>(store, {
|
|
12
12
|
key: `🔍 Transaction Update Log (Internal)`,
|
|
@@ -23,7 +23,7 @@ export const attachTransactionLogs = (
|
|
|
23
23
|
],
|
|
24
24
|
})
|
|
25
25
|
const findTransactionUpdateLogState = createSelectorFamily<
|
|
26
|
-
TransactionUpdate<
|
|
26
|
+
TransactionUpdate<Fn>[],
|
|
27
27
|
string
|
|
28
28
|
>(store, {
|
|
29
29
|
key: `🔍 Transaction Update Log`,
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type ReadableToken,
|
|
5
5
|
type SelectorToken,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import
|
|
7
|
+
import { IMPLICIT, type Store } from "atom.io/internal"
|
|
8
8
|
|
|
9
9
|
import type { FamilyNode } from "."
|
|
10
10
|
import type { AtomTokenIndex } from "./attach-atom-index"
|
|
@@ -22,7 +22,7 @@ export type ListResourcesParam = {
|
|
|
22
22
|
* @experimental
|
|
23
23
|
*/
|
|
24
24
|
export class Auditor {
|
|
25
|
-
public readonly store:
|
|
25
|
+
public readonly store: Store
|
|
26
26
|
public auditorCreatedAt: number = performance.now()
|
|
27
27
|
public statesCreatedAt: Map<string, number> = new Map()
|
|
28
28
|
public readonly atomIndex: AtomToken<AtomTokenIndex>
|
|
@@ -37,7 +37,7 @@ export class Auditor {
|
|
|
37
37
|
/**
|
|
38
38
|
* @param {Store} store - The store to audit.
|
|
39
39
|
*/
|
|
40
|
-
public constructor(store:
|
|
40
|
+
public constructor(store: Store = IMPLICIT.STORE) {
|
|
41
41
|
this.store = store
|
|
42
42
|
this.atomIndex = attachAtomIndex(this.store)
|
|
43
43
|
this.selectorIndex = attachSelectorIndex(this.store)
|
package/src/main/atom.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
|
|
|
34
34
|
return createRegularAtom(IMPLICIT.STORE, options, undefined)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type MutableAtomOptions<T extends Transceiver<any, any>> = {
|
|
37
|
+
export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
|
|
38
38
|
/** The unique identifier of the atom */
|
|
39
39
|
key: string
|
|
40
40
|
/** A constructor for the atom's value */
|
|
@@ -51,7 +51,7 @@ export type MutableAtomOptions<T extends Transceiver<any, any>> = {
|
|
|
51
51
|
* @returns
|
|
52
52
|
* A reference to the atom created: a {@link MutableAtomToken}
|
|
53
53
|
*/
|
|
54
|
-
export function mutableAtom<T extends Transceiver<any, any>>(
|
|
54
|
+
export function mutableAtom<T extends Transceiver<any, any, any>>(
|
|
55
55
|
options: MutableAtomOptions<T>,
|
|
56
56
|
): MutableAtomToken<T> {
|
|
57
57
|
return createMutableAtom(IMPLICIT.STORE, options, undefined)
|
|
@@ -99,7 +99,7 @@ export function atomFamily<T, K extends Canonical>(
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export type MutableAtomFamilyOptions<
|
|
102
|
-
T extends Transceiver<any, any>,
|
|
102
|
+
T extends Transceiver<any, any, any>,
|
|
103
103
|
K extends Canonical,
|
|
104
104
|
> = {
|
|
105
105
|
/** The unique identifier of the atom family */
|
|
@@ -119,7 +119,7 @@ export type MutableAtomFamilyOptions<
|
|
|
119
119
|
* A reference to the atom family created: a {@link MutableAtomFamilyToken}
|
|
120
120
|
*/
|
|
121
121
|
export function mutableAtomFamily<
|
|
122
|
-
T extends Transceiver<any, any>,
|
|
122
|
+
T extends Transceiver<any, any, any>,
|
|
123
123
|
K extends Canonical,
|
|
124
124
|
>(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
|
|
125
125
|
return createMutableAtomFamily(IMPLICIT.STORE, options)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { disposeFromStore, IMPLICIT } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
@@ -19,6 +19,7 @@ export function disposeState(token: ReadableToken<any>): void
|
|
|
19
19
|
*
|
|
20
20
|
* @param token - The token of the state family to dispose
|
|
21
21
|
* @param key - The unique key of the state to dispose
|
|
22
|
+
* @overload Streamlined
|
|
22
23
|
*/
|
|
23
24
|
export function disposeState<K extends Canonical>(
|
|
24
25
|
token: ReadableFamilyToken<any, K>,
|
|
@@ -30,8 +31,8 @@ export function disposeState(
|
|
|
30
31
|
| [token: ReadableToken<any>]
|
|
31
32
|
): void {
|
|
32
33
|
if (params.length === 2) {
|
|
33
|
-
|
|
34
|
+
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
34
35
|
} else {
|
|
35
|
-
|
|
36
|
+
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
36
37
|
}
|
|
37
38
|
}
|