atom.io 0.19.1 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +99 -79
- package/data/dist/index.js +2 -2
- package/data/src/join.ts +67 -50
- package/dist/{chunk-YDOGCZ53.js → chunk-ATKDGVTV.js} +29 -29
- package/dist/{chunk-7VCCW45K.js → chunk-CC7IF7QF.js} +4 -3
- package/dist/{chunk-WX2NCOZR.js → chunk-FTONNX2R.js} +8 -8
- package/dist/{chunk-7ZR244C2.js → chunk-MSCJWACE.js} +92 -72
- package/dist/index.cjs +14 -7
- package/dist/index.d.ts +23 -35
- package/dist/index.js +14 -7
- package/internal/dist/index.cjs +55 -43
- package/internal/dist/index.d.ts +20 -20
- package/internal/dist/index.js +48 -36
- package/internal/src/atom/create-regular-atom.ts +7 -5
- package/internal/src/atom/delete-atom.ts +2 -2
- package/internal/src/families/create-readonly-selector-family.ts +2 -2
- package/internal/src/families/create-regular-atom-family.ts +1 -1
- package/internal/src/families/create-writable-selector-family.ts +1 -1
- package/internal/src/future.ts +4 -2
- package/internal/src/lineage.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +7 -5
- package/internal/src/mutable/tracker.ts +3 -3
- package/internal/src/mutable/transceiver.ts +2 -2
- package/internal/src/selector/delete-selector.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +5 -5
- package/internal/src/store/withdraw.ts +4 -5
- package/internal/src/subject.ts +3 -1
- package/internal/src/subscribe/subscribe-to-transaction.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +13 -8
- package/internal/src/timeline/create-timeline.ts +3 -4
- package/internal/src/transaction/act-upon-store.ts +5 -5
- package/internal/src/transaction/apply-transaction.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +9 -6
- package/internal/src/transaction/create-transaction.ts +10 -10
- package/internal/src/transaction/index.ts +3 -3
- package/internal/src/transaction/is-root-store.ts +2 -2
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/src/attach-introspection-states.ts +3 -3
- package/introspection/src/attach-transaction-index.ts +4 -4
- package/introspection/src/attach-transaction-logs.ts +8 -4
- package/json/dist/index.cjs +6 -2
- package/json/dist/index.js +6 -2
- package/json/src/select-json-family.ts +3 -2
- package/json/src/select-json.ts +3 -1
- package/package.json +243 -241
- package/react/dist/index.cjs +9 -3
- package/react/dist/index.js +9 -3
- package/react/src/use-i.ts +3 -1
- package/react/src/use-tl.ts +6 -2
- package/react-devtools/dist/index.cjs +116 -53
- package/react-devtools/dist/index.d.ts +3 -5
- package/react-devtools/dist/index.js +113 -51
- package/react-devtools/src/AtomIODevtools.tsx +3 -1
- package/react-devtools/src/Button.tsx +3 -1
- package/react-devtools/src/StateIndex.tsx +6 -2
- package/react-devtools/src/TimelineIndex.tsx +6 -2
- package/react-devtools/src/TransactionIndex.tsx +3 -3
- package/react-devtools/src/Updates.tsx +14 -6
- package/realtime/dist/index.cjs +1 -0
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.js +1 -0
- package/realtime/src/realtime-continuity.ts +4 -3
- package/realtime-client/dist/index.cjs +29 -29
- package/realtime-client/dist/index.d.ts +2 -2
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/server-action.ts +2 -2
- package/realtime-client/src/sync-continuity.ts +23 -23
- package/realtime-react/dist/index.cjs +29 -29
- package/realtime-react/dist/index.d.ts +2 -2
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-server-action.ts +3 -3
- package/realtime-server/dist/index.cjs +54 -44
- package/realtime-server/dist/index.d.ts +5 -5
- package/realtime-server/dist/index.js +34 -24
- package/realtime-server/src/ipc-sockets/child-socket.ts +6 -6
- package/realtime-server/src/ipc-sockets/custom-socket.ts +4 -8
- package/realtime-server/src/ipc-sockets/parent-socket.ts +13 -7
- package/realtime-server/src/realtime-action-receiver.ts +7 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +3 -1
- package/realtime-testing/dist/index.cjs +15 -13
- package/realtime-testing/dist/index.js +9 -7
- package/realtime-testing/src/setup-realtime-test.tsx +6 -4
- package/src/atom.ts +4 -8
- package/src/dispose.ts +1 -0
- package/src/index.ts +2 -9
- package/src/selector.ts +4 -8
- package/src/silo.ts +9 -3
- package/src/subscribe.ts +6 -6
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +24 -24
- package/transceivers/set-rtx/dist/index.cjs +11 -12
- package/transceivers/set-rtx/dist/index.js +11 -12
- package/transceivers/set-rtx/src/set-rtx.ts +10 -10
|
@@ -74,29 +74,29 @@ function getJoinMap(store) {
|
|
|
74
74
|
function getJoin(token, store) {
|
|
75
75
|
var _a;
|
|
76
76
|
const joinMap = getJoinMap(store);
|
|
77
|
-
let
|
|
78
|
-
if (
|
|
77
|
+
let myJoin = joinMap.get(token.key);
|
|
78
|
+
if (myJoin === void 0) {
|
|
79
79
|
const rootJoinMap = getJoinMap(internal.IMPLICIT.STORE);
|
|
80
|
-
|
|
81
|
-
if (
|
|
80
|
+
myJoin = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
|
|
81
|
+
if (myJoin === void 0) {
|
|
82
82
|
throw new Error(
|
|
83
83
|
`Join "${token.key}" not found in store "${store.config.name}"`
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
joinMap.set(token.key,
|
|
86
|
+
joinMap.set(token.key, myJoin);
|
|
87
87
|
}
|
|
88
|
-
return
|
|
88
|
+
return myJoin;
|
|
89
89
|
}
|
|
90
90
|
function editRelationsInStore(token, change, store) {
|
|
91
|
-
const
|
|
91
|
+
const myJoin = getJoin(token, store);
|
|
92
92
|
const target = internal.newest(store);
|
|
93
93
|
if (internal.isChildStore(target)) {
|
|
94
94
|
const { transactors } = target.transactionMeta;
|
|
95
|
-
|
|
95
|
+
myJoin.transact(transactors, ({ relations }) => {
|
|
96
96
|
change(relations);
|
|
97
97
|
});
|
|
98
98
|
} else {
|
|
99
|
-
change(
|
|
99
|
+
change(myJoin.relations);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -213,7 +213,9 @@ var setupRealtimeTestClient = (options, name, port) => {
|
|
|
213
213
|
container: document.querySelector(`#app`)
|
|
214
214
|
}
|
|
215
215
|
);
|
|
216
|
-
const prettyPrint = () =>
|
|
216
|
+
const prettyPrint = () => {
|
|
217
|
+
console.log(react.prettyDOM(renderResult.container));
|
|
218
|
+
};
|
|
217
219
|
const dispose2 = () => {
|
|
218
220
|
renderResult.unmount();
|
|
219
221
|
socket.disconnect();
|
|
@@ -245,13 +247,13 @@ var singleClient = (options) => {
|
|
|
245
247
|
var multiClient = (options) => {
|
|
246
248
|
const server = setupRealtimeTestServer(options);
|
|
247
249
|
const clients = recordToEntries(options.clients).reduce(
|
|
248
|
-
(
|
|
249
|
-
|
|
250
|
+
(clientRecord, [name, client]) => {
|
|
251
|
+
clientRecord[name] = setupRealtimeTestClient(
|
|
250
252
|
__spreadProps(__spreadValues({}, options), { client }),
|
|
251
253
|
name,
|
|
252
254
|
server.port
|
|
253
255
|
);
|
|
254
|
-
return
|
|
256
|
+
return clientRecord;
|
|
255
257
|
},
|
|
256
258
|
{}
|
|
257
259
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { myUsernameState } from '../../dist/chunk-O47EQUM6.js';
|
|
2
|
-
import { editRelationsInStore } from '../../dist/chunk-
|
|
3
|
-
import '../../dist/chunk-
|
|
4
|
-
import { recordToEntries } from '../../dist/chunk-
|
|
2
|
+
import { editRelationsInStore } from '../../dist/chunk-MSCJWACE.js';
|
|
3
|
+
import '../../dist/chunk-FTONNX2R.js';
|
|
4
|
+
import { recordToEntries } from '../../dist/chunk-CC7IF7QF.js';
|
|
5
5
|
import '../../dist/chunk-BWWVY5O5.js';
|
|
6
6
|
import { __spreadProps, __spreadValues } from '../../dist/chunk-U2IICNHQ.js';
|
|
7
7
|
import * as http from 'http';
|
|
@@ -90,7 +90,9 @@ var setupRealtimeTestClient = (options, name, port) => {
|
|
|
90
90
|
container: document.querySelector(`#app`)
|
|
91
91
|
}
|
|
92
92
|
);
|
|
93
|
-
const prettyPrint = () =>
|
|
93
|
+
const prettyPrint = () => {
|
|
94
|
+
console.log(prettyDOM(renderResult.container));
|
|
95
|
+
};
|
|
94
96
|
const dispose = () => {
|
|
95
97
|
renderResult.unmount();
|
|
96
98
|
socket.disconnect();
|
|
@@ -122,13 +124,13 @@ var singleClient = (options) => {
|
|
|
122
124
|
var multiClient = (options) => {
|
|
123
125
|
const server = setupRealtimeTestServer(options);
|
|
124
126
|
const clients = recordToEntries(options.clients).reduce(
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
+
(clientRecord, [name, client]) => {
|
|
128
|
+
clientRecord[name] = setupRealtimeTestClient(
|
|
127
129
|
__spreadProps(__spreadValues({}, options), { client }),
|
|
128
130
|
name,
|
|
129
131
|
server.port
|
|
130
132
|
);
|
|
131
|
-
return
|
|
133
|
+
return clientRecord;
|
|
132
134
|
},
|
|
133
135
|
{}
|
|
134
136
|
);
|
|
@@ -159,7 +159,9 @@ export const setupRealtimeTestClient = (
|
|
|
159
159
|
},
|
|
160
160
|
)
|
|
161
161
|
|
|
162
|
-
const prettyPrint = () =>
|
|
162
|
+
const prettyPrint = () => {
|
|
163
|
+
console.log(prettyDOM(renderResult.container))
|
|
164
|
+
}
|
|
163
165
|
|
|
164
166
|
const dispose = () => {
|
|
165
167
|
renderResult.unmount()
|
|
@@ -200,13 +202,13 @@ export const multiClient = <ClientNames extends string>(
|
|
|
200
202
|
): RealtimeTestAPI__MultiClient<ClientNames> => {
|
|
201
203
|
const server = setupRealtimeTestServer(options)
|
|
202
204
|
const clients = recordToEntries(options.clients).reduce(
|
|
203
|
-
(
|
|
204
|
-
|
|
205
|
+
(clientRecord, [name, client]) => {
|
|
206
|
+
clientRecord[name] = setupRealtimeTestClient(
|
|
205
207
|
{ ...options, client },
|
|
206
208
|
name,
|
|
207
209
|
server.port,
|
|
208
210
|
)
|
|
209
|
-
return
|
|
211
|
+
return clientRecord
|
|
210
212
|
},
|
|
211
213
|
{} as Record<ClientNames, RealtimeTestClientBuilder>,
|
|
212
214
|
)
|
package/src/atom.ts
CHANGED
|
@@ -57,10 +57,8 @@ export type RegularAtomFamilyTokenWithCall<
|
|
|
57
57
|
K extends Json.Serializable,
|
|
58
58
|
> =
|
|
59
59
|
& RegularAtomFamilyToken<T, K>
|
|
60
|
-
&
|
|
61
|
-
|
|
62
|
-
(key: K): RegularAtomToken<T>
|
|
63
|
-
}
|
|
60
|
+
& /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
|
|
61
|
+
((key: K) => RegularAtomToken<T>)
|
|
64
62
|
// biome-ignore format: intersection
|
|
65
63
|
export type RegularAtomFamily<T, K extends Json.Serializable> =
|
|
66
64
|
& RegularAtomFamilyToken<T, K>
|
|
@@ -102,10 +100,8 @@ export type MutableAtomFamilyTokenWithCall<
|
|
|
102
100
|
K extends Json.Serializable,
|
|
103
101
|
> =
|
|
104
102
|
& MutableAtomFamilyToken<T, J, K>
|
|
105
|
-
&
|
|
106
|
-
|
|
107
|
-
(key: K): MutableAtomToken<T, J>
|
|
108
|
-
}
|
|
103
|
+
& /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
|
|
104
|
+
((key: K) => MutableAtomToken<T, J>)
|
|
109
105
|
// biome-ignore format: intersection
|
|
110
106
|
export type MutableAtomFamily<
|
|
111
107
|
T extends Transceiver<any>,
|
package/src/dispose.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import type { Transceiver } from "atom.io/internal"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
|
+
import type { AtomFamily, AtomFamilyToken } from "./atom"
|
|
3
4
|
import type {
|
|
4
|
-
AtomFamily,
|
|
5
|
-
AtomFamilyToken,
|
|
6
|
-
RegularAtomFamily,
|
|
7
|
-
RegularAtomFamilyToken,
|
|
8
|
-
} from "./atom"
|
|
9
|
-
import type {
|
|
10
|
-
ReadonlySelectorFamily,
|
|
11
|
-
ReadonlySelectorFamilyToken,
|
|
12
5
|
SelectorFamily,
|
|
13
6
|
SelectorFamilyToken,
|
|
14
7
|
WritableSelectorFamily,
|
|
@@ -28,7 +21,7 @@ export * from "./timeline"
|
|
|
28
21
|
export * from "./transaction"
|
|
29
22
|
export * from "./validators"
|
|
30
23
|
|
|
31
|
-
export type
|
|
24
|
+
export type Func = (...parameters: any[]) => any
|
|
32
25
|
|
|
33
26
|
export type RegularAtomToken<T> = {
|
|
34
27
|
key: string
|
package/src/selector.ts
CHANGED
|
@@ -53,10 +53,8 @@ export type WritableSelectorFamilyTokenWithCall<
|
|
|
53
53
|
K extends Json.Serializable,
|
|
54
54
|
> =
|
|
55
55
|
& WritableSelectorFamilyToken<T, K>
|
|
56
|
-
&
|
|
57
|
-
|
|
58
|
-
(key: K): WritableSelectorToken<T>
|
|
59
|
-
}
|
|
56
|
+
& /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
|
|
57
|
+
((key: K) => WritableSelectorToken<T>)
|
|
60
58
|
// biome-ignore format: intersection
|
|
61
59
|
export type WritableSelectorFamily<T, K extends Json.Serializable> =
|
|
62
60
|
& WritableSelectorFamilyToken<T, K>
|
|
@@ -78,10 +76,8 @@ export type ReadonlySelectorFamilyTokenWithCall<
|
|
|
78
76
|
K extends Json.Serializable,
|
|
79
77
|
> =
|
|
80
78
|
& ReadonlySelectorFamilyToken<T, K>
|
|
81
|
-
&
|
|
82
|
-
|
|
83
|
-
(key: K): ReadonlySelectorToken<T>
|
|
84
|
-
}
|
|
79
|
+
& /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
|
|
80
|
+
((key: K) => ReadonlySelectorToken<T>)
|
|
85
81
|
// biome-ignore format: intersection
|
|
86
82
|
export type ReadonlySelectorFamily<T, K extends Json.Serializable> =
|
|
87
83
|
& ((key: K) => ReadonlySelectorToken<T>)
|
package/src/silo.ts
CHANGED
|
@@ -85,9 +85,15 @@ export class Silo {
|
|
|
85
85
|
this.timeline = (options) => createTimeline(options, s)
|
|
86
86
|
this.findState = (token, key) => findInStore(token, key, s) as any
|
|
87
87
|
this.getState = (token) => getFromStore(token, s)
|
|
88
|
-
this.setState = (token, newValue) =>
|
|
88
|
+
this.setState = (token, newValue) => {
|
|
89
|
+
setIntoStore(token, newValue, s)
|
|
90
|
+
}
|
|
89
91
|
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
|
|
90
|
-
this.undo = (token) =>
|
|
91
|
-
|
|
92
|
+
this.undo = (token) => {
|
|
93
|
+
timeTravel(`undo`, token, s)
|
|
94
|
+
}
|
|
95
|
+
this.redo = (token) => {
|
|
96
|
+
timeTravel(`redo`, token, s)
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
99
|
}
|
package/src/subscribe.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
TimelineUpdate,
|
|
16
16
|
TransactionToken,
|
|
17
17
|
TransactionUpdate,
|
|
18
|
-
|
|
18
|
+
Func,
|
|
19
19
|
} from "."
|
|
20
20
|
|
|
21
21
|
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
@@ -25,8 +25,8 @@ export type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
|
25
25
|
}
|
|
26
26
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
27
27
|
|
|
28
|
-
export type TransactionUpdateHandler
|
|
29
|
-
data: TransactionUpdate
|
|
28
|
+
export type TransactionUpdateHandler<F extends Func> = (
|
|
29
|
+
data: TransactionUpdate<F>,
|
|
30
30
|
) => void
|
|
31
31
|
|
|
32
32
|
export function subscribe<T>(
|
|
@@ -35,9 +35,9 @@ export function subscribe<T>(
|
|
|
35
35
|
key?: string,
|
|
36
36
|
store?: Store,
|
|
37
37
|
): () => void
|
|
38
|
-
export function subscribe
|
|
39
|
-
token: TransactionToken
|
|
40
|
-
handleUpdate: TransactionUpdateHandler
|
|
38
|
+
export function subscribe<F extends Func>(
|
|
39
|
+
token: TransactionToken<F>,
|
|
40
|
+
handleUpdate: TransactionUpdateHandler<F>,
|
|
41
41
|
key?: string,
|
|
42
42
|
store?: Store,
|
|
43
43
|
): () => void
|
package/src/timeline.ts
CHANGED
|
@@ -36,10 +36,10 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
|
36
36
|
return createTimeline(options, IMPLICIT.STORE)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export const redo = (
|
|
40
|
-
timeTravel(`redo`,
|
|
39
|
+
export const redo = (tl: TimelineToken<any>): void => {
|
|
40
|
+
timeTravel(`redo`, tl, IMPLICIT.STORE)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export const undo = (
|
|
44
|
-
timeTravel(`undo`,
|
|
43
|
+
export const undo = (tl: TimelineToken<any>): void => {
|
|
44
|
+
timeTravel(`undo`, tl, IMPLICIT.STORE)
|
|
45
45
|
}
|
package/src/transaction.ts
CHANGED
|
@@ -11,10 +11,10 @@ import type {
|
|
|
11
11
|
ReadonlySelectorToken,
|
|
12
12
|
WritableToken,
|
|
13
13
|
findState,
|
|
14
|
-
|
|
14
|
+
Func,
|
|
15
15
|
} from "."
|
|
16
16
|
|
|
17
|
-
export type TransactionToken<F> = {
|
|
17
|
+
export type TransactionToken<F extends Func> = {
|
|
18
18
|
key: string
|
|
19
19
|
type: `transaction`
|
|
20
20
|
__F?: F
|
|
@@ -22,15 +22,15 @@ export type TransactionToken<F> = {
|
|
|
22
22
|
|
|
23
23
|
export type TransactionUpdateContent =
|
|
24
24
|
| KeyedStateUpdate<unknown>
|
|
25
|
-
| TransactionUpdate
|
|
25
|
+
| TransactionUpdate<Func>
|
|
26
26
|
|
|
27
|
-
export type TransactionUpdate
|
|
27
|
+
export type TransactionUpdate<F extends Func> = {
|
|
28
28
|
key: string
|
|
29
29
|
id: string
|
|
30
30
|
epoch: number
|
|
31
31
|
updates: TransactionUpdateContent[]
|
|
32
|
-
params: Parameters
|
|
33
|
-
output: ReturnType
|
|
32
|
+
params: Parameters<F>
|
|
33
|
+
output: ReturnType<F>
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type Transactors = Readonly<{
|
|
@@ -53,38 +53,38 @@ export type TransactorsWithRunAndEnv = Readonly<{
|
|
|
53
53
|
}>
|
|
54
54
|
export type ReadonlyTransactors = Pick<Transactors, `find` | `get`>
|
|
55
55
|
|
|
56
|
-
export type Read
|
|
56
|
+
export type Read<F extends Func> = (
|
|
57
57
|
transactors: ReadonlyTransactors,
|
|
58
|
-
...parameters: Parameters
|
|
59
|
-
) => ReturnType
|
|
58
|
+
...parameters: Parameters<F>
|
|
59
|
+
) => ReturnType<F>
|
|
60
60
|
|
|
61
|
-
export type Write
|
|
61
|
+
export type Write<F extends Func> = (
|
|
62
62
|
transactors: Transactors,
|
|
63
|
-
...parameters: Parameters
|
|
64
|
-
) => ReturnType
|
|
63
|
+
...parameters: Parameters<F>
|
|
64
|
+
) => ReturnType<F>
|
|
65
65
|
|
|
66
|
-
export type Transact
|
|
66
|
+
export type Transact<F extends Func> = (
|
|
67
67
|
transactors: TransactorsWithRunAndEnv,
|
|
68
|
-
...parameters: Parameters
|
|
69
|
-
) => ReturnType
|
|
68
|
+
...parameters: Parameters<F>
|
|
69
|
+
) => ReturnType<F>
|
|
70
70
|
|
|
71
|
-
export type TransactionOptions
|
|
71
|
+
export type TransactionOptions<F extends Func> = {
|
|
72
72
|
key: string
|
|
73
|
-
do: Transact
|
|
73
|
+
do: Transact<F>
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
77
|
-
Token extends TransactionToken<infer
|
|
77
|
+
Token extends TransactionToken<infer F> ? F : never
|
|
78
78
|
|
|
79
|
-
export function transaction
|
|
80
|
-
options: TransactionOptions
|
|
81
|
-
): TransactionToken
|
|
79
|
+
export function transaction<F extends Func>(
|
|
80
|
+
options: TransactionOptions<F>,
|
|
81
|
+
): TransactionToken<F> {
|
|
82
82
|
return createTransaction(options, IMPLICIT.STORE)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export function runTransaction
|
|
86
|
-
token: TransactionToken
|
|
85
|
+
export function runTransaction<F extends Func>(
|
|
86
|
+
token: TransactionToken<F>,
|
|
87
87
|
id = arbitrary(),
|
|
88
|
-
): (...parameters: Parameters
|
|
88
|
+
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
89
89
|
return actUponStore(token, id, IMPLICIT.STORE)
|
|
90
90
|
}
|
|
@@ -87,7 +87,7 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
87
87
|
this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
|
|
88
88
|
}
|
|
89
89
|
} catch (thrown) {
|
|
90
|
-
console.error(`Failed to apply transaction to SetRTX
|
|
90
|
+
console.error(`Failed to apply transaction to SetRTX:`, thrown);
|
|
91
91
|
throw thrown;
|
|
92
92
|
} finally {
|
|
93
93
|
unsubscribe();
|
|
@@ -100,10 +100,9 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
100
100
|
return this.subject.subscribe(key, fn);
|
|
101
101
|
}
|
|
102
102
|
subscribe(key, fn) {
|
|
103
|
-
return this.subject.subscribe(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
103
|
+
return this.subject.subscribe(key, (update) => {
|
|
104
|
+
fn(`${this.cacheUpdateNumber}=${update}`);
|
|
105
|
+
});
|
|
107
106
|
}
|
|
108
107
|
emit(update) {
|
|
109
108
|
this.subject.next(update);
|
|
@@ -123,8 +122,8 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
123
122
|
this.delete(json.parseJson(value));
|
|
124
123
|
break;
|
|
125
124
|
case `tx`:
|
|
126
|
-
for (const
|
|
127
|
-
this.doStep(
|
|
125
|
+
for (const subUpdate of value.split(`;`)) {
|
|
126
|
+
this.doStep(subUpdate);
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
}
|
|
@@ -158,12 +157,12 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
158
157
|
let done = false;
|
|
159
158
|
while (!done) {
|
|
160
159
|
this.cacheIdx %= this.cacheLimit;
|
|
161
|
-
const
|
|
160
|
+
const u = this.cache[this.cacheIdx];
|
|
162
161
|
this.cacheIdx--;
|
|
163
|
-
if (!
|
|
162
|
+
if (!u) {
|
|
164
163
|
return `OUT_OF_RANGE`;
|
|
165
164
|
}
|
|
166
|
-
this.undo(
|
|
165
|
+
this.undo(u);
|
|
167
166
|
done = this.cacheIdx === eventIdx - 1;
|
|
168
167
|
}
|
|
169
168
|
const innerUpdate = update.substring(breakpoint + 1);
|
|
@@ -187,8 +186,8 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
187
186
|
break;
|
|
188
187
|
case `clear`: {
|
|
189
188
|
const values = JSON.parse(value);
|
|
190
|
-
for (const
|
|
191
|
-
this.add(
|
|
189
|
+
for (const v of values)
|
|
190
|
+
this.add(v);
|
|
192
191
|
break;
|
|
193
192
|
}
|
|
194
193
|
case `tx`: {
|
|
@@ -85,7 +85,7 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
85
85
|
this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
|
|
86
86
|
}
|
|
87
87
|
} catch (thrown) {
|
|
88
|
-
console.error(`Failed to apply transaction to SetRTX
|
|
88
|
+
console.error(`Failed to apply transaction to SetRTX:`, thrown);
|
|
89
89
|
throw thrown;
|
|
90
90
|
} finally {
|
|
91
91
|
unsubscribe();
|
|
@@ -98,10 +98,9 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
98
98
|
return this.subject.subscribe(key, fn);
|
|
99
99
|
}
|
|
100
100
|
subscribe(key, fn) {
|
|
101
|
-
return this.subject.subscribe(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
);
|
|
101
|
+
return this.subject.subscribe(key, (update) => {
|
|
102
|
+
fn(`${this.cacheUpdateNumber}=${update}`);
|
|
103
|
+
});
|
|
105
104
|
}
|
|
106
105
|
emit(update) {
|
|
107
106
|
this.subject.next(update);
|
|
@@ -121,8 +120,8 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
121
120
|
this.delete(parseJson(value));
|
|
122
121
|
break;
|
|
123
122
|
case `tx`:
|
|
124
|
-
for (const
|
|
125
|
-
this.doStep(
|
|
123
|
+
for (const subUpdate of value.split(`;`)) {
|
|
124
|
+
this.doStep(subUpdate);
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -156,12 +155,12 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
156
155
|
let done = false;
|
|
157
156
|
while (!done) {
|
|
158
157
|
this.cacheIdx %= this.cacheLimit;
|
|
159
|
-
const
|
|
158
|
+
const u = this.cache[this.cacheIdx];
|
|
160
159
|
this.cacheIdx--;
|
|
161
|
-
if (!
|
|
160
|
+
if (!u) {
|
|
162
161
|
return `OUT_OF_RANGE`;
|
|
163
162
|
}
|
|
164
|
-
this.undo(
|
|
163
|
+
this.undo(u);
|
|
165
164
|
done = this.cacheIdx === eventIdx - 1;
|
|
166
165
|
}
|
|
167
166
|
const innerUpdate = update.substring(breakpoint + 1);
|
|
@@ -185,8 +184,8 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
185
184
|
break;
|
|
186
185
|
case `clear`: {
|
|
187
186
|
const values = JSON.parse(value);
|
|
188
|
-
for (const
|
|
189
|
-
this.add(
|
|
187
|
+
for (const v of values)
|
|
188
|
+
this.add(v);
|
|
190
189
|
break;
|
|
191
190
|
}
|
|
192
191
|
case `tx`: {
|
|
@@ -110,7 +110,7 @@ export class SetRTX<P extends primitive>
|
|
|
110
110
|
this.emit(`tx:${this.transactionUpdates.join(`;`)}`)
|
|
111
111
|
}
|
|
112
112
|
} catch (thrown) {
|
|
113
|
-
console.error(`Failed to apply transaction to SetRTX
|
|
113
|
+
console.error(`Failed to apply transaction to SetRTX:`, thrown)
|
|
114
114
|
throw thrown
|
|
115
115
|
} finally {
|
|
116
116
|
unsubscribe()
|
|
@@ -130,9 +130,9 @@ export class SetRTX<P extends primitive>
|
|
|
130
130
|
key: string,
|
|
131
131
|
fn: (update: NumberedSetUpdate) => void,
|
|
132
132
|
): () => void {
|
|
133
|
-
return this.subject.subscribe(key, (update) =>
|
|
134
|
-
fn(`${this.cacheUpdateNumber}=${update}`)
|
|
135
|
-
)
|
|
133
|
+
return this.subject.subscribe(key, (update) => {
|
|
134
|
+
fn(`${this.cacheUpdateNumber}=${update}`)
|
|
135
|
+
})
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
public emit(update: SetUpdate): void {
|
|
@@ -154,8 +154,8 @@ export class SetRTX<P extends primitive>
|
|
|
154
154
|
this.delete(parseJson(value as Stringified<P>))
|
|
155
155
|
break
|
|
156
156
|
case `tx`:
|
|
157
|
-
for (const
|
|
158
|
-
this.doStep(
|
|
157
|
+
for (const subUpdate of value.split(`;`)) {
|
|
158
|
+
this.doStep(subUpdate as SetUpdate)
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -191,12 +191,12 @@ export class SetRTX<P extends primitive>
|
|
|
191
191
|
let done = false
|
|
192
192
|
while (!done) {
|
|
193
193
|
this.cacheIdx %= this.cacheLimit
|
|
194
|
-
const
|
|
194
|
+
const u = this.cache[this.cacheIdx]
|
|
195
195
|
this.cacheIdx--
|
|
196
|
-
if (!
|
|
196
|
+
if (!u) {
|
|
197
197
|
return `OUT_OF_RANGE`
|
|
198
198
|
}
|
|
199
|
-
this.undo(
|
|
199
|
+
this.undo(u)
|
|
200
200
|
done = this.cacheIdx === eventIdx - 1
|
|
201
201
|
}
|
|
202
202
|
const innerUpdate = update.substring(breakpoint + 1) as SetUpdate
|
|
@@ -221,7 +221,7 @@ export class SetRTX<P extends primitive>
|
|
|
221
221
|
break
|
|
222
222
|
case `clear`: {
|
|
223
223
|
const values = JSON.parse(value) as P[]
|
|
224
|
-
for (const
|
|
224
|
+
for (const v of values) this.add(v)
|
|
225
225
|
break
|
|
226
226
|
}
|
|
227
227
|
case `tx`: {
|