atom.io 0.36.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internal/index.d.ts +83 -67
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +98 -98
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +5 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +2 -3
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +27 -29
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +8 -9
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +7 -8
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +9 -2
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +3 -0
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +3 -3
- package/src/internal/atom/create-regular-atom.ts +5 -5
- package/src/internal/atom/has-role.ts +12 -0
- package/src/internal/atom/index.ts +1 -0
- package/src/internal/caching.ts +38 -16
- package/src/internal/families/find-in-store.ts +1 -1
- package/src/internal/families/get-family-of-token.ts +1 -1
- package/src/internal/families/init-family-member.ts +1 -1
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/read-or-compute-value.ts +29 -20
- package/src/internal/index.ts +8 -8
- package/src/internal/join/join-internal.ts +7 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-json-token.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/get-update-token.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +27 -31
- package/src/internal/mutable/tracker.ts +29 -23
- package/src/internal/mutable/transceiver.ts +11 -10
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
- package/src/internal/selector/create-writable-held-selector.ts +3 -3
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/set-state/set-atom.ts +15 -22
- package/src/internal/set-state/set-into-store.ts +5 -4
- package/src/internal/store/counterfeit.ts +1 -1
- package/src/internal/store/deposit.ts +7 -8
- package/src/internal/store/store.ts +6 -6
- package/src/internal/store/withdraw.ts +8 -8
- package/src/internal/subscribe/subscribe-in-store.ts +2 -2
- package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +3 -3
- package/src/internal/transaction/act-upon-store.ts +2 -2
- package/src/internal/transaction/apply-transaction.ts +2 -2
- package/src/internal/transaction/build-transaction.ts +2 -2
- package/src/internal/transaction/create-transaction.ts +3 -3
- package/src/internal/transaction/index.ts +2 -2
- package/src/internal/transaction/is-root-store.ts +4 -2
- package/src/internal/utility-types.ts +1 -1
- package/src/introspection/attach-introspection-states.ts +3 -3
- package/src/introspection/attach-transaction-index.ts +4 -4
- package/src/introspection/attach-transaction-logs.ts +4 -4
- package/src/introspection/auditor.ts +3 -3
- package/src/main/atom.ts +4 -4
- package/src/main/dispose-state.ts +4 -3
- package/src/main/find-state.ts +1 -1
- package/src/main/get-state.ts +6 -5
- package/src/main/reset-state.ts +3 -3
- package/src/main/set-state.ts +3 -3
- package/src/main/subscribe.ts +3 -3
- package/src/main/tokens.ts +6 -10
- package/src/main/transaction.ts +13 -15
- package/src/react/use-json.ts +5 -5
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
- package/src/realtime-client/pull-mutable-atom.ts +5 -8
- package/src/realtime-client/push-state.ts +6 -5
- package/src/realtime-client/server-action.ts +5 -4
- package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
- package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
- package/src/realtime-react/use-server-action.ts +2 -2
- package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-provider.ts +1 -1
- package/src/transceivers/set-rtx/set-rtx.ts +14 -1
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
package/src/main/find-state.ts
CHANGED
|
@@ -30,7 +30,7 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
|
|
|
30
30
|
* @overload Mutable Atom
|
|
31
31
|
*/
|
|
32
32
|
export function findState<
|
|
33
|
-
T extends Transceiver<any, any>,
|
|
33
|
+
T extends Transceiver<any, any, any>,
|
|
34
34
|
K extends Canonical,
|
|
35
35
|
Key extends K,
|
|
36
36
|
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
|
package/src/main/get-state.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ViewOf } from "atom.io/internal"
|
|
2
|
+
import { getFromStore, IMPLICIT } from "atom.io/internal"
|
|
2
3
|
import type { Canonical } from "atom.io/json"
|
|
3
4
|
|
|
4
5
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
@@ -10,7 +11,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
10
11
|
* @overload Default
|
|
11
12
|
* @default
|
|
12
13
|
*/
|
|
13
|
-
export function getState<T>(token: ReadableToken<T>): T
|
|
14
|
+
export function getState<T>(token: ReadableToken<T>): ViewOf<T>
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Read or compute the current value of a state
|
|
@@ -22,7 +23,7 @@ export function getState<T>(token: ReadableToken<T>): T
|
|
|
22
23
|
export function getState<T, K extends Canonical, Key extends K>(
|
|
23
24
|
token: ReadableFamilyToken<T, K>,
|
|
24
25
|
key: Key,
|
|
25
|
-
): T
|
|
26
|
+
): ViewOf<T>
|
|
26
27
|
|
|
27
28
|
export function getState(
|
|
28
29
|
...params:
|
|
@@ -30,7 +31,7 @@ export function getState(
|
|
|
30
31
|
| [token: ReadableToken<any>]
|
|
31
32
|
): any {
|
|
32
33
|
if (params.length === 2) {
|
|
33
|
-
return
|
|
34
|
+
return getFromStore(IMPLICIT.STORE, ...params)
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return getFromStore(IMPLICIT.STORE, ...params)
|
|
36
37
|
}
|
package/src/main/reset-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IMPLICIT, resetInStore } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
@@ -26,8 +26,8 @@ export function resetState(
|
|
|
26
26
|
| [token: WritableToken<any>]
|
|
27
27
|
): void {
|
|
28
28
|
if (params.length === 2) {
|
|
29
|
-
|
|
29
|
+
resetInStore(IMPLICIT.STORE, ...params)
|
|
30
30
|
} else {
|
|
31
|
-
|
|
31
|
+
resetInStore(IMPLICIT.STORE, ...params)
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/main/set-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IMPLICIT, setIntoStore } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "./tokens"
|
|
@@ -45,8 +45,8 @@ export function setState<T, New extends T>(
|
|
|
45
45
|
| [token: WritableToken<T>, value: New | Setter<T, New>]
|
|
46
46
|
): void {
|
|
47
47
|
if (params.length === 2) {
|
|
48
|
-
|
|
48
|
+
setIntoStore(IMPLICIT.STORE, ...params)
|
|
49
49
|
} else {
|
|
50
|
-
|
|
50
|
+
setIntoStore(IMPLICIT.STORE, ...params)
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/main/subscribe.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Flat,
|
|
1
|
+
import type { Flat, Fn } from "atom.io/internal"
|
|
2
2
|
import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
|
|
3
3
|
|
|
4
4
|
import type {
|
|
@@ -20,7 +20,7 @@ export type KeyedStateUpdate<T> = Flat<
|
|
|
20
20
|
}
|
|
21
21
|
>
|
|
22
22
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
23
|
-
export type TransactionUpdateHandler<F extends
|
|
23
|
+
export type TransactionUpdateHandler<F extends Fn> = (
|
|
24
24
|
data: TransactionUpdate<F>,
|
|
25
25
|
) => void
|
|
26
26
|
|
|
@@ -45,7 +45,7 @@ export function subscribe<T>(
|
|
|
45
45
|
* @returns A function that can be called to unsubscribe from the transaction
|
|
46
46
|
* @overload Transaction
|
|
47
47
|
*/
|
|
48
|
-
export function subscribe<F extends
|
|
48
|
+
export function subscribe<F extends Fn>(
|
|
49
49
|
token: TransactionToken<F>,
|
|
50
50
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
51
51
|
key?: string,
|
package/src/main/tokens.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AsJSON,
|
|
1
|
+
import type { AsJSON, Fn, Transceiver } from "atom.io/internal"
|
|
2
2
|
import type { Canonical, stringified } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -53,7 +53,7 @@ export type TimelineToken<M> = {
|
|
|
53
53
|
__M?: M
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export type TransactionToken<F extends
|
|
56
|
+
export type TransactionToken<F extends Fn> = {
|
|
57
57
|
/** The unique identifier of the transaction */
|
|
58
58
|
key: string
|
|
59
59
|
/** Discriminator */
|
|
@@ -63,7 +63,7 @@ export type TransactionToken<F extends Func> = {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export type AtomToken<T, K extends Canonical = any> =
|
|
66
|
-
| MutableAtomToken<T extends Transceiver<any, any> ? T : never, K>
|
|
66
|
+
| MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
67
67
|
| RegularAtomToken<T, K>
|
|
68
68
|
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
69
69
|
/** The unique identifier of the atom. */
|
|
@@ -76,7 +76,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
|
76
76
|
__T?: T
|
|
77
77
|
}
|
|
78
78
|
export type MutableAtomToken<
|
|
79
|
-
T extends Transceiver<any, any>,
|
|
79
|
+
T extends Transceiver<any, any, any>,
|
|
80
80
|
K extends Canonical = any,
|
|
81
81
|
> = {
|
|
82
82
|
/** The unique identifier of the atom. */
|
|
@@ -87,8 +87,6 @@ export type MutableAtomToken<
|
|
|
87
87
|
family?: FamilyMetadata<K>
|
|
88
88
|
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
89
89
|
__J?: AsJSON<T>
|
|
90
|
-
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
91
|
-
__U?: T extends Transceiver<infer Update, any> ? Update : never
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
export type SelectorToken<T, K extends Canonical = any> =
|
|
@@ -159,7 +157,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
|
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
162
|
-
| MutableAtomFamilyToken<T extends Transceiver<any, any> ? T : never, K>
|
|
160
|
+
| MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
163
161
|
| RegularAtomFamilyToken<T, K>
|
|
164
162
|
export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
165
163
|
/** The unique identifier of the atom family */
|
|
@@ -172,7 +170,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
|
172
170
|
__K?: K
|
|
173
171
|
}
|
|
174
172
|
export type MutableAtomFamilyToken<
|
|
175
|
-
T extends Transceiver<any, any>,
|
|
173
|
+
T extends Transceiver<any, any, any>,
|
|
176
174
|
K extends Canonical,
|
|
177
175
|
> = {
|
|
178
176
|
/** The unique identifier of the atom family */
|
|
@@ -181,8 +179,6 @@ export type MutableAtomFamilyToken<
|
|
|
181
179
|
type: `mutable_atom_family`
|
|
182
180
|
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
183
181
|
__T?: T
|
|
184
|
-
/** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
|
|
185
|
-
__J?: AsJSON<T>
|
|
186
182
|
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
187
183
|
__K?: K
|
|
188
184
|
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AsJSON,
|
|
3
|
-
EnvironmentData,
|
|
4
|
-
Func,
|
|
5
|
-
Transceiver,
|
|
6
|
-
} from "atom.io/internal"
|
|
1
|
+
import type { AsJSON, EnvironmentData, Fn, Transceiver } from "atom.io/internal"
|
|
7
2
|
import {
|
|
8
3
|
actUponStore,
|
|
9
4
|
arbitrary,
|
|
@@ -33,6 +28,9 @@ export type StateCreation<Token extends ReadableToken<any>> = {
|
|
|
33
28
|
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
34
29
|
| AtomDisposal<Token>
|
|
35
30
|
| SelectorDisposal<Token>
|
|
31
|
+
export type StateLifecycleEvent<Token extends ReadableToken<any>> =
|
|
32
|
+
| StateCreation<Token>
|
|
33
|
+
| StateDisposal<Token>
|
|
36
34
|
|
|
37
35
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
38
36
|
type: `state_disposal`
|
|
@@ -72,9 +70,9 @@ export type TransactionUpdateContent =
|
|
|
72
70
|
| MoleculeTransfer
|
|
73
71
|
| StateCreation<ReadableToken<unknown>>
|
|
74
72
|
| StateDisposal<ReadableToken<unknown>>
|
|
75
|
-
| TransactionUpdate<
|
|
73
|
+
| TransactionUpdate<Fn>
|
|
76
74
|
|
|
77
|
-
export type TransactionUpdate<F extends
|
|
75
|
+
export type TransactionUpdate<F extends Fn> = {
|
|
78
76
|
type: `transaction_update`
|
|
79
77
|
key: string
|
|
80
78
|
id: string
|
|
@@ -91,7 +89,7 @@ export type ActorToolkit = Readonly<{
|
|
|
91
89
|
set: typeof setState
|
|
92
90
|
reset: typeof resetState
|
|
93
91
|
find: typeof findState
|
|
94
|
-
json: <T extends Transceiver<any, any>>(
|
|
92
|
+
json: <T extends Transceiver<any, any, any>>(
|
|
95
93
|
state: MutableAtomToken<T>,
|
|
96
94
|
) => WritablePureSelectorToken<AsJSON<T>>
|
|
97
95
|
dispose: typeof disposeState
|
|
@@ -99,21 +97,21 @@ export type ActorToolkit = Readonly<{
|
|
|
99
97
|
env: () => EnvironmentData
|
|
100
98
|
}>
|
|
101
99
|
|
|
102
|
-
export type Read<F extends
|
|
100
|
+
export type Read<F extends Fn> = (
|
|
103
101
|
toolkit: ReaderToolkit,
|
|
104
102
|
...parameters: Parameters<F>
|
|
105
103
|
) => ReturnType<F>
|
|
106
|
-
export type Write<F extends
|
|
104
|
+
export type Write<F extends Fn> = (
|
|
107
105
|
toolkit: WriterToolkit,
|
|
108
106
|
...parameters: Parameters<F>
|
|
109
107
|
) => ReturnType<F>
|
|
110
|
-
export type Transact<F extends
|
|
108
|
+
export type Transact<F extends Fn> = (
|
|
111
109
|
toolkit: ActorToolkit,
|
|
112
110
|
...parameters: Parameters<F>
|
|
113
111
|
) => ReturnType<F>
|
|
114
112
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
115
113
|
Token extends TransactionToken<infer F> ? F : never
|
|
116
|
-
export type TransactionOptions<F extends
|
|
114
|
+
export type TransactionOptions<F extends Fn> = {
|
|
117
115
|
/** The unique identifier of the transaction */
|
|
118
116
|
key: string
|
|
119
117
|
/** The operation to perform */
|
|
@@ -125,7 +123,7 @@ export type TransactionOptions<F extends Func> = {
|
|
|
125
123
|
* @param options - {@link TransactionOptions}
|
|
126
124
|
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
127
125
|
*/
|
|
128
|
-
export function transaction<F extends
|
|
126
|
+
export function transaction<F extends Fn>(
|
|
129
127
|
options: TransactionOptions<F>,
|
|
130
128
|
): TransactionToken<F> {
|
|
131
129
|
return createTransaction(IMPLICIT.STORE, options)
|
|
@@ -137,7 +135,7 @@ export function transaction<F extends Func>(
|
|
|
137
135
|
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
|
138
136
|
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
139
137
|
*/
|
|
140
|
-
export function runTransaction<F extends
|
|
138
|
+
export function runTransaction<F extends Fn>(
|
|
141
139
|
token: TransactionToken<F>,
|
|
142
140
|
id: string = arbitrary(),
|
|
143
141
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|
package/src/react/use-json.ts
CHANGED
|
@@ -7,14 +7,14 @@ import * as React from "react"
|
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
import { useO } from "./use-o"
|
|
9
9
|
|
|
10
|
-
export function useJSON<T extends Transceiver<any, any>>(
|
|
10
|
+
export function useJSON<T extends Transceiver<any, any, any>>(
|
|
11
11
|
token: MutableAtomToken<T>,
|
|
12
12
|
): AsJSON<T>
|
|
13
13
|
|
|
14
|
-
export function useJSON<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
): AsJSON<T>
|
|
14
|
+
export function useJSON<
|
|
15
|
+
T extends Transceiver<any, any, any>,
|
|
16
|
+
K extends Canonical,
|
|
17
|
+
>(token: MutableAtomFamilyToken<T, K>, key: K): AsJSON<T>
|
|
18
18
|
|
|
19
19
|
export function useJSON(
|
|
20
20
|
token: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
TransactionToken,
|
|
5
5
|
TransactionUpdate,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import { findInStore, type
|
|
7
|
+
import { findInStore, type Fn } from "atom.io/internal"
|
|
8
8
|
import { useI, useO } from "atom.io/react"
|
|
9
9
|
import { type FC, useContext } from "react"
|
|
10
10
|
|
|
@@ -13,9 +13,9 @@ import { DevtoolsContext } from "./store"
|
|
|
13
13
|
import { article } from "./Updates"
|
|
14
14
|
|
|
15
15
|
export const TransactionLog: FC<{
|
|
16
|
-
token: TransactionToken<
|
|
16
|
+
token: TransactionToken<Fn>
|
|
17
17
|
isOpenState: RegularAtomToken<boolean>
|
|
18
|
-
logState: ReadonlyPureSelectorToken<TransactionUpdate<
|
|
18
|
+
logState: ReadonlyPureSelectorToken<TransactionUpdate<Fn>[]>
|
|
19
19
|
}> = ({ token, isOpenState, logState }) => {
|
|
20
20
|
const log = useO(logState)
|
|
21
21
|
const isOpen = useO(isOpenState)
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
TimelineUpdate,
|
|
4
4
|
TransactionUpdate,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import type {
|
|
6
|
+
import type { Fn } from "atom.io/internal"
|
|
7
7
|
import { discoverType, prettyJson } from "atom.io/introspection"
|
|
8
8
|
import { stringifyJson } from "atom.io/json"
|
|
9
9
|
import * as React from "react"
|
|
@@ -37,7 +37,7 @@ const AtomUpdateFC: React.FC<{
|
|
|
37
37
|
|
|
38
38
|
const TransactionUpdateFC: React.FC<{
|
|
39
39
|
serialNumber: number
|
|
40
|
-
transactionUpdate: TransactionUpdate<
|
|
40
|
+
transactionUpdate: TransactionUpdate<Fn>
|
|
41
41
|
}> = ({ serialNumber, transactionUpdate }) => {
|
|
42
42
|
return (
|
|
43
43
|
<article
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import {
|
|
4
4
|
actUponStore,
|
|
5
5
|
getEpochNumberOfContinuity,
|
|
@@ -22,7 +22,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
22
22
|
optimisticUpdates: AtomIO.TransactionUpdate<any>[],
|
|
23
23
|
confirmedUpdates: AtomIO.TransactionUpdate<any>[],
|
|
24
24
|
) =>
|
|
25
|
-
(confirmed: AtomIO.TransactionUpdate<
|
|
25
|
+
(confirmed: AtomIO.TransactionUpdate<Fn>): void => {
|
|
26
26
|
function reconcileEpoch(
|
|
27
27
|
optimisticUpdate: AtomIO.TransactionUpdate<any>,
|
|
28
28
|
confirmedUpdate: AtomIO.TransactionUpdate<any>,
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type { AsJSON, Store, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
|
|
3
3
|
import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
|
|
4
4
|
import { parseJson } from "atom.io/json"
|
|
5
5
|
import type { Socket } from "socket.io-client"
|
|
6
6
|
|
|
7
7
|
/* eslint-disable no-console */
|
|
8
8
|
|
|
9
|
-
export function pullMutableAtomFamilyMember<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
token: AtomIO.MutableAtomToken<T>,
|
|
13
|
-
): () => void {
|
|
9
|
+
export function pullMutableAtomFamilyMember<
|
|
10
|
+
T extends Transceiver<any, any, any>,
|
|
11
|
+
>(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
|
|
14
12
|
if (!(`family` in token)) {
|
|
15
13
|
console.error(`Token is not a family member:`, token)
|
|
16
14
|
return () => {}
|
|
@@ -21,13 +19,10 @@ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
|
|
|
21
19
|
const jsonToken = getJsonToken(store, token)
|
|
22
20
|
setIntoStore(store, jsonToken, data)
|
|
23
21
|
})
|
|
24
|
-
socket.on(
|
|
25
|
-
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
setIntoStore(store, trackerToken, data)
|
|
29
|
-
},
|
|
30
|
-
)
|
|
22
|
+
socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
|
|
23
|
+
const trackerToken = getUpdateToken(token)
|
|
24
|
+
setIntoStore(store, trackerToken, data)
|
|
25
|
+
})
|
|
31
26
|
socket.emit(`sub:${familyKey}`, subKey)
|
|
32
27
|
return () => {
|
|
33
28
|
socket.off(`serve:${token.key}`)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type { AsJSON, Store, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
|
|
3
3
|
import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
|
-
export function pullMutableAtom<T extends Transceiver<any, any>>(
|
|
6
|
+
export function pullMutableAtom<T extends Transceiver<any, any, any>>(
|
|
7
7
|
store: Store,
|
|
8
8
|
socket: Socket,
|
|
9
9
|
token: AtomIO.MutableAtomToken<T>,
|
|
@@ -13,12 +13,9 @@ export function pullMutableAtom<T extends Transceiver<any, any>>(
|
|
|
13
13
|
socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
|
|
14
14
|
setIntoStore(store, jsonToken, data)
|
|
15
15
|
})
|
|
16
|
-
socket.on(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setIntoStore(store, updateToken, data)
|
|
20
|
-
},
|
|
21
|
-
)
|
|
16
|
+
socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
|
|
17
|
+
setIntoStore(store, updateToken, data)
|
|
18
|
+
})
|
|
22
19
|
socket.emit(`sub:${token.key}`)
|
|
23
20
|
return () => {
|
|
24
21
|
socket.off(`init:${token.key}`)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import type { WritableToken } from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { subscribeToState } from "atom.io/internal"
|
|
3
4
|
import type { Json } from "atom.io/json"
|
|
4
5
|
import type { Socket } from "socket.io-client"
|
|
5
6
|
|
|
6
7
|
export function pushState<J extends Json.Serializable>(
|
|
7
|
-
store:
|
|
8
|
+
store: Store,
|
|
8
9
|
socket: Socket,
|
|
9
|
-
token:
|
|
10
|
+
token: WritableToken<J>,
|
|
10
11
|
): () => void {
|
|
11
12
|
socket.emit(`claim:${token.key}`)
|
|
12
|
-
|
|
13
|
+
subscribeToState(store, token, `push`, ({ newValue }) => {
|
|
13
14
|
socket.emit(`pub:${token.key}`, newValue)
|
|
14
15
|
})
|
|
15
16
|
return () => {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
|
+
import { subscribeToTransaction } from "atom.io/internal"
|
|
3
4
|
import type { Socket } from "socket.io-client"
|
|
4
5
|
|
|
5
|
-
export function serverAction<F extends
|
|
6
|
-
store:
|
|
6
|
+
export function serverAction<F extends Fn>(
|
|
7
|
+
store: Store,
|
|
7
8
|
socket: Socket,
|
|
8
9
|
token: AtomIO.TransactionToken<F>,
|
|
9
10
|
): () => void {
|
|
10
|
-
const unsubscribeFromLocalUpdates =
|
|
11
|
+
const unsubscribeFromLocalUpdates = subscribeToTransaction(
|
|
11
12
|
store,
|
|
12
13
|
token,
|
|
13
14
|
`tx-run:${token.key}:${socket.id}`,
|
|
@@ -6,7 +6,7 @@ import * as React from "react"
|
|
|
6
6
|
|
|
7
7
|
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
|
-
export function usePullMutable<T extends Transceiver<any, any>>(
|
|
9
|
+
export function usePullMutable<T extends Transceiver<any, any, any>>(
|
|
10
10
|
token: AtomIO.MutableAtomToken<T>,
|
|
11
11
|
): T {
|
|
12
12
|
const store = React.useContext(StoreContext)
|
|
@@ -9,7 +9,7 @@ import * as React from "react"
|
|
|
9
9
|
import { useRealtimeService } from "./use-realtime-service"
|
|
10
10
|
|
|
11
11
|
export function usePullMutableAtomFamilyMember<
|
|
12
|
-
T extends Transceiver<any, any>,
|
|
12
|
+
T extends Transceiver<any, any, any>,
|
|
13
13
|
K extends Canonical,
|
|
14
14
|
Key extends K,
|
|
15
15
|
>(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn } from "atom.io/internal"
|
|
3
3
|
import { actUponStore, arbitrary } from "atom.io/internal"
|
|
4
4
|
import { StoreContext } from "atom.io/react"
|
|
5
5
|
import * as RTC from "atom.io/realtime-client"
|
|
@@ -7,7 +7,7 @@ import * as React from "react"
|
|
|
7
7
|
|
|
8
8
|
import { useRealtimeService } from "./use-realtime-service"
|
|
9
9
|
|
|
10
|
-
export function useServerAction<F extends
|
|
10
|
+
export function useServerAction<F extends Fn>(
|
|
11
11
|
token: AtomIO.TransactionToken<F>,
|
|
12
12
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
13
13
|
const store = React.useContext(StoreContext)
|
|
@@ -21,7 +21,7 @@ export function realtimeMutableFamilyProvider({
|
|
|
21
21
|
store = IMPLICIT.STORE,
|
|
22
22
|
}: ServerConfig) {
|
|
23
23
|
return function mutableFamilyProvider<
|
|
24
|
-
T extends Transceiver<any, any>,
|
|
24
|
+
T extends Transceiver<any, any, any>,
|
|
25
25
|
K extends Canonical,
|
|
26
26
|
>(
|
|
27
27
|
family: AtomIO.MutableAtomFamilyToken<T, K>,
|
|
@@ -17,7 +17,7 @@ export function realtimeMutableProvider({
|
|
|
17
17
|
store = IMPLICIT.STORE,
|
|
18
18
|
}: ServerConfig) {
|
|
19
19
|
return function mutableProvider<
|
|
20
|
-
Core extends Transceiver<Json.Serializable, Json.Serializable>,
|
|
20
|
+
Core extends Transceiver<any, Json.Serializable, Json.Serializable>,
|
|
21
21
|
>(token: AtomIO.MutableAtomToken<Core>): () => void {
|
|
22
22
|
let unsubscribeFromStateUpdates: (() => void) | null = null
|
|
23
23
|
|
|
@@ -7,6 +7,13 @@ export type SetUpdateType = `add` | `clear` | `del` | `tx`
|
|
|
7
7
|
export type SetUpdate = `${SetUpdateType}:${string}`
|
|
8
8
|
export type NumberedSetUpdate = `${number}=${SetUpdate}`
|
|
9
9
|
|
|
10
|
+
export interface SetRTXView<P extends primitive> extends ReadonlySet<P> {
|
|
11
|
+
readonly cache: ReadonlyArray<NumberedSetUpdate | null>
|
|
12
|
+
readonly cacheLimit: number
|
|
13
|
+
readonly cacheIdx: number
|
|
14
|
+
readonly cacheUpdateNumber: number
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export interface SetRTXJson<P extends primitive> extends Json.Object {
|
|
11
18
|
members: P[]
|
|
12
19
|
cache: (NumberedSetUpdate | null)[]
|
|
@@ -16,7 +23,9 @@ export interface SetRTXJson<P extends primitive> extends Json.Object {
|
|
|
16
23
|
}
|
|
17
24
|
export class SetRTX<P extends primitive>
|
|
18
25
|
extends Set<P>
|
|
19
|
-
implements
|
|
26
|
+
implements
|
|
27
|
+
Transceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,
|
|
28
|
+
Lineage
|
|
20
29
|
{
|
|
21
30
|
public mode: TransceiverMode = `record`
|
|
22
31
|
public readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()
|
|
@@ -42,6 +51,10 @@ export class SetRTX<P extends primitive>
|
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
|
|
54
|
+
public view(): SetRTXView<P> {
|
|
55
|
+
return this
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
public toJSON(): SetRTXJson<P> {
|
|
46
59
|
return {
|
|
47
60
|
members: [...this],
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { MutableAtom, Transceiver } from ".."
|
|
2
|
-
import { Tracker } from "../mutable"
|
|
3
|
-
import type { Store } from "../store"
|
|
4
|
-
|
|
5
|
-
export function copyMutableIfNeeded<T extends Transceiver<any, any>>(
|
|
6
|
-
target: Store,
|
|
7
|
-
atom: MutableAtom<T>,
|
|
8
|
-
origin: Store,
|
|
9
|
-
): T {
|
|
10
|
-
const originValue = origin.valueMap.get(atom.key) as
|
|
11
|
-
| Transceiver<any, any>
|
|
12
|
-
| undefined
|
|
13
|
-
const targetValue = target.valueMap.get(atom.key)
|
|
14
|
-
|
|
15
|
-
if (originValue !== targetValue) {
|
|
16
|
-
return targetValue
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (originValue === undefined) {
|
|
20
|
-
return new atom.class()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
origin.logger.info(`📃`, `atom`, atom.key, `copying`)
|
|
24
|
-
const jsonValue = originValue.toJSON()
|
|
25
|
-
const copiedValue = atom.class.fromJSON(jsonValue)
|
|
26
|
-
target.valueMap.set(atom.key, copiedValue)
|
|
27
|
-
new Tracker(atom, origin)
|
|
28
|
-
return copiedValue
|
|
29
|
-
}
|