atom.io 0.31.1 → 0.32.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/data/dist/index.d.ts +3 -154
- package/data/dist/index.js +11 -559
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-3PQTWLQQ.js +83 -0
- package/dist/chunk-3ZFTRSNG.js +523 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-KVI5OBF2.js +153 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-UQEYZ3OI.js} +1814 -721
- package/dist/chunk-UYYKOGZQ.js +1034 -0
- package/dist/chunk-VRJP2PCU.js +631 -0
- package/dist/chunk-X7SD2NXU.js +108 -0
- package/dist/index.d.ts +137 -12
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +3 -149
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/explicit-state-types.ts +1 -0
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -0
- package/eslint-plugin/src/walk.ts +1 -0
- package/internal/dist/index.d.ts +129 -58
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +2 -0
- package/internal/src/install-into-store.ts +1 -1
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +21 -430
- package/internal/src/junction.ts +7 -4
- package/internal/src/keys.ts +7 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/pretty-print.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +6 -9
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +4 -2
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +22 -22
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +19 -38
- package/internal/src/timeline/time-travel.ts +2 -1
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +2 -2
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +31 -49
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.js +31 -18
- package/react-devtools/src/Updates.tsx +12 -0
- package/react-devtools/src/devtools.scss +16 -14
- package/react-devtools/src/json-editor/editors-by-type/utilities/cast-to-json.ts +2 -1
- package/realtime/dist/index.d.ts +1 -2
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +3 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +9 -9
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +2 -4
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/ipc-sockets/child-socket.ts +2 -0
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +10 -2
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.js +20 -22
- package/realtime-testing/src/setup-realtime-test.tsx +2 -1
- package/src/index.ts +4 -0
- package/src/join.ts +218 -0
- package/src/silo.ts +4 -4
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +4 -3
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/transceivers/set-rtx/src/set-rtx.ts +4 -7
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/ephemeral/dist/index.d.ts +0 -67
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- package/react-devtools/src/json-editor/assets/Untitled-1.ai +2 -1436
- package/react-devtools/src/json-editor/assets/data-vis.ai +1 -1548
- package/react-devtools/src/json-editor/comp/json-editor-sketches.ai +5 -1449
- /package/{ephemeral/src → src}/find-state.ts +0 -0
|
@@ -102,7 +102,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
102
102
|
key: subsequentOptimistic.key,
|
|
103
103
|
} as const
|
|
104
104
|
const { id, params } = subsequentOptimistic
|
|
105
|
-
actUponStore(token, id
|
|
105
|
+
actUponStore(store, token, id)(...params)
|
|
106
106
|
}
|
|
107
107
|
store.logger.info(
|
|
108
108
|
`⏩`,
|
|
@@ -177,7 +177,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
177
177
|
continuityKey,
|
|
178
178
|
`has no optimistic updates to deal with`,
|
|
179
179
|
)
|
|
180
|
-
const continuityEpoch = getEpochNumberOfContinuity(
|
|
180
|
+
const continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
|
|
181
181
|
const isRoot = isRootStore(store)
|
|
182
182
|
|
|
183
183
|
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
@@ -189,7 +189,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
189
189
|
)
|
|
190
190
|
ingestTransactionUpdate(`newValue`, confirmed, store)
|
|
191
191
|
socket.emit(`ack:${continuityKey}`, confirmed.epoch)
|
|
192
|
-
setEpochNumberOfContinuity(continuityKey, confirmed.epoch
|
|
192
|
+
setEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)
|
|
193
193
|
} else if (isRoot && continuityEpoch !== undefined) {
|
|
194
194
|
store.logger.info(
|
|
195
195
|
`🧑⚖️`,
|
|
@@ -7,9 +7,9 @@ import type { Socket } from "socket.io-client"
|
|
|
7
7
|
/* eslint-disable no-console */
|
|
8
8
|
|
|
9
9
|
export function pullAtomFamilyMember<J extends Json.Serializable>(
|
|
10
|
-
token: AtomIO.RegularAtomToken<J>,
|
|
11
|
-
socket: Socket,
|
|
12
10
|
store: Store,
|
|
11
|
+
socket: Socket,
|
|
12
|
+
token: AtomIO.RegularAtomToken<J>,
|
|
13
13
|
): () => void {
|
|
14
14
|
if (!(`family` in token)) {
|
|
15
15
|
console.error(`Token is not a family member:`, token)
|
|
@@ -4,9 +4,9 @@ import type { Json } from "atom.io/json"
|
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
6
|
export function pullAtom<J extends Json.Serializable>(
|
|
7
|
-
token: AtomIO.RegularAtomToken<J>,
|
|
8
|
-
socket: Socket,
|
|
9
7
|
store: Store,
|
|
8
|
+
socket: Socket,
|
|
9
|
+
token: AtomIO.RegularAtomToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
const setServedValue = (data: J) => {
|
|
12
12
|
setIntoStore(store, token, data)
|
|
@@ -11,9 +11,9 @@ export function pullMutableAtomFamilyMember<
|
|
|
11
11
|
T extends Transceiver<any>,
|
|
12
12
|
J extends Json.Serializable,
|
|
13
13
|
>(
|
|
14
|
-
token: AtomIO.MutableAtomToken<T, J>,
|
|
15
|
-
socket: Socket,
|
|
16
14
|
store: Store,
|
|
15
|
+
socket: Socket,
|
|
16
|
+
token: AtomIO.MutableAtomToken<T, J>,
|
|
17
17
|
): () => void {
|
|
18
18
|
if (!(`family` in token)) {
|
|
19
19
|
console.error(`Token is not a family member:`, token)
|
|
@@ -8,9 +8,9 @@ export function pullMutableAtom<
|
|
|
8
8
|
T extends Transceiver<any>,
|
|
9
9
|
J extends Json.Serializable,
|
|
10
10
|
>(
|
|
11
|
-
token: AtomIO.MutableAtomToken<T, J>,
|
|
12
|
-
socket: Socket,
|
|
13
11
|
store: Store,
|
|
12
|
+
socket: Socket,
|
|
13
|
+
token: AtomIO.MutableAtomToken<T, J>,
|
|
14
14
|
): () => void {
|
|
15
15
|
const jsonToken = getJsonToken(store, token)
|
|
16
16
|
const updateToken = getUpdateToken(token)
|
|
@@ -8,9 +8,9 @@ import { pullMutableAtomFamilyMember } from "./pull-mutable-atom-family-member"
|
|
|
8
8
|
/* eslint-disable no-console */
|
|
9
9
|
|
|
10
10
|
export function pullSelectorFamilyMember<T>(
|
|
11
|
-
token: AtomIO.SelectorToken<T>,
|
|
12
|
-
socket: Socket,
|
|
13
11
|
store: Store,
|
|
12
|
+
socket: Socket,
|
|
13
|
+
token: AtomIO.SelectorToken<T>,
|
|
14
14
|
): () => void {
|
|
15
15
|
if (!(`family` in token)) {
|
|
16
16
|
console.error(`Token is not a family member:`, token)
|
|
@@ -26,11 +26,11 @@ export function pullSelectorFamilyMember<T>(
|
|
|
26
26
|
}
|
|
27
27
|
switch (atom.type) {
|
|
28
28
|
case `atom`: {
|
|
29
|
-
unsubscribes.push(pullAtomFamilyMember(
|
|
29
|
+
unsubscribes.push(pullAtomFamilyMember(store, socket, atom))
|
|
30
30
|
break
|
|
31
31
|
}
|
|
32
32
|
case `mutable_atom`: {
|
|
33
|
-
unsubscribes.push(pullMutableAtomFamilyMember(
|
|
33
|
+
unsubscribes.push(pullMutableAtomFamilyMember(store, socket, atom))
|
|
34
34
|
break
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -6,9 +6,9 @@ import { pullAtom } from "./pull-atom"
|
|
|
6
6
|
import { pullMutableAtom } from "./pull-mutable-atom"
|
|
7
7
|
|
|
8
8
|
export function pullSelector<T>(
|
|
9
|
-
token: AtomIO.SelectorToken<T>,
|
|
10
|
-
socket: Socket,
|
|
11
9
|
store: Store,
|
|
10
|
+
socket: Socket,
|
|
11
|
+
token: AtomIO.SelectorToken<T>,
|
|
12
12
|
): () => void {
|
|
13
13
|
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key)
|
|
14
14
|
const unsubscribes: Array<() => void> = []
|
|
@@ -20,11 +20,11 @@ export function pullSelector<T>(
|
|
|
20
20
|
}
|
|
21
21
|
switch (atom.type) {
|
|
22
22
|
case `atom`: {
|
|
23
|
-
unsubscribes.push(pullAtom(
|
|
23
|
+
unsubscribes.push(pullAtom(store, socket, atom))
|
|
24
24
|
break
|
|
25
25
|
}
|
|
26
26
|
case `mutable_atom`: {
|
|
27
|
-
unsubscribes.push(pullMutableAtom(
|
|
27
|
+
unsubscribes.push(pullMutableAtom(store, socket, atom))
|
|
28
28
|
break
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -4,19 +4,14 @@ import type { Json } from "atom.io/json"
|
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
6
|
export function pushState<J extends Json.Serializable>(
|
|
7
|
-
token: AtomIO.WritableToken<J>,
|
|
8
|
-
socket: Socket,
|
|
9
7
|
store: Internal.Store,
|
|
8
|
+
socket: Socket,
|
|
9
|
+
token: AtomIO.WritableToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
socket.emit(`claim:${token.key}`)
|
|
12
|
-
Internal.subscribeToState(
|
|
13
|
-
token
|
|
14
|
-
|
|
15
|
-
socket.emit(`pub:${token.key}`, newValue)
|
|
16
|
-
},
|
|
17
|
-
`push`,
|
|
18
|
-
store,
|
|
19
|
-
)
|
|
12
|
+
Internal.subscribeToState(store, token, `push`, ({ newValue }) => {
|
|
13
|
+
socket.emit(`pub:${token.key}`, newValue)
|
|
14
|
+
})
|
|
20
15
|
return () => {
|
|
21
16
|
socket.off(`pub:${token.key}`)
|
|
22
17
|
socket.emit(`unclaim:${token.key}`)
|
|
@@ -3,17 +3,17 @@ import * as Internal from "atom.io/internal"
|
|
|
3
3
|
import type { Socket } from "socket.io-client"
|
|
4
4
|
|
|
5
5
|
export function serverAction<F extends Internal.Func>(
|
|
6
|
-
token: AtomIO.TransactionToken<F>,
|
|
7
|
-
socket: Socket,
|
|
8
6
|
store: Internal.Store,
|
|
7
|
+
socket: Socket,
|
|
8
|
+
token: AtomIO.TransactionToken<F>,
|
|
9
9
|
): () => void {
|
|
10
10
|
const unsubscribeFromLocalUpdates = Internal.subscribeToTransaction(
|
|
11
|
+
store,
|
|
11
12
|
token,
|
|
13
|
+
`tx-run:${token.key}:${socket.id}`,
|
|
12
14
|
(clientUpdate) => {
|
|
13
15
|
socket.emit(`tx-run:${token.key}`, clientUpdate)
|
|
14
16
|
},
|
|
15
|
-
`tx-run:${token.key}:${socket.id}`,
|
|
16
|
-
store,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
return () => {
|
|
@@ -20,9 +20,9 @@ import { useConcealState } from "./continuity/use-conceal-state"
|
|
|
20
20
|
import { useRevealState } from "./continuity/use-reveal-state"
|
|
21
21
|
|
|
22
22
|
export function syncContinuity(
|
|
23
|
-
continuity: ContinuityToken,
|
|
24
|
-
socket: Socket,
|
|
25
23
|
store: Store,
|
|
24
|
+
socket: Socket,
|
|
25
|
+
continuity: ContinuityToken,
|
|
26
26
|
): () => void {
|
|
27
27
|
const continuityKey = continuity.key
|
|
28
28
|
const optimisticUpdates = getFromStore(store, optimisticUpdateQueue)
|
|
@@ -45,7 +45,7 @@ export function syncContinuity(
|
|
|
45
45
|
}
|
|
46
46
|
i++
|
|
47
47
|
}
|
|
48
|
-
setEpochNumberOfContinuity(continuityKey, epoch
|
|
48
|
+
setEpochNumberOfContinuity(store, continuityKey, epoch)
|
|
49
49
|
}
|
|
50
50
|
socket.off(`continuity-init:${continuityKey}`)
|
|
51
51
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity)
|
|
@@ -61,9 +61,11 @@ export function syncContinuity(
|
|
|
61
61
|
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)
|
|
62
62
|
|
|
63
63
|
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
64
|
-
assignTransactionToContinuity(continuityKey, transaction.key
|
|
64
|
+
assignTransactionToContinuity(store, continuityKey, transaction.key)
|
|
65
65
|
const unsubscribeFromTransactionUpdates = subscribeToTransaction(
|
|
66
|
+
store,
|
|
66
67
|
transaction,
|
|
68
|
+
`tx-run:${continuityKey}`,
|
|
67
69
|
(clientUpdate) => {
|
|
68
70
|
store.logger.info(
|
|
69
71
|
`🤞`,
|
|
@@ -104,8 +106,6 @@ export function syncContinuity(
|
|
|
104
106
|
params: clientUpdate.params,
|
|
105
107
|
})
|
|
106
108
|
},
|
|
107
|
-
`tx-run:${continuityKey}`,
|
|
108
|
-
store,
|
|
109
109
|
)
|
|
110
110
|
return unsubscribeFromTransactionUpdates
|
|
111
111
|
})
|
|
@@ -1,155 +1,6 @@
|
|
|
1
|
+
export { RealtimeContext, RealtimeProvider, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity } from '../../dist/chunk-KVI5OBF2.js';
|
|
2
|
+
import '../../dist/chunk-3ZFTRSNG.js';
|
|
3
|
+
import '../../dist/chunk-4LWKCEW3.js';
|
|
4
|
+
import '../../dist/chunk-3PQTWLQQ.js';
|
|
5
|
+
import '../../dist/chunk-UQEYZ3OI.js';
|
|
1
6
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
2
|
-
import { useI, StoreContext, useO } from 'atom.io/react';
|
|
3
|
-
import * as RTC from 'atom.io/realtime-client';
|
|
4
|
-
import { syncContinuity } from 'atom.io/realtime-client';
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
import { findInStore, actUponStore, arbitrary } from 'atom.io/internal';
|
|
8
|
-
|
|
9
|
-
var RealtimeContext = React.createContext({
|
|
10
|
-
socket: null,
|
|
11
|
-
services: null
|
|
12
|
-
});
|
|
13
|
-
var RealtimeProvider = ({ children, socket }) => {
|
|
14
|
-
const services = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15
|
-
const setMyId = useI(RTC.myIdState__INTERNAL);
|
|
16
|
-
React.useEffect(() => {
|
|
17
|
-
setMyId(socket?.id);
|
|
18
|
-
socket?.on(`connect`, () => {
|
|
19
|
-
setMyId(socket.id);
|
|
20
|
-
});
|
|
21
|
-
socket?.on(`disconnect`, () => {
|
|
22
|
-
setMyId(undefined);
|
|
23
|
-
});
|
|
24
|
-
}, [socket, setMyId]);
|
|
25
|
-
return /* @__PURE__ */ jsx(RealtimeContext.Provider, { value: { socket, services }, children });
|
|
26
|
-
};
|
|
27
|
-
var { NODE_ENV } = globalThis.env ?? {};
|
|
28
|
-
var IN_DEV = NODE_ENV === `development`;
|
|
29
|
-
function noop() {
|
|
30
|
-
}
|
|
31
|
-
function useSingleEffect(effect, deps) {
|
|
32
|
-
if (IN_DEV) {
|
|
33
|
-
const cleanup = React.useRef(noop);
|
|
34
|
-
React.useEffect(() => {
|
|
35
|
-
let dispose = cleanup.current;
|
|
36
|
-
if (dispose === noop) {
|
|
37
|
-
dispose = effect() ?? noop;
|
|
38
|
-
cleanup.current = dispose;
|
|
39
|
-
} else {
|
|
40
|
-
return () => {
|
|
41
|
-
dispose();
|
|
42
|
-
cleanup.current = noop;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}, deps);
|
|
46
|
-
} else {
|
|
47
|
-
React.useEffect(effect, deps);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// realtime-react/src/on-mount.ts
|
|
52
|
-
function onMount(effect) {
|
|
53
|
-
useSingleEffect(effect, []);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// realtime-react/src/use-realtime-service.ts
|
|
57
|
-
function useRealtimeService(key, create) {
|
|
58
|
-
const { socket, services } = React.useContext(RealtimeContext);
|
|
59
|
-
onMount(() => {
|
|
60
|
-
let service = services?.get(key);
|
|
61
|
-
if (service) {
|
|
62
|
-
service[0]++;
|
|
63
|
-
} else {
|
|
64
|
-
const dispose = socket ? create(socket) : undefined;
|
|
65
|
-
service = [1, dispose];
|
|
66
|
-
services?.set(key, service);
|
|
67
|
-
}
|
|
68
|
-
return () => {
|
|
69
|
-
if (service) {
|
|
70
|
-
service[0]--;
|
|
71
|
-
if (service[0] === 0) {
|
|
72
|
-
service[1]?.();
|
|
73
|
-
services?.delete(key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// realtime-react/src/use-pull-atom.ts
|
|
81
|
-
function usePullAtom(token) {
|
|
82
|
-
const store = React.useContext(StoreContext);
|
|
83
|
-
useRealtimeService(
|
|
84
|
-
`pull:${token.key}`,
|
|
85
|
-
(socket) => RTC.pullAtom(token, socket, store)
|
|
86
|
-
);
|
|
87
|
-
return useO(token);
|
|
88
|
-
}
|
|
89
|
-
function usePullAtomFamilyMember(family, subKey) {
|
|
90
|
-
const store = React.useContext(StoreContext);
|
|
91
|
-
const token = findInStore(store, family, subKey);
|
|
92
|
-
useRealtimeService(
|
|
93
|
-
`pull:${token.key}`,
|
|
94
|
-
(socket) => RTC.pullAtomFamilyMember(token, socket, store)
|
|
95
|
-
);
|
|
96
|
-
return useO(token);
|
|
97
|
-
}
|
|
98
|
-
function usePullMutable(token) {
|
|
99
|
-
const store = React.useContext(StoreContext);
|
|
100
|
-
useRealtimeService(
|
|
101
|
-
`pull:${token.key}`,
|
|
102
|
-
(socket) => RTC.pullMutableAtom(token, socket, store)
|
|
103
|
-
);
|
|
104
|
-
return useO(token);
|
|
105
|
-
}
|
|
106
|
-
function usePullMutableAtomFamilyMember(familyToken, key) {
|
|
107
|
-
const store = React.useContext(StoreContext);
|
|
108
|
-
const token = findInStore(store, familyToken, key);
|
|
109
|
-
useRealtimeService(
|
|
110
|
-
`pull:${token.key}`,
|
|
111
|
-
(socket) => RTC.pullMutableAtomFamilyMember(token, socket, store)
|
|
112
|
-
);
|
|
113
|
-
return useO(token);
|
|
114
|
-
}
|
|
115
|
-
function usePullSelector(token) {
|
|
116
|
-
const store = React.useContext(StoreContext);
|
|
117
|
-
useRealtimeService(
|
|
118
|
-
`pull:${token.key}`,
|
|
119
|
-
(socket) => RTC.pullSelector(token, socket, store)
|
|
120
|
-
);
|
|
121
|
-
return useO(token);
|
|
122
|
-
}
|
|
123
|
-
function usePullSelectorFamilyMember(familyToken, key) {
|
|
124
|
-
const store = React.useContext(StoreContext);
|
|
125
|
-
const token = findInStore(store, familyToken, key);
|
|
126
|
-
useRealtimeService(
|
|
127
|
-
`pull:${token.key}`,
|
|
128
|
-
(socket) => RTC.pullSelectorFamilyMember(token, socket, store)
|
|
129
|
-
);
|
|
130
|
-
return useO(token);
|
|
131
|
-
}
|
|
132
|
-
function usePush(token) {
|
|
133
|
-
const store = React.useContext(StoreContext);
|
|
134
|
-
useRealtimeService(
|
|
135
|
-
`push:${token.key}`,
|
|
136
|
-
(socket) => RTC.pushState(token, socket, store)
|
|
137
|
-
);
|
|
138
|
-
return useI(token);
|
|
139
|
-
}
|
|
140
|
-
function useServerAction(token) {
|
|
141
|
-
const store = React.useContext(StoreContext);
|
|
142
|
-
useRealtimeService(
|
|
143
|
-
`tx:${token.key}`,
|
|
144
|
-
(socket) => RTC.serverAction(token, socket, store)
|
|
145
|
-
);
|
|
146
|
-
return actUponStore(token, arbitrary(), store);
|
|
147
|
-
}
|
|
148
|
-
function useSyncContinuity(token) {
|
|
149
|
-
const store = React.useContext(StoreContext);
|
|
150
|
-
useRealtimeService(`tx-sync:${token.key}`, (socket) => {
|
|
151
|
-
return syncContinuity(token, socket, store);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { RealtimeContext, RealtimeProvider, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity };
|
|
@@ -15,7 +15,7 @@ export function usePullAtomFamilyMember<
|
|
|
15
15
|
const store = React.useContext(StoreContext)
|
|
16
16
|
const token = findInStore(store, family, subKey)
|
|
17
17
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
18
|
-
RTC.pullAtomFamilyMember(
|
|
18
|
+
RTC.pullAtomFamilyMember(store, socket, token),
|
|
19
19
|
)
|
|
20
20
|
return useO(token)
|
|
21
21
|
}
|
|
@@ -11,7 +11,7 @@ export function usePullAtom<J extends Json.Serializable>(
|
|
|
11
11
|
): J {
|
|
12
12
|
const store = React.useContext(StoreContext)
|
|
13
13
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
14
|
-
RTC.pullAtom(
|
|
14
|
+
RTC.pullAtom(store, socket, token),
|
|
15
15
|
)
|
|
16
16
|
return useO(token)
|
|
17
17
|
}
|
|
@@ -13,7 +13,7 @@ export function usePullMutable<
|
|
|
13
13
|
>(token: AtomIO.MutableAtomToken<T, J>): T {
|
|
14
14
|
const store = React.useContext(StoreContext)
|
|
15
15
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
16
|
-
RTC.pullMutableAtom(
|
|
16
|
+
RTC.pullMutableAtom(store, socket, token),
|
|
17
17
|
)
|
|
18
18
|
return useO(token)
|
|
19
19
|
}
|
|
@@ -17,7 +17,7 @@ export function usePullMutableAtomFamilyMember<
|
|
|
17
17
|
const store = React.useContext(StoreContext)
|
|
18
18
|
const token = findInStore(store, familyToken, key)
|
|
19
19
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
20
|
-
RTC.pullMutableAtomFamilyMember(
|
|
20
|
+
RTC.pullMutableAtomFamilyMember(store, socket, token),
|
|
21
21
|
)
|
|
22
22
|
return useO(token)
|
|
23
23
|
}
|
|
@@ -15,7 +15,7 @@ export function usePullSelectorFamilyMember<
|
|
|
15
15
|
const store = React.useContext(StoreContext)
|
|
16
16
|
const token = findInStore(store, familyToken, key)
|
|
17
17
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
18
|
-
RTC.pullSelectorFamilyMember(
|
|
18
|
+
RTC.pullSelectorFamilyMember(store, socket, token),
|
|
19
19
|
)
|
|
20
20
|
return useO(token)
|
|
21
21
|
}
|
|
@@ -12,7 +12,7 @@ export function usePullSelector<J extends Json.Serializable>(
|
|
|
12
12
|
): J {
|
|
13
13
|
const store = React.useContext(StoreContext)
|
|
14
14
|
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
15
|
-
RTC.pullSelector(
|
|
15
|
+
RTC.pullSelector(store, socket, token),
|
|
16
16
|
)
|
|
17
17
|
return useO(token)
|
|
18
18
|
}
|
|
@@ -11,7 +11,7 @@ export function usePush<J extends Json.Serializable>(
|
|
|
11
11
|
): <New extends J>(next: New | ((old: J) => New)) => void {
|
|
12
12
|
const store = React.useContext(StoreContext)
|
|
13
13
|
useRealtimeService(`push:${token.key}`, (socket) =>
|
|
14
|
-
RTC.pushState(
|
|
14
|
+
RTC.pushState(store, socket, token),
|
|
15
15
|
)
|
|
16
16
|
return useI(token)
|
|
17
17
|
}
|
|
@@ -13,7 +13,7 @@ export function useServerAction<F extends Func>(
|
|
|
13
13
|
const store = React.useContext(StoreContext)
|
|
14
14
|
|
|
15
15
|
useRealtimeService(`tx:${token.key}`, (socket) =>
|
|
16
|
-
RTC.serverAction(
|
|
16
|
+
RTC.serverAction(store, socket, token),
|
|
17
17
|
)
|
|
18
|
-
return actUponStore(token, arbitrary()
|
|
18
|
+
return actUponStore(store, token, arbitrary())
|
|
19
19
|
}
|
|
@@ -8,6 +8,6 @@ import { useRealtimeService } from "./use-realtime-service"
|
|
|
8
8
|
export function useSyncContinuity(token: ContinuityToken): void {
|
|
9
9
|
const store = React.useContext(StoreContext)
|
|
10
10
|
useRealtimeService(`tx-sync:${token.key}`, (socket) => {
|
|
11
|
-
return syncContinuity(
|
|
11
|
+
return syncContinuity(store, socket, token)
|
|
12
12
|
})
|
|
13
13
|
}
|
|
@@ -3,9 +3,7 @@ import { Json, stringified, JsonIO, Canonical } from 'atom.io/json';
|
|
|
3
3
|
import { ContinuityToken, UserInRoomMeta } from 'atom.io/realtime';
|
|
4
4
|
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
5
5
|
import * as AtomIO from 'atom.io';
|
|
6
|
-
import { TransactionUpdateContent, TransactionUpdate, Hierarchy, WritableToken } from 'atom.io';
|
|
7
|
-
import * as atom_io_data from 'atom.io/data';
|
|
8
|
-
import { Loadable } from 'atom.io/data';
|
|
6
|
+
import { Loadable, TransactionUpdateContent, TransactionUpdate, Hierarchy, WritableToken } from 'atom.io';
|
|
9
7
|
import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
|
|
10
8
|
|
|
11
9
|
type ExposeRealtimeContinuity = (continuity: ContinuityToken) => () => void;
|
|
@@ -117,7 +115,7 @@ type SocketSystemHierarchy = Hierarchy<[
|
|
|
117
115
|
declare const socketAtoms: AtomIO.RegularAtomFamilyToken<Socket | null, `socket::${string}`>;
|
|
118
116
|
declare const socketIndex: AtomIO.MutableAtomToken<SetRTX<`socket::${string}`>, SetRTXJson<`socket::${string}`>>;
|
|
119
117
|
declare const userIndex: AtomIO.MutableAtomToken<SetRTX<`user::${string}`>, SetRTXJson<`user::${string}`>>;
|
|
120
|
-
declare const usersOfSockets:
|
|
118
|
+
declare const usersOfSockets: AtomIO.JoinToken<"user", `user::${string}`, "socket", `socket::${string}`, "1:1", null>;
|
|
121
119
|
|
|
122
120
|
type StateProvider = ReturnType<typeof realtimeStateProvider>;
|
|
123
121
|
declare function realtimeStateProvider({ socket, store, }: ServerConfig): <J extends Json.Serializable>(token: AtomIO.WritableToken<J>) => () => void;
|