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
|
@@ -67,17 +67,20 @@ export function registerSelector(
|
|
|
67
67
|
updateSelectorAtoms(store, selectorType, selectorKey, token, covered)
|
|
68
68
|
return dependencyValue
|
|
69
69
|
},
|
|
70
|
-
set: (<T, K extends Canonical
|
|
70
|
+
set: (<T, K extends Canonical>(
|
|
71
71
|
...params:
|
|
72
72
|
| [
|
|
73
73
|
token: WritableFamilyToken<T, K>,
|
|
74
|
-
key:
|
|
75
|
-
value:
|
|
74
|
+
key: NoInfer<K>,
|
|
75
|
+
value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
|
|
76
|
+
]
|
|
77
|
+
| [
|
|
78
|
+
token: WritableToken<T>,
|
|
79
|
+
value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
|
|
76
80
|
]
|
|
77
|
-
| [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
|
|
78
81
|
) => {
|
|
79
82
|
const target = newest(store)
|
|
80
|
-
operateOnStore(
|
|
83
|
+
operateOnStore(JOIN_OP, target, ...params)
|
|
81
84
|
}) as typeof setState,
|
|
82
85
|
find: ((...args: Parameters<typeof findState>) =>
|
|
83
86
|
findInStore(store, ...args)) as typeof findState,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Atom, Store } from ".."
|
|
2
1
|
import { isAtomKey } from "../keys"
|
|
2
|
+
import type { Atom } from "../state-types"
|
|
3
|
+
import type { Store } from "../store"
|
|
3
4
|
import { getSelectorDependencyKeys } from "./get-selector-dependency-keys"
|
|
4
5
|
|
|
5
6
|
export function traceRootSelectorAtoms(
|
|
@@ -5,14 +5,15 @@ import type {
|
|
|
5
5
|
TimelineEvent,
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
|
|
8
|
-
import type { MutableAtom, Subject, WritableFamily, WritableState } from ".."
|
|
9
|
-
import { newest } from ".."
|
|
10
8
|
import { hasRole } from "../atom"
|
|
11
9
|
import { readOrComputeValue } from "../get-state"
|
|
10
|
+
import { newest } from "../lineage"
|
|
12
11
|
import type { Transceiver } from "../mutable"
|
|
13
12
|
import { isTransceiver } from "../mutable"
|
|
14
13
|
import type { OpenOperation } from "../operation"
|
|
14
|
+
import type { MutableAtom, WritableFamily, WritableState } from "../state-types"
|
|
15
15
|
import { deposit, type Store } from "../store"
|
|
16
|
+
import type { Subject } from "../subject"
|
|
16
17
|
import { isChildStore, isRootStore } from "../transaction"
|
|
17
18
|
import { evictDownstreamFromAtom } from "./evict-downstream"
|
|
18
19
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Atom } from ".."
|
|
2
1
|
import { evictCachedValue } from "../caching"
|
|
3
2
|
import { newest } from "../lineage"
|
|
4
3
|
import { isDone, markDone } from "../operation"
|
|
4
|
+
import type { Atom } from "../state-types"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
7
|
export function evictDownstreamFromAtom(
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
1
|
+
import type { Setter, WritableFamilyToken, WritableToken } from "atom.io"
|
|
2
2
|
import { type Canonical, parseJson } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { WritableFamily } from ".."
|
|
5
4
|
import { seekInStore } from "../families"
|
|
6
5
|
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
7
6
|
import { mintInStore, MUST_CREATE } from "../families/mint-in-store"
|
|
8
7
|
import type { OpenOperation } from "../operation"
|
|
9
8
|
import { closeOperation, openOperation } from "../operation"
|
|
9
|
+
import type { WritableFamily } from "../state-types"
|
|
10
10
|
import { type Store, withdraw } from "../store"
|
|
11
11
|
import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
|
|
12
12
|
import { resetAtomOrSelector } from "./reset-atom-or-selector"
|
|
@@ -18,32 +18,26 @@ export type ProtoUpdate<T> = { oldValue: T; newValue: T }
|
|
|
18
18
|
export const OWN_OP: unique symbol = Symbol(`OWN_OP`)
|
|
19
19
|
export const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)
|
|
20
20
|
|
|
21
|
-
export function operateOnStore<
|
|
22
|
-
T,
|
|
23
|
-
K extends Canonical,
|
|
24
|
-
New extends T,
|
|
25
|
-
Key extends K,
|
|
26
|
-
E,
|
|
27
|
-
>(
|
|
28
|
-
store: Store,
|
|
21
|
+
export function operateOnStore<T, TT extends T, K extends Canonical, E>(
|
|
29
22
|
opMode: typeof JOIN_OP | typeof OWN_OP,
|
|
23
|
+
store: Store,
|
|
30
24
|
...params:
|
|
31
25
|
| [
|
|
32
26
|
token: WritableFamilyToken<T, K, E>,
|
|
33
|
-
key:
|
|
34
|
-
value:
|
|
27
|
+
key: NoInfer<K>,
|
|
28
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
35
29
|
]
|
|
36
30
|
| [
|
|
37
|
-
token: WritableToken<T,
|
|
38
|
-
value:
|
|
31
|
+
token: WritableToken<T, any, E>,
|
|
32
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
39
33
|
]
|
|
40
34
|
): void {
|
|
41
|
-
let existingToken: WritableToken<T,
|
|
42
|
-
let brandNewToken: WritableToken<T,
|
|
43
|
-
let token: WritableToken<T,
|
|
35
|
+
let existingToken: WritableToken<T, K, E> | undefined
|
|
36
|
+
let brandNewToken: WritableToken<T, K, E> | undefined
|
|
37
|
+
let token: WritableToken<T, K, E>
|
|
44
38
|
let family: WritableFamily<T, K, E> | undefined
|
|
45
|
-
let key:
|
|
46
|
-
let value:
|
|
39
|
+
let key: K | null
|
|
40
|
+
let value: Setter<TT> | TT | typeof RESET_STATE
|
|
47
41
|
if (params.length === 2) {
|
|
48
42
|
token = params[0]
|
|
49
43
|
value = params[1]
|
|
@@ -52,7 +46,7 @@ export function operateOnStore<
|
|
|
52
46
|
key = parseJson(token.family.subKey)
|
|
53
47
|
existingToken = seekInStore(store, family, key)
|
|
54
48
|
if (!existingToken) {
|
|
55
|
-
token = brandNewToken = mintInStore(store, family, key
|
|
49
|
+
token = brandNewToken = mintInStore(MUST_CREATE, store, family, key)
|
|
56
50
|
} else {
|
|
57
51
|
token = existingToken
|
|
58
52
|
}
|
|
@@ -63,7 +57,7 @@ export function operateOnStore<
|
|
|
63
57
|
value = params[2]
|
|
64
58
|
existingToken = seekInStore(store, family, key)
|
|
65
59
|
if (!existingToken) {
|
|
66
|
-
token = brandNewToken = mintInStore(store, family, key
|
|
60
|
+
token = brandNewToken = mintInStore(MUST_CREATE, store, family, key)
|
|
67
61
|
} else {
|
|
68
62
|
token = existingToken
|
|
69
63
|
}
|
|
@@ -90,7 +84,7 @@ export function operateOnStore<
|
|
|
90
84
|
action,
|
|
91
85
|
`from T-${rejectionTime}`,
|
|
92
86
|
)
|
|
93
|
-
operateOnStore(
|
|
87
|
+
operateOnStore(opMode, store, token, value)
|
|
94
88
|
},
|
|
95
89
|
)
|
|
96
90
|
return
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { Atom, OpenOperation, Store, WritableState } from ".."
|
|
2
|
-
import { traceRootSelectorAtoms } from ".."
|
|
3
1
|
import { isFn } from "../is-fn"
|
|
2
|
+
import type { OpenOperation } from "../operation"
|
|
4
3
|
import { safeCompute } from "../safe-compute"
|
|
4
|
+
import { traceRootSelectorAtoms } from "../selector"
|
|
5
|
+
import type { Atom, WritableState } from "../state-types"
|
|
6
|
+
import type { Store } from "../store"
|
|
5
7
|
import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
|
|
6
8
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
7
9
|
import { setAtom } from "./set-atom"
|
|
@@ -17,7 +19,7 @@ function resetAtom<T, E>(
|
|
|
17
19
|
let def: E | T
|
|
18
20
|
if (isFn(atom.default)) def = safeCompute(target, atom)
|
|
19
21
|
else def = atom.default
|
|
20
|
-
return setAtom(target, atom, def)
|
|
22
|
+
return setAtom<E | T>(target, atom, def)
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -14,20 +14,20 @@ export function resetInStore(
|
|
|
14
14
|
export function resetInStore<K extends Canonical>(
|
|
15
15
|
store: Store,
|
|
16
16
|
token: WritableFamilyToken<any, K, any>,
|
|
17
|
-
key: K
|
|
17
|
+
key: NoInfer<K>,
|
|
18
18
|
): void
|
|
19
19
|
|
|
20
|
-
export function resetInStore<T, K extends Canonical
|
|
20
|
+
export function resetInStore<T, K extends Canonical>(
|
|
21
21
|
store: Store,
|
|
22
22
|
...params:
|
|
23
|
-
| [token: WritableFamilyToken<T, K, any>, key:
|
|
23
|
+
| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]
|
|
24
24
|
| [token: WritableToken<T, any, any>]
|
|
25
25
|
): void
|
|
26
26
|
|
|
27
|
-
export function resetInStore<T, K extends Canonical
|
|
27
|
+
export function resetInStore<T, K extends Canonical>(
|
|
28
28
|
store: Store,
|
|
29
29
|
...params:
|
|
30
|
-
| [token: WritableFamilyToken<T, K, any>, key:
|
|
30
|
+
| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]
|
|
31
31
|
| [token: WritableToken<T, any, any>]
|
|
32
32
|
): void {
|
|
33
33
|
const subParams = [...params, RESET_STATE] as const
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { WritableState } from ".."
|
|
2
1
|
import type { OpenOperation } from "../operation"
|
|
2
|
+
import type { WritableState } from "../state-types"
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
5
5
|
import { setAtom } from "./set-atom"
|
|
@@ -8,7 +8,7 @@ import { setSelector } from "./set-selector"
|
|
|
8
8
|
export const setAtomOrSelector = <T>(
|
|
9
9
|
target: Store & { operation: OpenOperation },
|
|
10
10
|
state: WritableState<T, any>,
|
|
11
|
-
value: T | ((oldValue: T) => T),
|
|
11
|
+
value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
|
|
12
12
|
): ProtoUpdate<T> => {
|
|
13
13
|
let protoUpdate: ProtoUpdate<T>
|
|
14
14
|
switch (state.type) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { Atom, OpenOperation, Store } from ".."
|
|
2
1
|
import { writeToCache } from "../caching"
|
|
3
2
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
3
|
+
import type { OpenOperation } from "../operation"
|
|
4
4
|
import { markDone } from "../operation"
|
|
5
|
+
import type { Atom } from "../state-types"
|
|
6
|
+
import type { Store } from "../store"
|
|
5
7
|
import { become } from "./become"
|
|
6
8
|
import { evictDownstreamFromAtom } from "./evict-downstream"
|
|
7
9
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
@@ -9,7 +11,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
9
11
|
export const setAtom = <T>(
|
|
10
12
|
target: Store & { operation: OpenOperation<any> },
|
|
11
13
|
atom: Atom<T, any>,
|
|
12
|
-
next: T | ((oldValue: T) => T),
|
|
14
|
+
next: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
|
|
13
15
|
): ProtoUpdate<T> => {
|
|
14
16
|
const oldValue = readOrComputeValue(target, atom, `mut`)
|
|
15
17
|
let newValue = become(next, oldValue)
|
|
@@ -1,67 +1,49 @@
|
|
|
1
|
-
import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
1
|
+
import type { Setter, WritableFamilyToken, WritableToken } from "atom.io"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { Store } from "../store"
|
|
5
5
|
import { operateOnStore, OWN_OP } from "./operate-on-store"
|
|
6
6
|
import type { RESET_STATE } from "./reset-in-store"
|
|
7
7
|
|
|
8
|
-
export function setIntoStore<T,
|
|
8
|
+
export function setIntoStore<T, TT extends T>(
|
|
9
9
|
store: Store,
|
|
10
|
-
token: WritableToken<T, any,
|
|
11
|
-
value:
|
|
10
|
+
token: WritableToken<T, any, any>,
|
|
11
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
12
12
|
): void
|
|
13
13
|
|
|
14
|
-
export function setIntoStore<
|
|
15
|
-
T,
|
|
16
|
-
K extends Canonical,
|
|
17
|
-
New extends T,
|
|
18
|
-
Key extends K,
|
|
19
|
-
E,
|
|
20
|
-
>(
|
|
14
|
+
export function setIntoStore<T, TT extends T, K extends Canonical>(
|
|
21
15
|
store: Store,
|
|
22
|
-
token: WritableFamilyToken<T, K,
|
|
23
|
-
key:
|
|
24
|
-
value:
|
|
16
|
+
token: WritableFamilyToken<T, K, any>,
|
|
17
|
+
key: NoInfer<K>,
|
|
18
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
25
19
|
): void
|
|
26
20
|
|
|
27
|
-
export function setIntoStore<
|
|
28
|
-
T,
|
|
29
|
-
K extends Canonical,
|
|
30
|
-
New extends T,
|
|
31
|
-
Key extends K,
|
|
32
|
-
E,
|
|
33
|
-
>(
|
|
21
|
+
export function setIntoStore<T, TT extends T, K extends Canonical>(
|
|
34
22
|
store: Store,
|
|
35
23
|
...params:
|
|
36
24
|
| [
|
|
37
|
-
token: WritableFamilyToken<T, K,
|
|
38
|
-
key:
|
|
39
|
-
value:
|
|
25
|
+
token: WritableFamilyToken<T, K, any>,
|
|
26
|
+
key: NoInfer<K>,
|
|
27
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
40
28
|
]
|
|
41
29
|
| [
|
|
42
|
-
token: WritableToken<T, any,
|
|
43
|
-
value:
|
|
30
|
+
token: WritableToken<T, any, any>,
|
|
31
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
44
32
|
]
|
|
45
33
|
): void
|
|
46
34
|
|
|
47
|
-
export function setIntoStore<
|
|
48
|
-
T,
|
|
49
|
-
K extends Canonical,
|
|
50
|
-
New extends T,
|
|
51
|
-
Key extends K,
|
|
52
|
-
E,
|
|
53
|
-
>(
|
|
35
|
+
export function setIntoStore<T, TT extends T, K extends Canonical>(
|
|
54
36
|
store: Store,
|
|
55
37
|
...params:
|
|
56
38
|
| [
|
|
57
|
-
token: WritableFamilyToken<T, K,
|
|
58
|
-
key:
|
|
59
|
-
value:
|
|
39
|
+
token: WritableFamilyToken<T, K, any>,
|
|
40
|
+
key: NoInfer<K>,
|
|
41
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
60
42
|
]
|
|
61
43
|
| [
|
|
62
|
-
token: WritableToken<T, any,
|
|
63
|
-
value:
|
|
44
|
+
token: WritableToken<T, any, any>,
|
|
45
|
+
value: Setter<TT> | TT | typeof RESET_STATE,
|
|
64
46
|
]
|
|
65
47
|
): void {
|
|
66
|
-
operateOnStore(
|
|
48
|
+
operateOnStore(OWN_OP, store, ...params)
|
|
67
49
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { readOrComputeValue, type WritableSelector } from ".."
|
|
2
1
|
import { writeToCache } from "../caching"
|
|
2
|
+
import { readOrComputeValue } from "../get-state"
|
|
3
3
|
import { markDone, type OpenOperation } from "../operation"
|
|
4
|
+
import type { WritableSelector } from "../state-types"
|
|
4
5
|
import type { Store } from "../store"
|
|
5
6
|
import { become } from "./become"
|
|
6
7
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
@@ -8,7 +9,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
8
9
|
export function setSelector<T>(
|
|
9
10
|
target: Store & { operation: OpenOperation<any> },
|
|
10
11
|
selector: WritableSelector<T, any>,
|
|
11
|
-
next: T | ((oldValue: T) => T),
|
|
12
|
+
next: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
|
|
12
13
|
): ProtoUpdate<T> {
|
|
13
14
|
let oldValue: T
|
|
14
15
|
let newValue: T
|
|
@@ -0,0 +1,228 @@
|
|
|
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"
|
|
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
|
+
export type AtomIOState = {
|
|
29
|
+
key: string
|
|
30
|
+
family?: FamilyMetadata
|
|
31
|
+
install: (store: RootStore) => void
|
|
32
|
+
subject: Subject<StateUpdate<any>>
|
|
33
|
+
}
|
|
34
|
+
export type RegularAtom<T, E> = Flat<
|
|
35
|
+
AtomIOState & {
|
|
36
|
+
type: `atom`
|
|
37
|
+
default: T | (() => T)
|
|
38
|
+
cleanup?: () => void
|
|
39
|
+
internalRoles?: InternalRole[]
|
|
40
|
+
catch?: readonly Ctor<E>[]
|
|
41
|
+
__T?: T
|
|
42
|
+
__E?: E
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
export type MutableAtom<T extends Transceiver<any, any, any>> = Flat<
|
|
46
|
+
AtomIOState & {
|
|
47
|
+
type: `mutable_atom`
|
|
48
|
+
class: ConstructorOf<T>
|
|
49
|
+
cleanup?: () => void
|
|
50
|
+
__T?: T
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
export type Atom<T, E> =
|
|
54
|
+
| RegularAtom<T, E>
|
|
55
|
+
| (T extends Transceiver<any, any, any> ? MutableAtom<T> : never)
|
|
56
|
+
|
|
57
|
+
export type WritableHeldSelector<T> = Flat<
|
|
58
|
+
AtomIOState & {
|
|
59
|
+
type: `writable_held_selector`
|
|
60
|
+
const: T
|
|
61
|
+
getFrom: (target: Store) => T
|
|
62
|
+
setSelf: (newValue: T) => void
|
|
63
|
+
__T?: T
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
export type ReadonlyHeldSelector<T> = Flat<
|
|
67
|
+
AtomIOState & {
|
|
68
|
+
type: `readonly_held_selector`
|
|
69
|
+
const: T
|
|
70
|
+
getFrom: (target: Store) => T
|
|
71
|
+
__T?: T
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
export type WritablePureSelector<T, E> = Flat<
|
|
75
|
+
AtomIOState & {
|
|
76
|
+
type: `writable_pure_selector`
|
|
77
|
+
getFrom: (target: Store) => E | T
|
|
78
|
+
setSelf: (newValue: T) => void
|
|
79
|
+
catch?: readonly Ctor<E>[]
|
|
80
|
+
__T?: T
|
|
81
|
+
__E?: E
|
|
82
|
+
}
|
|
83
|
+
>
|
|
84
|
+
export type ReadonlyPureSelector<T, E> = Flat<
|
|
85
|
+
AtomIOState & {
|
|
86
|
+
type: `readonly_pure_selector`
|
|
87
|
+
getFrom: (target: Store) => E | T
|
|
88
|
+
catch?: readonly Ctor<E>[]
|
|
89
|
+
__T?: T
|
|
90
|
+
__E?: E
|
|
91
|
+
}
|
|
92
|
+
>
|
|
93
|
+
export type ReadonlySelector<T, E> =
|
|
94
|
+
| ReadonlyHeldSelector<T>
|
|
95
|
+
| ReadonlyPureSelector<T, E>
|
|
96
|
+
export type WritableSelector<T, E> =
|
|
97
|
+
| WritableHeldSelector<T>
|
|
98
|
+
| WritablePureSelector<T, E>
|
|
99
|
+
export type HeldSelector<T> = ReadonlyHeldSelector<T> | WritableHeldSelector<T>
|
|
100
|
+
export type PureSelector<T, E> =
|
|
101
|
+
| ReadonlyPureSelector<T, E>
|
|
102
|
+
| WritablePureSelector<T, E>
|
|
103
|
+
export type Selector<T, E> =
|
|
104
|
+
| ReadonlyHeldSelector<T>
|
|
105
|
+
| ReadonlyPureSelector<T, E>
|
|
106
|
+
| WritableHeldSelector<T>
|
|
107
|
+
| WritablePureSelector<T, E>
|
|
108
|
+
|
|
109
|
+
export type WritableState<T, E> = Atom<T, E> | WritableSelector<T, E>
|
|
110
|
+
export type ReadableState<T, E> = Atom<T, E> | Selector<T, E>
|
|
111
|
+
|
|
112
|
+
// biome-ignore format: intersection
|
|
113
|
+
export type RegularAtomFamily<T, K extends Canonical, E = never> =
|
|
114
|
+
& Flat<
|
|
115
|
+
& RegularAtomFamilyToken<T, K, E>
|
|
116
|
+
& {
|
|
117
|
+
create: <Key extends K>(key: Key) => RegularAtomToken<T, Key, E>
|
|
118
|
+
default: T | ((key: K) => T)
|
|
119
|
+
install: (store: RootStore) => void
|
|
120
|
+
internalRoles: string[] | undefined
|
|
121
|
+
subject: Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>
|
|
122
|
+
}
|
|
123
|
+
>
|
|
124
|
+
|
|
125
|
+
// biome-ignore format: intersection
|
|
126
|
+
export type MutableAtomFamily<
|
|
127
|
+
T extends Transceiver<any, any, any>,
|
|
128
|
+
K extends Canonical,
|
|
129
|
+
> =
|
|
130
|
+
& Flat<
|
|
131
|
+
& MutableAtomFamilyToken<T, K>
|
|
132
|
+
& {
|
|
133
|
+
create: <Key extends K>(key: Key) => MutableAtomToken<T, Key>
|
|
134
|
+
class: ConstructorOf<T>
|
|
135
|
+
install: (store: RootStore) => void
|
|
136
|
+
internalRoles: string[] | undefined
|
|
137
|
+
subject: Subject<StateLifecycleEvent<MutableAtomToken<T>>>
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
|
|
141
|
+
export type AtomFamily<T, K extends Canonical, E> =
|
|
142
|
+
| MutableAtomFamily<T extends Transceiver<any, any, any> ? T : never, K>
|
|
143
|
+
| RegularAtomFamily<T, K, E>
|
|
144
|
+
|
|
145
|
+
// biome-ignore format: intersection
|
|
146
|
+
export type WritablePureSelectorFamily<T, K extends Canonical, E> =
|
|
147
|
+
& Flat<
|
|
148
|
+
& WritablePureSelectorFamilyToken<T, K, E>
|
|
149
|
+
& {
|
|
150
|
+
create: <Key extends K>(key: Key) => WritablePureSelectorToken<T, Key, E>
|
|
151
|
+
default: (key: K) => T,
|
|
152
|
+
install: (store: RootStore) => void
|
|
153
|
+
internalRoles: string[] | undefined
|
|
154
|
+
subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>>
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
|
|
158
|
+
// biome-ignore format: intersection
|
|
159
|
+
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
160
|
+
& Flat<
|
|
161
|
+
& WritableHeldSelectorFamilyToken<T, K>
|
|
162
|
+
& {
|
|
163
|
+
create: <Key extends K>(key: Key) => WritableHeldSelectorToken<T, Key>
|
|
164
|
+
default: (key: K) => T,
|
|
165
|
+
install: (store: RootStore) => void
|
|
166
|
+
internalRoles: string[] | undefined
|
|
167
|
+
subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T, K>>>
|
|
168
|
+
}
|
|
169
|
+
>
|
|
170
|
+
|
|
171
|
+
// biome-ignore format: intersection
|
|
172
|
+
export type ReadonlyPureSelectorFamily<T, K extends Canonical, E> =
|
|
173
|
+
& Flat<
|
|
174
|
+
& ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
175
|
+
& {
|
|
176
|
+
create: <Key extends K>(key: Key) => ReadonlyPureSelectorToken<T, Key, E>
|
|
177
|
+
default: (key: K) => T,
|
|
178
|
+
install: (store: RootStore) => void
|
|
179
|
+
internalRoles: string[] | undefined
|
|
180
|
+
subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>>
|
|
181
|
+
}
|
|
182
|
+
>
|
|
183
|
+
|
|
184
|
+
// biome-ignore format: intersection
|
|
185
|
+
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
186
|
+
& Flat<
|
|
187
|
+
& ReadonlyHeldSelectorFamilyToken<T, K>
|
|
188
|
+
& {
|
|
189
|
+
create: <Key extends K>(key: Key) => ReadonlyHeldSelectorToken<T, Key>
|
|
190
|
+
default: (key: K) => T,
|
|
191
|
+
install: (store: RootStore) => void
|
|
192
|
+
internalRoles: string[] | undefined
|
|
193
|
+
subject: Subject<StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>>
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
|
|
197
|
+
export type PureSelectorFamily<T, K extends Canonical, E> =
|
|
198
|
+
| ReadonlyPureSelectorFamily<T, K, E>
|
|
199
|
+
| WritablePureSelectorFamily<T, K, E>
|
|
200
|
+
|
|
201
|
+
export type HeldSelectorFamily<T, K extends Canonical> =
|
|
202
|
+
| ReadonlyHeldSelectorFamily<T, K>
|
|
203
|
+
| WritableHeldSelectorFamily<T, K>
|
|
204
|
+
|
|
205
|
+
export type ReadonlySelectorFamily<T, K extends Canonical, E> =
|
|
206
|
+
| ReadonlyHeldSelectorFamily<T, K>
|
|
207
|
+
| ReadonlyPureSelectorFamily<T, K, E>
|
|
208
|
+
|
|
209
|
+
export type WritableSelectorFamily<T, K extends Canonical, E> =
|
|
210
|
+
| WritableHeldSelectorFamily<T, K>
|
|
211
|
+
| WritablePureSelectorFamily<T, K, E>
|
|
212
|
+
|
|
213
|
+
export type SelectorFamily<T, K extends Canonical, E> =
|
|
214
|
+
| HeldSelectorFamily<T, K>
|
|
215
|
+
| PureSelectorFamily<T, K, E>
|
|
216
|
+
|
|
217
|
+
export type WritableFamily<T, K extends Canonical, E> =
|
|
218
|
+
| AtomFamily<T, K, E>
|
|
219
|
+
| WritableSelectorFamily<T, K, E>
|
|
220
|
+
export type ReadableFamily<T, K extends Canonical, E> =
|
|
221
|
+
| AtomFamily<T, K, E>
|
|
222
|
+
| SelectorFamily<T, K, E>
|
|
223
|
+
|
|
224
|
+
export type AtomIOInternalResource =
|
|
225
|
+
| ReadableFamily<any, any, any>
|
|
226
|
+
| ReadableState<any, any>
|
|
227
|
+
| Timeline<any>
|
|
228
|
+
| Transaction<any>
|
|
@@ -22,11 +22,11 @@ import type {
|
|
|
22
22
|
} from "atom.io"
|
|
23
23
|
import type { Canonical } from "atom.io/json"
|
|
24
24
|
|
|
25
|
+
import type { Transceiver } from "../mutable"
|
|
25
26
|
import type {
|
|
26
27
|
Atom,
|
|
27
28
|
AtomFamily,
|
|
28
29
|
AtomIOInternalResource,
|
|
29
|
-
Fn,
|
|
30
30
|
MutableAtom,
|
|
31
31
|
MutableAtomFamily,
|
|
32
32
|
ReadableFamily,
|
|
@@ -37,14 +37,14 @@ import type {
|
|
|
37
37
|
RegularAtomFamily,
|
|
38
38
|
Selector,
|
|
39
39
|
SelectorFamily,
|
|
40
|
-
Timeline,
|
|
41
|
-
Transceiver,
|
|
42
40
|
WritableFamily,
|
|
43
41
|
WritablePureSelector,
|
|
44
42
|
WritablePureSelectorFamily,
|
|
45
43
|
WritableState,
|
|
46
|
-
} from "
|
|
44
|
+
} from "../state-types"
|
|
45
|
+
import type { Timeline } from "../timeline"
|
|
47
46
|
import type { Transaction } from "../transaction"
|
|
47
|
+
import type { Fn } from "../utility-types"
|
|
48
48
|
|
|
49
49
|
export function deposit<T, E>(
|
|
50
50
|
state: RegularAtom<T, E>,
|
|
@@ -10,6 +10,14 @@ import type {
|
|
|
10
10
|
import { AtomIOLogger } from "atom.io"
|
|
11
11
|
import type { Canonical, stringified } from "atom.io/json"
|
|
12
12
|
|
|
13
|
+
import type { Join } from "../join"
|
|
14
|
+
import { Junction } from "../junction"
|
|
15
|
+
import type { Lineage } from "../lineage"
|
|
16
|
+
import type { Molecule } from "../molecule"
|
|
17
|
+
import type { Tracker, Transceiver } from "../mutable"
|
|
18
|
+
import { getJsonToken, getUpdateToken } from "../mutable"
|
|
19
|
+
import type { OperationProgress } from "../operation"
|
|
20
|
+
import { isReservedIntrospectionKey } from "../reserved-keys"
|
|
13
21
|
import type {
|
|
14
22
|
Atom,
|
|
15
23
|
HeldSelectorFamily,
|
|
@@ -18,15 +26,7 @@ import type {
|
|
|
18
26
|
ReadonlySelector,
|
|
19
27
|
RegularAtomFamily,
|
|
20
28
|
WritableSelector,
|
|
21
|
-
} from "
|
|
22
|
-
import { isReservedIntrospectionKey } from ".."
|
|
23
|
-
import type { Join } from "../join"
|
|
24
|
-
import { Junction } from "../junction"
|
|
25
|
-
import type { Lineage } from "../lineage"
|
|
26
|
-
import type { Molecule } from "../molecule"
|
|
27
|
-
import type { Tracker, Transceiver } from "../mutable"
|
|
28
|
-
import { getJsonToken, getUpdateToken } from "../mutable"
|
|
29
|
-
import type { OperationProgress } from "../operation"
|
|
29
|
+
} from "../state-types"
|
|
30
30
|
import { StatefulSubject, Subject } from "../subject"
|
|
31
31
|
import type { Timeline } from "../timeline"
|
|
32
32
|
import type {
|
|
@@ -34,11 +34,12 @@ import type {
|
|
|
34
34
|
} from "atom.io"
|
|
35
35
|
import type { Canonical } from "atom.io/json"
|
|
36
36
|
|
|
37
|
+
import type { Transceiver } from "../mutable"
|
|
38
|
+
import { NotFoundError } from "../not-found-error"
|
|
37
39
|
import type {
|
|
38
40
|
Atom,
|
|
39
41
|
AtomFamily,
|
|
40
42
|
AtomIOInternalResource,
|
|
41
|
-
Fn,
|
|
42
43
|
HeldSelector,
|
|
43
44
|
HeldSelectorFamily,
|
|
44
45
|
MutableAtom,
|
|
@@ -57,7 +58,6 @@ import type {
|
|
|
57
58
|
RegularAtomFamily,
|
|
58
59
|
Selector,
|
|
59
60
|
SelectorFamily,
|
|
60
|
-
Transceiver,
|
|
61
61
|
WritableFamily,
|
|
62
62
|
WritableHeldSelector,
|
|
63
63
|
WritableHeldSelectorFamily,
|
|
@@ -66,10 +66,10 @@ import type {
|
|
|
66
66
|
WritableSelector,
|
|
67
67
|
WritableSelectorFamily,
|
|
68
68
|
WritableState,
|
|
69
|
-
} from "
|
|
70
|
-
import { NotFoundError } from ".."
|
|
69
|
+
} from "../state-types"
|
|
71
70
|
import type { Timeline } from "../timeline"
|
|
72
71
|
import type { Transaction } from "../transaction"
|
|
72
|
+
import type { Fn } from "../utility-types"
|
|
73
73
|
import type { Store } from "./store"
|
|
74
74
|
|
|
75
75
|
export function withdraw<T, E>(
|