atom.io 0.36.0 → 0.36.2
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 +93 -73
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +233 -248
- 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 +29 -37
- 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 +60 -41
- 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 +26 -21
- package/src/internal/index.ts +8 -8
- package/src/internal/join/create-join.ts +3 -2
- 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 -4
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/set-state/evict-downstream.ts +17 -15
- package/src/internal/set-state/index.ts +1 -0
- package/src/internal/set-state/reset-in-store.ts +6 -50
- package/src/internal/set-state/set-atom.ts +17 -24
- package/src/internal/set-state/set-into-store.ts +29 -13
- 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 +8 -8
- package/src/internal/subscribe/subscribe-to-timeline.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 +9 -18
- 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Json } from "atom.io/json"
|
|
2
2
|
|
|
3
3
|
export interface Transceiver<
|
|
4
|
+
V,
|
|
4
5
|
S extends Json.Serializable,
|
|
5
6
|
J extends Json.Serializable,
|
|
6
7
|
> {
|
|
@@ -9,20 +10,21 @@ export interface Transceiver<
|
|
|
9
10
|
subscribe: (key: string, fn: (update: S) => void) => () => void
|
|
10
11
|
cacheUpdateNumber: number
|
|
11
12
|
getUpdateNumber: (update: S) => number
|
|
13
|
+
view: () => V
|
|
12
14
|
toJSON: () => J
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
// biome-ignore format: intersection
|
|
16
18
|
export type TransceiverConstructor<
|
|
17
19
|
J extends Json.Serializable,
|
|
18
|
-
T extends Transceiver<any, J>
|
|
20
|
+
T extends Transceiver<any, any, J>
|
|
19
21
|
> =
|
|
20
22
|
& ( new () => T )
|
|
21
23
|
& { fromJSON: (json: J) => T }
|
|
22
24
|
|
|
23
25
|
export function isTransceiver(
|
|
24
26
|
value: unknown,
|
|
25
|
-
): value is Transceiver<Json.Serializable, Json.Serializable> {
|
|
27
|
+
): value is Transceiver<any, Json.Serializable, Json.Serializable> {
|
|
26
28
|
return (
|
|
27
29
|
typeof value === `object` &&
|
|
28
30
|
value !== null &&
|
|
@@ -34,21 +36,20 @@ export function isTransceiver(
|
|
|
34
36
|
|
|
35
37
|
export type TransceiverMode = `playback` | `record` | `transaction`
|
|
36
38
|
|
|
37
|
-
export type
|
|
38
|
-
infer S,
|
|
39
|
-
any
|
|
40
|
-
>
|
|
41
|
-
? S
|
|
42
|
-
: never
|
|
39
|
+
export type ViewOf<T> = T extends Transceiver<infer V, any, any> ? V : T
|
|
43
40
|
|
|
44
|
-
export type
|
|
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,
|
|
45
46
|
any,
|
|
46
47
|
infer J
|
|
47
48
|
>
|
|
48
49
|
? J
|
|
49
50
|
: never
|
|
50
51
|
|
|
51
|
-
export type ConstructorOf<T extends Transceiver<any, any>> =
|
|
52
|
+
export type ConstructorOf<T extends Transceiver<any, any, any>> =
|
|
52
53
|
TransceiverConstructor<AsJSON<T>, T>
|
|
53
54
|
|
|
54
55
|
/*
|
|
@@ -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), readonlySelector, constant)
|
|
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, readonlySelector, value)
|
|
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, mySelector, constant)
|
|
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, mySelector, newValue)
|
|
54
54
|
markDone(innerTarget, key)
|
|
55
55
|
if (isRootStore(innerTarget)) {
|
|
56
56
|
subject.next({ newValue, oldValue })
|
|
@@ -67,7 +67,6 @@ export const createWritableHeldSelector = <T extends object>(
|
|
|
67
67
|
...(family && { family }),
|
|
68
68
|
}
|
|
69
69
|
target.writableSelectors.set(key, mySelector)
|
|
70
|
-
// const initialValue = getSelf()
|
|
71
70
|
|
|
72
71
|
const token: WritableHeldSelectorToken<T> = { key, type }
|
|
73
72
|
if (family) {
|
|
@@ -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, mySelector, value)
|
|
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, mySelector, newValue)
|
|
54
54
|
markDone(innerTarget, options.key)
|
|
55
55
|
if (isRootStore(innerTarget)) {
|
|
56
56
|
subject.next({ newValue, oldValue })
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type { Atom
|
|
1
|
+
import type { Atom } from ".."
|
|
2
2
|
import { evictCachedValue } from "../caching"
|
|
3
3
|
import { newest } from "../lineage"
|
|
4
4
|
import { isDone, markDone } from "../operation"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function evictDownstreamFromAtom(store: Store, atom: Atom<any>): void {
|
|
8
8
|
const target = newest(store)
|
|
9
|
-
const
|
|
9
|
+
const { key, type } = atom
|
|
10
|
+
const downstreamKeys = target.selectorAtoms.getRelatedKeys(key)
|
|
10
11
|
target.logger.info(
|
|
11
12
|
`🧹`,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
type,
|
|
14
|
+
key,
|
|
14
15
|
downstreamKeys
|
|
15
16
|
? `evicting ${downstreamKeys.size} states downstream:`
|
|
16
17
|
: `no downstream states`,
|
|
@@ -20,36 +21,37 @@ export function evictDownStream(store: Store, atom: Atom<any>): void {
|
|
|
20
21
|
if (target.operation.open) {
|
|
21
22
|
target.logger.info(
|
|
22
23
|
`🧹`,
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
type,
|
|
25
|
+
key,
|
|
25
26
|
`[ ${[...target.operation.done].join(`, `)} ] already done`,
|
|
26
27
|
)
|
|
27
28
|
}
|
|
28
|
-
for (const
|
|
29
|
-
if (isDone(target,
|
|
29
|
+
for (const downstreamKey of downstreamKeys) {
|
|
30
|
+
if (isDone(target, downstreamKey)) {
|
|
30
31
|
continue
|
|
31
32
|
}
|
|
32
|
-
evictCachedValue(target,
|
|
33
|
-
markDone(target,
|
|
33
|
+
evictCachedValue(target, downstreamKey)
|
|
34
|
+
markDone(target, downstreamKey)
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export function
|
|
39
|
+
export function evictDownstreamFromSelector(
|
|
39
40
|
store: Store,
|
|
40
|
-
|
|
41
|
+
selectorKey: string,
|
|
41
42
|
): void {
|
|
42
43
|
const target = newest(store)
|
|
43
44
|
const relationEntries = target.selectorGraph
|
|
44
45
|
.getRelationEntries({
|
|
45
|
-
upstreamSelectorKey:
|
|
46
|
+
upstreamSelectorKey: selectorKey,
|
|
46
47
|
})
|
|
47
|
-
.filter(([_, { source }]) => source ===
|
|
48
|
+
.filter(([_, { source }]) => source === selectorKey)
|
|
48
49
|
for (const [downstreamSelectorKey] of relationEntries) {
|
|
49
50
|
if (isDone(target, downstreamSelectorKey)) {
|
|
50
51
|
continue
|
|
51
52
|
}
|
|
52
53
|
evictCachedValue(target, downstreamSelectorKey)
|
|
53
54
|
markDone(target, downstreamSelectorKey)
|
|
55
|
+
evictDownstreamFromSelector(store, downstreamSelectorKey)
|
|
54
56
|
}
|
|
55
57
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
2
|
-
import {
|
|
2
|
+
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import { findInStore } from "../families"
|
|
5
|
-
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
6
|
-
import { closeOperation, openOperation } from "../operation"
|
|
7
4
|
import type { Store } from "../store"
|
|
8
|
-
import {
|
|
9
|
-
|
|
5
|
+
import { setIntoStore } from "./set-into-store"
|
|
6
|
+
|
|
7
|
+
export const RESET_STATE: unique symbol = Symbol(`RESET`)
|
|
10
8
|
|
|
11
9
|
export function resetInStore(store: Store, token: WritableToken<any>): void
|
|
12
10
|
|
|
@@ -27,52 +25,10 @@ export function resetInStore<T>(
|
|
|
27
25
|
let key: Canonical | null
|
|
28
26
|
if (params.length === 1) {
|
|
29
27
|
token = params[0]
|
|
30
|
-
|
|
31
|
-
if (family) {
|
|
32
|
-
key = token.family ? parseJson(token.family.subKey) : null
|
|
33
|
-
token = findInStore(store, family, key)
|
|
34
|
-
}
|
|
28
|
+
setIntoStore(store, token, RESET_STATE)
|
|
35
29
|
} else {
|
|
36
30
|
family = params[0]
|
|
37
31
|
key = params[1]
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (`counterfeit` in token && `family` in token) {
|
|
42
|
-
const subKey = token.family.subKey
|
|
43
|
-
const disposal = store.disposalTraces.buffer.find(
|
|
44
|
-
(item) => item?.key === subKey,
|
|
45
|
-
)
|
|
46
|
-
store.logger.error(
|
|
47
|
-
`❌`,
|
|
48
|
-
token.type,
|
|
49
|
-
token.key,
|
|
50
|
-
`could not be reset because it was not found in the store "${store.config.name}".`,
|
|
51
|
-
disposal
|
|
52
|
-
? `This state was previously disposed:\n${disposal.trace}`
|
|
53
|
-
: `No previous disposal trace was found.`,
|
|
54
|
-
)
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const rejectionTime = openOperation(store, token)
|
|
59
|
-
if (rejectionTime) {
|
|
60
|
-
const unsubscribe = store.on.operationClose.subscribe(
|
|
61
|
-
`waiting to reset "${token.key}" at T-${rejectionTime}`,
|
|
62
|
-
() => {
|
|
63
|
-
unsubscribe()
|
|
64
|
-
store.logger.info(
|
|
65
|
-
`🟢`,
|
|
66
|
-
token.type,
|
|
67
|
-
token.key,
|
|
68
|
-
`resuming deferred resetState from T-${rejectionTime}`,
|
|
69
|
-
)
|
|
70
|
-
resetInStore(store, token)
|
|
71
|
-
},
|
|
72
|
-
)
|
|
73
|
-
return
|
|
32
|
+
setIntoStore(store, family, key, RESET_STATE)
|
|
74
33
|
}
|
|
75
|
-
const state = withdraw(store, token)
|
|
76
|
-
resetAtomOrSelector(store, state)
|
|
77
|
-
closeOperation(store)
|
|
78
34
|
}
|
|
@@ -1,33 +1,27 @@
|
|
|
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
|
-
import {
|
|
12
|
+
import { evictDownstreamFromAtom } from "./evict-downstream"
|
|
13
13
|
|
|
14
14
|
export const setAtom = <T>(
|
|
15
15
|
target: Store,
|
|
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, newValue)
|
|
29
23
|
markDone(target, atom.key)
|
|
30
|
-
|
|
24
|
+
evictDownstreamFromAtom(target, atom)
|
|
31
25
|
const update = { oldValue, newValue }
|
|
32
26
|
if (!isChildStore(target)) {
|
|
33
27
|
emitUpdate(target, atom, update)
|
|
@@ -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
|
+
evictDownstreamFromAtom(target, mutable)
|
|
63
|
+
}
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -6,19 +6,21 @@ import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
|
6
6
|
import { closeOperation, openOperation } from "../operation"
|
|
7
7
|
import type { Store } from "../store"
|
|
8
8
|
import { withdraw } from "../store"
|
|
9
|
+
import { resetAtomOrSelector } from "./reset-atom-or-selector"
|
|
10
|
+
import { RESET_STATE } from "./reset-in-store"
|
|
9
11
|
import { setAtomOrSelector } from "./set-atom-or-selector"
|
|
10
12
|
|
|
11
13
|
export function setIntoStore<T, New extends T>(
|
|
12
14
|
store: Store,
|
|
13
15
|
token: WritableToken<T>,
|
|
14
|
-
value: New | ((oldValue: T) => New),
|
|
16
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
15
17
|
): void
|
|
16
18
|
|
|
17
19
|
export function setIntoStore<T, K extends Canonical, New extends T>(
|
|
18
20
|
store: Store,
|
|
19
21
|
token: WritableFamilyToken<T, K>,
|
|
20
22
|
key: K,
|
|
21
|
-
value: New | ((oldValue: T) => New),
|
|
23
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
22
24
|
): void
|
|
23
25
|
|
|
24
26
|
export function setIntoStore<T, New extends T>(
|
|
@@ -27,20 +29,24 @@ export function setIntoStore<T, New extends T>(
|
|
|
27
29
|
| [
|
|
28
30
|
token: WritableFamilyToken<T, Canonical>,
|
|
29
31
|
key: Canonical,
|
|
30
|
-
value: New | ((oldValue: T) => New),
|
|
32
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
33
|
+
]
|
|
34
|
+
| [
|
|
35
|
+
token: WritableToken<T>,
|
|
36
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
31
37
|
]
|
|
32
|
-
| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
|
|
33
38
|
): void {
|
|
34
39
|
let token: WritableToken<T>
|
|
35
40
|
let family: WritableFamilyToken<T, Canonical> | null
|
|
36
41
|
let key: Canonical | null
|
|
37
|
-
let value: New | ((oldValue: T) => New)
|
|
42
|
+
let value: New | typeof RESET_STATE | ((oldValue: T) => New)
|
|
38
43
|
if (params.length === 2) {
|
|
39
44
|
token = params[0]
|
|
40
45
|
value = params[1]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
if (token.family) {
|
|
47
|
+
// biome-ignore lint/style/noNonNullAssertion: this token belongs to a family
|
|
48
|
+
family = getFamilyOfToken(store, token)!
|
|
49
|
+
key = parseJson(token.family.subKey)
|
|
44
50
|
token = findInStore(store, family, key)
|
|
45
51
|
}
|
|
46
52
|
} else {
|
|
@@ -50,6 +56,8 @@ export function setIntoStore<T, New extends T>(
|
|
|
50
56
|
token = findInStore(store, family, key)
|
|
51
57
|
}
|
|
52
58
|
|
|
59
|
+
const action = value === RESET_STATE ? `reset` : `set`
|
|
60
|
+
|
|
53
61
|
if (`counterfeit` in token && `family` in token) {
|
|
54
62
|
const subKey = token.family.subKey
|
|
55
63
|
const disposal = store.disposalTraces.buffer.find(
|
|
@@ -59,7 +67,9 @@ export function setIntoStore<T, New extends T>(
|
|
|
59
67
|
`❌`,
|
|
60
68
|
token.type,
|
|
61
69
|
token.key,
|
|
62
|
-
`could not be
|
|
70
|
+
`could not be`,
|
|
71
|
+
action,
|
|
72
|
+
`because it was not found in the store "${store.config.name}".`,
|
|
63
73
|
disposal
|
|
64
74
|
? `This state was previously disposed:\n${disposal.trace}`
|
|
65
75
|
: `No previous disposal trace was found.`,
|
|
@@ -70,14 +80,16 @@ export function setIntoStore<T, New extends T>(
|
|
|
70
80
|
const rejectionTime = openOperation(store, token)
|
|
71
81
|
if (rejectionTime) {
|
|
72
82
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
73
|
-
`waiting to
|
|
74
|
-
()
|
|
83
|
+
`waiting to ${action} "${token.key}" at T-${rejectionTime}`,
|
|
84
|
+
function waitUntilOperationCloseToSetState() {
|
|
75
85
|
unsubscribe()
|
|
76
86
|
store.logger.info(
|
|
77
87
|
`🟢`,
|
|
78
88
|
token.type,
|
|
79
89
|
token.key,
|
|
80
|
-
`resuming deferred
|
|
90
|
+
`resuming deferred`,
|
|
91
|
+
action,
|
|
92
|
+
`from T-${rejectionTime}`,
|
|
81
93
|
)
|
|
82
94
|
setIntoStore(store, token, value)
|
|
83
95
|
},
|
|
@@ -85,6 +97,10 @@ export function setIntoStore<T, New extends T>(
|
|
|
85
97
|
return
|
|
86
98
|
}
|
|
87
99
|
const state = withdraw(store, token)
|
|
88
|
-
|
|
100
|
+
if (value === RESET_STATE) {
|
|
101
|
+
resetAtomOrSelector(store, state)
|
|
102
|
+
} else {
|
|
103
|
+
setAtomOrSelector(store, state, value)
|
|
104
|
+
}
|
|
89
105
|
closeOperation(store)
|
|
90
106
|
}
|
|
@@ -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,13 +7,13 @@ import type {
|
|
|
7
7
|
TransactionUpdateHandler,
|
|
8
8
|
UpdateHandler,
|
|
9
9
|
} from "atom.io"
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "
|
|
10
|
+
|
|
11
|
+
import { arbitrary } from "../arbitrary"
|
|
12
|
+
import type { Store } from "../store"
|
|
13
|
+
import type { Fn } from "../utility-types"
|
|
14
|
+
import { subscribeToState } from "./subscribe-to-state"
|
|
15
|
+
import { subscribeToTimeline } from "./subscribe-to-timeline"
|
|
16
|
+
import { subscribeToTransaction } from "./subscribe-to-transaction"
|
|
17
17
|
|
|
18
18
|
export function subscribeInStore<T>(
|
|
19
19
|
store: Store,
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import type { TimelineManageable, TimelineToken, TimelineUpdate } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { Store } from "
|
|
4
|
-
import { withdraw } from "
|
|
3
|
+
import type { Store } from "../store/store"
|
|
4
|
+
import { withdraw } from "../store/withdraw"
|
|
5
5
|
|
|
6
6
|
export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
|
|
7
7
|
store: Store,
|