atom.io 0.40.6 → 0.40.8
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/README.md +1 -1
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.js +1 -2
- package/dist/data/index.js.map +1 -1
- package/dist/employ-socket-D6wgByWh.js +12 -0
- package/dist/employ-socket-D6wgByWh.js.map +1 -0
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/has-role-CMlaUlaf.js +1133 -0
- package/dist/has-role-CMlaUlaf.js.map +1 -0
- package/dist/internal/index.d.ts +248 -248
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +590 -1803
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +1 -1
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +13 -32
- package/dist/introspection/index.js.map +1 -1
- package/dist/is-fn-DY1wZ-md.js +10 -0
- package/dist/is-fn-DY1wZ-md.js.map +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +33 -33
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +3 -4
- package/dist/main/index.js.map +1 -1
- package/dist/mutex-store-CSvxY9i3.js +11 -0
- package/dist/mutex-store-CSvxY9i3.js.map +1 -0
- package/dist/react/index.d.ts +5 -5
- 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 +9 -11
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +7 -15
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +4 -35
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +6 -9
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +96 -88
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +17 -13
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +39 -50
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +83 -84
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +604 -543
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +5 -4
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js +35 -22
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/shared-room-store-BfW3nWif.js +31 -0
- package/dist/shared-room-store-BfW3nWif.js.map +1 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +4 -8
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/web/index.d.ts +3 -3
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +4 -3
- package/dist/web/index.js.map +1 -1
- package/package.json +13 -13
- package/src/internal/atom/create-regular-atom.ts +5 -4
- package/src/internal/atom/dispose-atom.ts +7 -2
- package/src/internal/atom/has-role.ts +3 -3
- package/src/internal/caching.ts +4 -2
- package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
- package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
- package/src/internal/families/create-regular-atom-family.ts +2 -1
- package/src/internal/families/create-writable-held-selector-family.ts +2 -1
- package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
- package/src/internal/families/dispose-from-store.ts +4 -4
- package/src/internal/families/find-in-store.ts +10 -10
- package/src/internal/families/get-family-of-token.ts +2 -2
- package/src/internal/families/index.ts +1 -0
- package/src/internal/families/mint-in-store.ts +54 -19
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/get-fallback.ts +2 -2
- package/src/internal/get-state/get-from-store.ts +5 -5
- package/src/internal/get-state/read-or-compute-value.ts +1 -1
- package/src/internal/get-state/reduce-reference.ts +8 -6
- package/src/internal/index.ts +2 -220
- package/src/internal/molecule.ts +1 -2
- package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
- package/src/internal/mutable/create-mutable-atom.ts +4 -2
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +2 -1
- package/src/internal/mutable/tracker.ts +71 -59
- package/src/internal/safe-compute.ts +1 -1
- package/src/internal/selector/create-readonly-held-selector.ts +2 -1
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
- package/src/internal/selector/create-writable-held-selector.ts +2 -1
- package/src/internal/selector/create-writable-pure-selector.ts +2 -1
- package/src/internal/selector/dispose-selector.ts +3 -2
- package/src/internal/selector/register-selector.ts +8 -5
- package/src/internal/selector/trace-selector-atoms.ts +2 -1
- package/src/internal/set-state/dispatch-state-update.ts +3 -2
- package/src/internal/set-state/evict-downstream.ts +1 -1
- package/src/internal/set-state/operate-on-store.ts +16 -22
- package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
- package/src/internal/set-state/reset-in-store.ts +5 -5
- package/src/internal/set-state/set-atom-or-selector.ts +2 -2
- package/src/internal/set-state/set-atom.ts +4 -2
- package/src/internal/set-state/set-into-store.ts +21 -39
- package/src/internal/set-state/set-selector.ts +3 -2
- package/src/internal/state-types.ts +228 -0
- package/src/internal/store/deposit.ts +4 -4
- package/src/internal/store/index.ts +0 -1
- package/src/internal/store/store.ts +9 -9
- package/src/internal/store/withdraw.ts +4 -4
- package/src/internal/subscribe/recall-state.ts +1 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
- package/src/internal/subscribe/subscribe-to-state.ts +9 -0
- package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
- package/src/internal/transaction/build-transaction.ts +3 -2
- package/src/internal/transaction/index.ts +1 -23
- package/src/internal/transaction/is-root-store.ts +4 -1
- package/src/internal/transaction/transaction-meta-progress.ts +22 -0
- package/src/main/atom.ts +1 -2
- package/src/main/find-state.ts +5 -5
- package/src/main/get-state.ts +4 -4
- package/src/main/realm.ts +2 -2
- package/src/main/set-state.ts +10 -10
- package/src/react/parse-state-overloads.ts +3 -3
- package/src/react/use-i.ts +6 -4
- package/src/react/use-loadable.ts +4 -10
- package/src/react/use-o.ts +6 -4
- package/src/react-devtools/store.ts +6 -6
- package/src/realtime/index.ts +1 -0
- package/src/realtime/mutex-store.ts +11 -0
- package/src/realtime/realtime-continuity.ts +1 -5
- package/src/realtime-client/index.ts +0 -1
- package/src/realtime-client/pull-atom-family-member.ts +14 -17
- package/src/realtime-client/pull-atom.ts +1 -1
- package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
- package/src/realtime-client/pull-selector-family-member.ts +8 -35
- package/src/realtime-client/pull-selector-roots.ts +90 -0
- package/src/realtime-client/pull-selector.ts +2 -27
- package/src/realtime-client/push-state.ts +33 -5
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
- package/src/realtime-react/index.ts +2 -2
- package/src/realtime-react/realtime-context.tsx +9 -5
- package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
- package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
- package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
- package/src/realtime-react/use-push.ts +7 -3
- package/src/realtime-react/use-realtime-service.ts +11 -11
- package/src/realtime-react/use-single-effect.ts +11 -14
- package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
- package/src/realtime-server/continuity/provide-continuity.ts +50 -0
- package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
- package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
- package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
- package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
- package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
- package/src/realtime-server/employ-socket.ts +14 -0
- package/src/realtime-server/index.ts +3 -22
- package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
- package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
- package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
- package/src/realtime-server/realtime-family-provider.ts +78 -29
- package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
- package/src/realtime-server/realtime-mutable-provider.ts +30 -22
- package/src/realtime-server/realtime-server-stores/index.ts +0 -2
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
- package/src/realtime-server/realtime-state-provider.ts +30 -29
- package/src/realtime-server/realtime-state-receiver.ts +62 -16
- package/src/realtime-server/server-config.ts +8 -0
- package/src/realtime-server/socket-interface.ts +14 -0
- package/src/realtime-testing/setup-realtime-test.tsx +70 -31
- package/src/web/index.ts +1 -1
- package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
- package/src/internal/store/mint-or-counterfeit.ts +0 -108
- package/src/realtime-client/server-action.ts +0 -23
- package/src/realtime-react/on-mount.ts +0 -5
- package/src/realtime-react/use-server-action.ts +0 -19
- package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
- package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
- package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
- package/src/realtime-server/realtime-action-receiver.ts +0 -40
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ReadableToken, ViewOf } from "atom.io"
|
|
2
2
|
import { type Canonical, stringifyJson } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { ReadableFamily } from "
|
|
4
|
+
import type { ReadableFamily } from "../state-types"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
7
|
export function getFallback<T, K extends Canonical, E>(
|
|
8
8
|
store: Store,
|
|
9
9
|
token: ReadableToken<T, K, E>,
|
|
10
10
|
family: ReadableFamily<T, K, E>,
|
|
11
|
-
subKey: K
|
|
11
|
+
subKey: NoInfer<K>,
|
|
12
12
|
): ViewOf<E | T> {
|
|
13
13
|
const disposal = store.disposalTraces.buffer.find(
|
|
14
14
|
(item) => item?.key === stringifyJson(subKey),
|
|
@@ -16,20 +16,20 @@ export function getFromStore<T, E>(
|
|
|
16
16
|
export function getFromStore<T, K extends Canonical, E>(
|
|
17
17
|
store: Store,
|
|
18
18
|
token: ReadableFamilyToken<T, K, E>,
|
|
19
|
-
key: K
|
|
19
|
+
key: NoInfer<K>,
|
|
20
20
|
): ViewOf<E | T>
|
|
21
21
|
|
|
22
|
-
export function getFromStore<T, K extends Canonical,
|
|
22
|
+
export function getFromStore<T, K extends Canonical, E>(
|
|
23
23
|
store: Store,
|
|
24
24
|
...params:
|
|
25
|
-
| [token: ReadableFamilyToken<T, K, E>, key:
|
|
25
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
26
26
|
| [token: ReadableToken<T, any, E>]
|
|
27
27
|
): ViewOf<E | T>
|
|
28
28
|
|
|
29
|
-
export function getFromStore<T, K extends Canonical,
|
|
29
|
+
export function getFromStore<T, K extends Canonical, E>(
|
|
30
30
|
store: Store,
|
|
31
31
|
...params:
|
|
32
|
-
| [token: ReadableFamilyToken<T, K, E>, key:
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
33
33
|
| [token: ReadableToken<T, any, E>]
|
|
34
34
|
): ViewOf<E | T> {
|
|
35
35
|
const { token, family, subKey } = reduceReference(store, ...params)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ViewOf } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { ReadableState } from ".."
|
|
4
3
|
import { readFromCache, writeToCache } from "../caching"
|
|
5
4
|
import { safeCompute } from "../safe-compute"
|
|
5
|
+
import type { ReadableState } from "../state-types"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
|
|
8
8
|
export function readOrComputeValue<T, E>(
|
|
@@ -5,23 +5,25 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
import { type Canonical, parseJson } from "atom.io/json"
|
|
7
7
|
|
|
8
|
-
import type { ReadableFamily, Subject } from ".."
|
|
9
|
-
import { isChildStore, isRootStore, newest } from ".."
|
|
10
8
|
import { seekInStore } from "../families"
|
|
11
9
|
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
12
10
|
import { mintInStore, MUST_CREATE } from "../families/mint-in-store"
|
|
11
|
+
import { newest } from "../lineage"
|
|
12
|
+
import type { ReadableFamily } from "../state-types"
|
|
13
13
|
import type { Store } from "../store"
|
|
14
14
|
import { withdraw } from "../store"
|
|
15
|
+
import type { Subject } from "../subject"
|
|
16
|
+
import { isChildStore, isRootStore } from "../transaction"
|
|
15
17
|
|
|
16
18
|
export function reduceReference<T, K extends Canonical, E>(
|
|
17
19
|
store: Store,
|
|
18
20
|
...params:
|
|
19
|
-
| [token: ReadableFamilyToken<T, K, E>, key: K]
|
|
21
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
20
22
|
| [token: ReadableToken<T, K, E>]
|
|
21
23
|
): {
|
|
22
24
|
token: ReadableToken<T, K, E>
|
|
23
25
|
family: ReadableFamily<T, K, E> | undefined
|
|
24
|
-
subKey: K | undefined
|
|
26
|
+
subKey: NoInfer<K> | undefined
|
|
25
27
|
isNew: boolean
|
|
26
28
|
} {
|
|
27
29
|
let existingToken: ReadableToken<T, K, E> | undefined
|
|
@@ -45,7 +47,7 @@ export function reduceReference<T, K extends Canonical, E>(
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
if (!existingToken) {
|
|
48
|
-
brandNewToken = mintInStore(store, familyToken, subKey
|
|
50
|
+
brandNewToken = mintInStore(MUST_CREATE, store, familyToken, subKey)
|
|
49
51
|
token = brandNewToken
|
|
50
52
|
} else {
|
|
51
53
|
token = existingToken
|
|
@@ -56,7 +58,7 @@ export function reduceReference<T, K extends Canonical, E>(
|
|
|
56
58
|
subKey = params[1]
|
|
57
59
|
existingToken = seekInStore(store, family, subKey)
|
|
58
60
|
if (!existingToken) {
|
|
59
|
-
brandNewToken = mintInStore(store, family, subKey
|
|
61
|
+
brandNewToken = mintInStore(MUST_CREATE, store, family, subKey)
|
|
60
62
|
token = brandNewToken
|
|
61
63
|
} else {
|
|
62
64
|
token = existingToken
|
package/src/internal/index.ts
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FamilyMetadata,
|
|
3
|
-
MutableAtomFamilyToken,
|
|
4
|
-
MutableAtomToken,
|
|
5
|
-
ReadonlyHeldSelectorFamilyToken,
|
|
6
|
-
ReadonlyHeldSelectorToken,
|
|
7
|
-
ReadonlyPureSelectorFamilyToken,
|
|
8
|
-
ReadonlyPureSelectorToken,
|
|
9
|
-
RegularAtomFamilyToken,
|
|
10
|
-
RegularAtomToken,
|
|
11
|
-
StateLifecycleEvent,
|
|
12
|
-
StateUpdate,
|
|
13
|
-
WritableHeldSelectorFamilyToken,
|
|
14
|
-
WritableHeldSelectorToken,
|
|
15
|
-
WritablePureSelectorFamilyToken,
|
|
16
|
-
WritablePureSelectorToken,
|
|
17
|
-
} from "atom.io"
|
|
18
|
-
import type { Canonical } from "atom.io/json"
|
|
19
|
-
|
|
20
|
-
import type { internalRole } from "./atom/has-role"
|
|
21
|
-
import type { ConstructorOf, Transceiver } from "./mutable"
|
|
22
|
-
import type { Store } from "./store"
|
|
23
|
-
import type { Subject } from "./subject"
|
|
24
|
-
import type { Timeline } from "./timeline"
|
|
25
|
-
import type { RootStore, Transaction } from "./transaction"
|
|
26
|
-
import type { Ctor, Flat } from "./utility-types"
|
|
27
|
-
|
|
28
1
|
export * from "./arbitrary"
|
|
29
2
|
export * from "./atom"
|
|
30
3
|
export * from "./caching"
|
|
@@ -36,6 +9,7 @@ export * from "./get-environment-data"
|
|
|
36
9
|
export * from "./get-state"
|
|
37
10
|
export * from "./get-trace"
|
|
38
11
|
export * from "./install-into-store"
|
|
12
|
+
export * from "./is-fn"
|
|
39
13
|
export * from "./join"
|
|
40
14
|
export * from "./junction"
|
|
41
15
|
export * from "./keys"
|
|
@@ -48,202 +22,10 @@ export * from "./overlays"
|
|
|
48
22
|
export * from "./reserved-keys"
|
|
49
23
|
export * from "./selector"
|
|
50
24
|
export * from "./set-state"
|
|
25
|
+
export type * from "./state-types"
|
|
51
26
|
export * from "./store"
|
|
52
27
|
export * from "./subject"
|
|
53
28
|
export * from "./subscribe"
|
|
54
29
|
export * from "./timeline"
|
|
55
30
|
export * from "./transaction"
|
|
56
31
|
export type * from "./utility-types"
|
|
57
|
-
|
|
58
|
-
export type AtomIOState = {
|
|
59
|
-
key: string
|
|
60
|
-
family?: FamilyMetadata
|
|
61
|
-
install: (store: RootStore) => void
|
|
62
|
-
subject: Subject<StateUpdate<any>>
|
|
63
|
-
}
|
|
64
|
-
export type RegularAtom<T, E> = Flat<
|
|
65
|
-
AtomIOState & {
|
|
66
|
-
type: `atom`
|
|
67
|
-
default: T | (() => T)
|
|
68
|
-
cleanup?: () => void
|
|
69
|
-
internalRoles?: internalRole[]
|
|
70
|
-
catch?: readonly Ctor<E>[]
|
|
71
|
-
}
|
|
72
|
-
>
|
|
73
|
-
export type MutableAtom<T extends Transceiver<any, any, any>> = Flat<
|
|
74
|
-
AtomIOState & {
|
|
75
|
-
type: `mutable_atom`
|
|
76
|
-
class: ConstructorOf<T>
|
|
77
|
-
cleanup?: () => void
|
|
78
|
-
}
|
|
79
|
-
>
|
|
80
|
-
export type Atom<T, E> =
|
|
81
|
-
| RegularAtom<T, E>
|
|
82
|
-
| (T extends Transceiver<any, any, any> ? MutableAtom<T> : never)
|
|
83
|
-
|
|
84
|
-
export type WritableHeldSelector<T> = Flat<
|
|
85
|
-
AtomIOState & {
|
|
86
|
-
type: `writable_held_selector`
|
|
87
|
-
const: T
|
|
88
|
-
getFrom: (target: Store) => T
|
|
89
|
-
setSelf: (newValue: T) => void
|
|
90
|
-
}
|
|
91
|
-
>
|
|
92
|
-
export type ReadonlyHeldSelector<T> = Flat<
|
|
93
|
-
AtomIOState & {
|
|
94
|
-
type: `readonly_held_selector`
|
|
95
|
-
const: T
|
|
96
|
-
getFrom: (target: Store) => T
|
|
97
|
-
}
|
|
98
|
-
>
|
|
99
|
-
export type WritablePureSelector<T, E> = Flat<
|
|
100
|
-
AtomIOState & {
|
|
101
|
-
type: `writable_pure_selector`
|
|
102
|
-
getFrom: (target: Store) => E | T
|
|
103
|
-
setSelf: (newValue: T) => void
|
|
104
|
-
catch?: readonly Ctor<E>[]
|
|
105
|
-
}
|
|
106
|
-
>
|
|
107
|
-
export type ReadonlyPureSelector<T, E> = Flat<
|
|
108
|
-
AtomIOState & {
|
|
109
|
-
type: `readonly_pure_selector`
|
|
110
|
-
getFrom: (target: Store) => E | T
|
|
111
|
-
catch?: readonly Ctor<E>[]
|
|
112
|
-
}
|
|
113
|
-
>
|
|
114
|
-
export type ReadonlySelector<T, E> =
|
|
115
|
-
| ReadonlyHeldSelector<T>
|
|
116
|
-
| ReadonlyPureSelector<T, E>
|
|
117
|
-
export type WritableSelector<T, E> =
|
|
118
|
-
| WritableHeldSelector<T>
|
|
119
|
-
| WritablePureSelector<T, E>
|
|
120
|
-
export type HeldSelector<T> = ReadonlyHeldSelector<T> | WritableHeldSelector<T>
|
|
121
|
-
export type PureSelector<T, E> =
|
|
122
|
-
| ReadonlyPureSelector<T, E>
|
|
123
|
-
| WritablePureSelector<T, E>
|
|
124
|
-
export type Selector<T, E> =
|
|
125
|
-
| ReadonlyHeldSelector<T>
|
|
126
|
-
| ReadonlyPureSelector<T, E>
|
|
127
|
-
| WritableHeldSelector<T>
|
|
128
|
-
| WritablePureSelector<T, E>
|
|
129
|
-
|
|
130
|
-
export type WritableState<T, E> = Atom<T, E> | WritableSelector<T, E>
|
|
131
|
-
export type ReadableState<T, E> = Atom<T, E> | Selector<T, E>
|
|
132
|
-
|
|
133
|
-
// biome-ignore format: intersection
|
|
134
|
-
export type RegularAtomFamily<T, K extends Canonical, E = never> =
|
|
135
|
-
& Flat<
|
|
136
|
-
& RegularAtomFamilyToken<T, K, E>
|
|
137
|
-
& {
|
|
138
|
-
create: <Key extends K>(key: Key) => RegularAtomToken<T, Key, E>
|
|
139
|
-
default: T | ((key: K) => T)
|
|
140
|
-
install: (store: RootStore) => void
|
|
141
|
-
internalRoles: string[] | undefined
|
|
142
|
-
subject: Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>
|
|
143
|
-
}
|
|
144
|
-
>
|
|
145
|
-
|
|
146
|
-
// biome-ignore format: intersection
|
|
147
|
-
export type MutableAtomFamily<
|
|
148
|
-
T extends Transceiver<any, any, any>,
|
|
149
|
-
K extends Canonical,
|
|
150
|
-
> =
|
|
151
|
-
& Flat<
|
|
152
|
-
& MutableAtomFamilyToken<T, K>
|
|
153
|
-
& {
|
|
154
|
-
create: <Key extends K>(key: Key) => MutableAtomToken<T, Key>
|
|
155
|
-
class: ConstructorOf<T>
|
|
156
|
-
install: (store: RootStore) => void
|
|
157
|
-
internalRoles: string[] | undefined
|
|
158
|
-
subject: Subject<StateLifecycleEvent<MutableAtomToken<T>>>
|
|
159
|
-
}
|
|
160
|
-
>
|
|
161
|
-
|
|
162
|
-
export type AtomFamily<T, K extends Canonical, E> =
|
|
163
|
-
| MutableAtomFamily<T extends Transceiver<any, any, any> ? T : never, K>
|
|
164
|
-
| RegularAtomFamily<T, K, E>
|
|
165
|
-
|
|
166
|
-
// biome-ignore format: intersection
|
|
167
|
-
export type WritablePureSelectorFamily<T, K extends Canonical, E> =
|
|
168
|
-
& Flat<
|
|
169
|
-
& WritablePureSelectorFamilyToken<T, K, E>
|
|
170
|
-
& {
|
|
171
|
-
create: <Key extends K>(key: Key) => WritablePureSelectorToken<T, Key, E>
|
|
172
|
-
default: (key: K) => T,
|
|
173
|
-
install: (store: RootStore) => void
|
|
174
|
-
internalRoles: string[] | undefined
|
|
175
|
-
subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>>
|
|
176
|
-
}
|
|
177
|
-
>
|
|
178
|
-
|
|
179
|
-
// biome-ignore format: intersection
|
|
180
|
-
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
181
|
-
& Flat<
|
|
182
|
-
& WritableHeldSelectorFamilyToken<T, K>
|
|
183
|
-
& {
|
|
184
|
-
create: <Key extends K>(key: Key) => WritableHeldSelectorToken<T, Key>
|
|
185
|
-
default: (key: K) => T,
|
|
186
|
-
install: (store: RootStore) => void
|
|
187
|
-
internalRoles: string[] | undefined
|
|
188
|
-
subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T, K>>>
|
|
189
|
-
}
|
|
190
|
-
>
|
|
191
|
-
|
|
192
|
-
// biome-ignore format: intersection
|
|
193
|
-
export type ReadonlyPureSelectorFamily<T, K extends Canonical, E> =
|
|
194
|
-
& Flat<
|
|
195
|
-
& ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
196
|
-
& {
|
|
197
|
-
create: <Key extends K>(key: Key) => ReadonlyPureSelectorToken<T, Key, E>
|
|
198
|
-
default: (key: K) => T,
|
|
199
|
-
install: (store: RootStore) => void
|
|
200
|
-
internalRoles: string[] | undefined
|
|
201
|
-
subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>>
|
|
202
|
-
}
|
|
203
|
-
>
|
|
204
|
-
|
|
205
|
-
// biome-ignore format: intersection
|
|
206
|
-
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
207
|
-
& Flat<
|
|
208
|
-
& ReadonlyHeldSelectorFamilyToken<T, K>
|
|
209
|
-
& {
|
|
210
|
-
create: <Key extends K>(key: Key) => ReadonlyHeldSelectorToken<T, Key>
|
|
211
|
-
default: (key: K) => T,
|
|
212
|
-
install: (store: RootStore) => void
|
|
213
|
-
internalRoles: string[] | undefined
|
|
214
|
-
subject: Subject<StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>>
|
|
215
|
-
}
|
|
216
|
-
>
|
|
217
|
-
|
|
218
|
-
export type PureSelectorFamily<T, K extends Canonical, E> =
|
|
219
|
-
| ReadonlyPureSelectorFamily<T, K, E>
|
|
220
|
-
| WritablePureSelectorFamily<T, K, E>
|
|
221
|
-
|
|
222
|
-
export type HeldSelectorFamily<T, K extends Canonical> =
|
|
223
|
-
| ReadonlyHeldSelectorFamily<T, K>
|
|
224
|
-
| WritableHeldSelectorFamily<T, K>
|
|
225
|
-
|
|
226
|
-
export type ReadonlySelectorFamily<T, K extends Canonical, E> =
|
|
227
|
-
| ReadonlyHeldSelectorFamily<T, K>
|
|
228
|
-
| ReadonlyPureSelectorFamily<T, K, E>
|
|
229
|
-
|
|
230
|
-
export type WritableSelectorFamily<T, K extends Canonical, E> =
|
|
231
|
-
| WritableHeldSelectorFamily<T, K>
|
|
232
|
-
| WritablePureSelectorFamily<T, K, E>
|
|
233
|
-
|
|
234
|
-
export type SelectorFamily<T, K extends Canonical, E> =
|
|
235
|
-
| HeldSelectorFamily<T, K>
|
|
236
|
-
| PureSelectorFamily<T, K, E>
|
|
237
|
-
|
|
238
|
-
export type WritableFamily<T, K extends Canonical, E> =
|
|
239
|
-
| AtomFamily<T, K, E>
|
|
240
|
-
| WritableSelectorFamily<T, K, E>
|
|
241
|
-
export type ReadableFamily<T, K extends Canonical, E> =
|
|
242
|
-
| AtomFamily<T, K, E>
|
|
243
|
-
| SelectorFamily<T, K, E>
|
|
244
|
-
|
|
245
|
-
export type AtomIOInternalResource =
|
|
246
|
-
| ReadableFamily<any, any, any>
|
|
247
|
-
| ReadableState<any, any>
|
|
248
|
-
| Timeline<any>
|
|
249
|
-
| Transaction<any>
|
package/src/internal/molecule.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { getFromStore } from "./get-state"
|
|
|
19
19
|
import { getTrace } from "./get-trace"
|
|
20
20
|
import { newest } from "./lineage"
|
|
21
21
|
import type { Store } from "./store"
|
|
22
|
-
import { IMPLICIT } from "./store"
|
|
23
22
|
import type { RootStore } from "./transaction"
|
|
24
23
|
import { createTransaction, isChildStore } from "./transaction"
|
|
25
24
|
|
|
@@ -30,8 +29,8 @@ export type Molecule<K extends Canonical> = {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export function makeRootMoleculeInStore<S extends string>(
|
|
32
|
+
store: Store,
|
|
33
33
|
key: S,
|
|
34
|
-
store: Store = IMPLICIT.STORE,
|
|
35
34
|
): S {
|
|
36
35
|
const molecule = {
|
|
37
36
|
key,
|
|
@@ -10,11 +10,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
10
10
|
import type { Canonical } from "atom.io/json"
|
|
11
11
|
import { stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
|
-
import
|
|
14
|
-
import { createWritablePureSelectorFamily } from ".."
|
|
13
|
+
import { createWritablePureSelectorFamily } from "../families"
|
|
15
14
|
import { newest } from "../lineage"
|
|
16
15
|
import { createMutableAtom } from "../mutable"
|
|
16
|
+
import type { MutableAtomFamily } from "../state-types"
|
|
17
17
|
import { Subject } from "../subject"
|
|
18
|
+
import type { RootStore } from "../transaction"
|
|
18
19
|
import { FamilyTracker } from "./tracker-family"
|
|
19
20
|
import type { AsJSON, Transceiver } from "./transceiver"
|
|
20
21
|
|
|
@@ -5,12 +5,14 @@ import type {
|
|
|
5
5
|
UpdateHandler,
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
|
|
8
|
-
import type { MutableAtom, RootStore } from ".."
|
|
9
|
-
import { createStandaloneSelector, resetInStore, setIntoStore } from ".."
|
|
10
8
|
import { newest } from "../lineage"
|
|
9
|
+
import { createStandaloneSelector } from "../selector"
|
|
10
|
+
import { resetInStore, setIntoStore } from "../set-state"
|
|
11
|
+
import type { MutableAtom } from "../state-types"
|
|
11
12
|
import { deposit, type Store } from "../store"
|
|
12
13
|
import { Subject } from "../subject"
|
|
13
14
|
import { subscribeToState } from "../subscribe"
|
|
15
|
+
import type { RootStore } from "../transaction"
|
|
14
16
|
import { Tracker } from "./tracker"
|
|
15
17
|
import type { Transceiver } from "./transceiver"
|
|
16
18
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
2
|
import type { Canonical, Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { WritablePureSelectorFamily } from ".."
|
|
5
4
|
import { newest } from "../lineage"
|
|
5
|
+
import type { WritablePureSelectorFamily } from "../state-types"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import type { Transceiver } from "./transceiver"
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { RegularAtomFamily } from ".."
|
|
5
4
|
import { newest } from "../lineage"
|
|
5
|
+
import type { RegularAtomFamily } from "../state-types"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
8
8
|
|
|
@@ -2,9 +2,10 @@ import type { MutableAtomToken, StateLifecycleEvent } from "atom.io"
|
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
import { parseJson } from "atom.io/json"
|
|
4
4
|
|
|
5
|
-
import type { MutableAtomFamily, RegularAtomFamily, RootStore } from ".."
|
|
6
5
|
import { createRegularAtomFamily } from "../families"
|
|
6
|
+
import type { MutableAtomFamily, RegularAtomFamily } from "../state-types"
|
|
7
7
|
import { withdraw } from "../store"
|
|
8
|
+
import type { RootStore } from "../transaction"
|
|
8
9
|
import { Tracker } from "./tracker"
|
|
9
10
|
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
10
11
|
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
FamilyMetadata,
|
|
3
|
+
MutableAtomToken,
|
|
4
|
+
RegularAtomToken,
|
|
5
|
+
StateUpdate,
|
|
6
|
+
} from "atom.io"
|
|
2
7
|
|
|
3
|
-
import type { Store } from ".."
|
|
4
|
-
import {
|
|
5
|
-
getFromStore,
|
|
6
|
-
newest,
|
|
7
|
-
setIntoStore,
|
|
8
|
-
subscribeToState,
|
|
9
|
-
subscribeToTimeline,
|
|
10
|
-
} from ".."
|
|
11
8
|
import { createRegularAtom } from "../atom"
|
|
9
|
+
import { getFromStore } from "../get-state"
|
|
10
|
+
import { newest } from "../lineage"
|
|
11
|
+
import { setIntoStore } from "../set-state"
|
|
12
|
+
import { JOIN_OP, operateOnStore } from "../set-state/operate-on-store"
|
|
13
|
+
import type { Store } from "../store"
|
|
14
|
+
import { subscribeToState, subscribeToTimeline } from "../subscribe"
|
|
12
15
|
import { isChildStore } from "../transaction/is-root-store"
|
|
13
16
|
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
14
17
|
|
|
@@ -64,9 +67,9 @@ export class Tracker<T extends Transceiver<any, any, any>> {
|
|
|
64
67
|
const storeStatus = isChildStore(target)
|
|
65
68
|
? target.transactionMeta.update.token.key
|
|
66
69
|
: `main`
|
|
67
|
-
const subscriptionKey = `tracker:${storeName}:${storeStatus}:${stateKey}`
|
|
70
|
+
const subscriptionKey = `tracker-from-core:${storeName}:${storeStatus}:${stateKey}`
|
|
68
71
|
const trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {
|
|
69
|
-
|
|
72
|
+
operateOnStore(JOIN_OP, target, latestSignalState, update)
|
|
70
73
|
}
|
|
71
74
|
const originalInnerValue = getFromStore(target, mutableState)
|
|
72
75
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
@@ -94,60 +97,69 @@ export class Tracker<T extends Transceiver<any, any, any>> {
|
|
|
94
97
|
latestSignalState: RegularAtomToken<SignalFrom<T> | null>,
|
|
95
98
|
target: Store,
|
|
96
99
|
): void {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
const stateKey = mutableState.key
|
|
101
|
+
const storeName = target.config.name
|
|
102
|
+
const storeStatus = isChildStore(target)
|
|
103
|
+
? target.transactionMeta.update.token.key
|
|
104
|
+
: `main`
|
|
105
|
+
const subscriptionKey = `tracker-to-core:${storeName}:${storeStatus}:${stateKey}`
|
|
100
106
|
subscribeToState(
|
|
101
107
|
target,
|
|
102
108
|
latestSignalState,
|
|
103
109
|
subscriptionKey,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
target,
|
|
112
|
-
{ key: timelineId, type: `timeline` },
|
|
113
|
-
subscriptionKey,
|
|
114
|
-
function trackerWaitsForTimeTravelToFinish(update) {
|
|
115
|
-
unsubscribe()
|
|
116
|
-
setIntoStore(target, mutableState, (transceiver) => {
|
|
117
|
-
if (update === `redo` && newValue) {
|
|
118
|
-
transceiver.do(newValue)
|
|
119
|
-
} else if (update === `undo` && oldValue) {
|
|
120
|
-
transceiver.undo(oldValue)
|
|
121
|
-
}
|
|
122
|
-
return transceiver
|
|
123
|
-
})
|
|
124
|
-
},
|
|
110
|
+
Object.assign(
|
|
111
|
+
function trackerCapturesInboundSignal({
|
|
112
|
+
newValue,
|
|
113
|
+
oldValue,
|
|
114
|
+
}: StateUpdate<SignalFrom<T> | null>) {
|
|
115
|
+
const timelineId = target.timelineTopics.getRelatedKey(
|
|
116
|
+
latestSignalState.key,
|
|
125
117
|
)
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
119
|
+
if (timelineId && target.timelines.get(timelineId)?.timeTraveling) {
|
|
120
|
+
const unsubscribe = subscribeToTimeline(
|
|
121
|
+
target,
|
|
122
|
+
{ key: timelineId, type: `timeline` },
|
|
123
|
+
subscriptionKey,
|
|
124
|
+
function trackerWaitsForTimeTravelToFinish(update) {
|
|
125
|
+
unsubscribe()
|
|
126
|
+
setIntoStore(target, mutableState, (transceiver) => {
|
|
127
|
+
if (update === `redo` && newValue) {
|
|
128
|
+
transceiver.do(newValue)
|
|
129
|
+
} else if (update === `undo` && oldValue) {
|
|
130
|
+
transceiver.undo(oldValue)
|
|
131
|
+
}
|
|
132
|
+
return transceiver
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const mutable = getFromStore(target, mutableState)
|
|
140
|
+
const updateNumber = mutable.getUpdateNumber(newValue)
|
|
141
|
+
const eventOffset = updateNumber - mutable.cacheUpdateNumber
|
|
142
|
+
if (newValue && eventOffset === 1) {
|
|
143
|
+
setIntoStore(
|
|
144
|
+
target,
|
|
145
|
+
mutableState,
|
|
146
|
+
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
147
|
+
)
|
|
148
|
+
} else {
|
|
149
|
+
const expected = mutable.cacheUpdateNumber + 1
|
|
150
|
+
target.logger.info(
|
|
151
|
+
`❌`,
|
|
152
|
+
`mutable_atom`,
|
|
153
|
+
mutableState.key,
|
|
154
|
+
`could not be updated. Expected update number`,
|
|
155
|
+
expected,
|
|
156
|
+
`but got`,
|
|
157
|
+
updateNumber,
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{ inboundTracker: true },
|
|
162
|
+
),
|
|
151
163
|
)
|
|
152
164
|
}
|
|
153
165
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PureSelector, RegularAtom } from "."
|
|
2
1
|
import { writeToCache } from "./caching"
|
|
3
2
|
import { isFn } from "./is-fn"
|
|
3
|
+
import type { PureSelector, RegularAtom } from "./state-types"
|
|
4
4
|
import type { Store } from "./store"
|
|
5
5
|
|
|
6
6
|
export function safeCompute<T, E>(
|
|
@@ -4,11 +4,12 @@ import type {
|
|
|
4
4
|
ReadonlyHeldSelectorToken,
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
|
-
import type { ReadonlyHeldSelector, RootStore } from ".."
|
|
8
7
|
import { writeToCache } from "../caching"
|
|
9
8
|
import { newest } from "../lineage"
|
|
9
|
+
import type { ReadonlyHeldSelector } from "../state-types"
|
|
10
10
|
import type { Store } from "../store"
|
|
11
11
|
import { Subject } from "../subject"
|
|
12
|
+
import type { RootStore } from "../transaction"
|
|
12
13
|
import { registerSelector } from "./register-selector"
|
|
13
14
|
|
|
14
15
|
export function createReadonlyHeldSelector<T extends object>(
|
|
@@ -6,11 +6,12 @@ import type {
|
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
import type { Canonical } from "atom.io/json"
|
|
8
8
|
|
|
9
|
-
import type { ReadonlyPureSelector, RootStore } from ".."
|
|
10
9
|
import { writeToCache } from "../caching"
|
|
11
10
|
import { newest } from "../lineage"
|
|
11
|
+
import type { ReadonlyPureSelector } from "../state-types"
|
|
12
12
|
import type { Store } from "../store"
|
|
13
13
|
import { Subject } from "../subject"
|
|
14
|
+
import type { RootStore } from "../transaction"
|
|
14
15
|
import { registerSelector } from "./register-selector"
|
|
15
16
|
|
|
16
17
|
export function createReadonlyPureSelector<T, K extends Canonical, E>(
|
|
@@ -4,11 +4,12 @@ import type {
|
|
|
4
4
|
WritableHeldSelectorToken,
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
|
|
7
|
-
import type { RootStore, WritableHeldSelector } from ".."
|
|
8
7
|
import { writeToCache } from "../caching"
|
|
9
8
|
import { newest } from "../lineage"
|
|
9
|
+
import type { WritableHeldSelector } from "../state-types"
|
|
10
10
|
import type { Store } from "../store"
|
|
11
11
|
import { Subject } from "../subject"
|
|
12
|
+
import type { RootStore } from "../transaction"
|
|
12
13
|
import { registerSelector } from "./register-selector"
|
|
13
14
|
|
|
14
15
|
export function createWritableHeldSelector<T extends object>(
|
|
@@ -6,11 +6,12 @@ import type {
|
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
import type { Canonical } from "atom.io/json"
|
|
8
8
|
|
|
9
|
-
import type { RootStore, WritablePureSelector } from ".."
|
|
10
9
|
import { writeToCache } from "../caching"
|
|
11
10
|
import { newest } from "../lineage"
|
|
11
|
+
import type { WritablePureSelector } from "../state-types"
|
|
12
12
|
import type { Store } from "../store"
|
|
13
13
|
import { Subject } from "../subject"
|
|
14
|
+
import type { RootStore } from "../transaction"
|
|
14
15
|
import { registerSelector } from "./register-selector"
|
|
15
16
|
|
|
16
17
|
export function createWritablePureSelector<T, K extends Canonical, E>(
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { SelectorFamilyToken, SelectorToken } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { newest } from "../lineage"
|
|
4
|
+
import { type Store, withdraw } from "../store"
|
|
5
|
+
import { isChildStore } from "../transaction"
|
|
5
6
|
|
|
6
7
|
export function disposeSelector(
|
|
7
8
|
store: Store,
|