atom.io 0.31.0 → 0.32.0
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 +867 -101
- package/data/dist/index.js +10 -558
- 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-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +855 -127
- package/dist/index.js +1 -143
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +794 -70
- package/internal/dist/index.js +1 -2
- 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/families/find-in-store.ts +1 -6
- 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 +19 -9
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
- package/internal/src/install-into-store.ts +48 -0
- 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} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/molecule.ts +299 -0
- 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/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +2 -13
- 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 +7 -17
- 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 +1 -1
- 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/deposit.ts +10 -8
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +34 -53
- 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 +17 -37
- 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.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -81
- package/json/src/select-json-family.ts +3 -14
- package/package.json +27 -45
- package/react/dist/index.d.ts +921 -3
- 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.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- 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.d.ts +166 -12
- 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 +971 -28
- 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 +0 -1
- 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-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +23 -26
- package/realtime-testing/src/setup-realtime-test.tsx +6 -5
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +12 -2
- package/{ephemeral/src → src}/find-state.ts +35 -25
- package/src/get-state.ts +16 -0
- package/src/index.ts +77 -3
- package/src/join.ts +218 -0
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +13 -7
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -212
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/dist/chunk-ICGFFQ3H.js +0 -272
- package/ephemeral/dist/index.d.ts +0 -57
- 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/src/allocate.ts +0 -443
- package/src/molecule.ts +0 -16
|
@@ -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,9 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
|
-
import * as AtomIO from 'atom.io';
|
|
4
|
-
import { Json, Canonical } from 'atom.io/json';
|
|
5
|
-
import { Transceiver, Func } from 'atom.io/internal';
|
|
6
|
-
import { ContinuityToken } from 'atom.io/realtime';
|
|
7
3
|
|
|
8
4
|
type RealtimeReactStore = {
|
|
9
5
|
socket: Socket | null;
|
|
@@ -18,21 +14,179 @@ declare const RealtimeProvider: React.FC<{
|
|
|
18
14
|
socket: Socket | null;
|
|
19
15
|
}>;
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
type primitive = boolean | number | string | null;
|
|
18
|
+
declare namespace Json {
|
|
19
|
+
namespace Tree {
|
|
20
|
+
type Array<Element = unknown> = ReadonlyArray<Element>;
|
|
21
|
+
type Object<K extends string = string, V = unknown> = Record<K, V>;
|
|
22
|
+
type Fork = Array | Object;
|
|
23
|
+
type Leaf = primitive;
|
|
24
|
+
type Node = Fork | Leaf;
|
|
25
|
+
}
|
|
26
|
+
type Serializable = primitive | Readonly<{
|
|
27
|
+
[key: string]: Serializable;
|
|
28
|
+
}> | ReadonlyArray<Serializable>;
|
|
29
|
+
type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
30
|
+
type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
31
|
+
}
|
|
32
|
+
type stringified<J extends Json.Serializable> = J extends string ? `"${J}"` : J extends number ? `${J}` : J extends true ? `true` : J extends false ? `false` : J extends boolean ? `false` | `true` : J extends null ? `null` : string & {
|
|
33
|
+
__json?: J;
|
|
34
|
+
};
|
|
35
|
+
type Canonical = primitive | ReadonlyArray<Canonical>;
|
|
36
|
+
|
|
37
|
+
type Func = (...parameters: any[]) => any;
|
|
22
38
|
|
|
23
|
-
|
|
39
|
+
interface Transceiver<S extends Json.Serializable> {
|
|
40
|
+
do: (update: S) => number | `OUT_OF_RANGE` | null;
|
|
41
|
+
undo: (update: S) => void;
|
|
42
|
+
subscribe: (key: string, fn: (update: S) => void) => () => void;
|
|
43
|
+
cacheUpdateNumber: number;
|
|
44
|
+
getUpdateNumber: (update: S) => number;
|
|
45
|
+
}
|
|
24
46
|
|
|
25
|
-
|
|
47
|
+
type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
48
|
+
key: string;
|
|
49
|
+
type: `atom_family`;
|
|
50
|
+
__T?: T;
|
|
51
|
+
__K?: K;
|
|
52
|
+
};
|
|
53
|
+
type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = {
|
|
54
|
+
key: string;
|
|
55
|
+
type: `mutable_atom_family`;
|
|
56
|
+
__T?: T;
|
|
57
|
+
__J?: J;
|
|
58
|
+
__K?: K;
|
|
59
|
+
};
|
|
60
|
+
type AtomFamilyToken<T, K extends Canonical = Canonical> = MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamilyToken<T, K>;
|
|
26
61
|
|
|
27
|
-
|
|
62
|
+
type TransactionToken<F extends Func> = {
|
|
63
|
+
key: string;
|
|
64
|
+
type: `transaction`;
|
|
65
|
+
__F?: F;
|
|
66
|
+
};
|
|
28
67
|
|
|
29
|
-
|
|
68
|
+
type WritableSelectorFamilyToken<T, K extends Canonical> = {
|
|
69
|
+
key: string;
|
|
70
|
+
type: `selector_family`;
|
|
71
|
+
__T?: T;
|
|
72
|
+
__K?: K;
|
|
73
|
+
};
|
|
74
|
+
type ReadonlySelectorFamilyToken<T, K extends Canonical> = {
|
|
75
|
+
key: string;
|
|
76
|
+
type: `readonly_selector_family`;
|
|
77
|
+
__T?: T;
|
|
78
|
+
__K?: K;
|
|
79
|
+
};
|
|
80
|
+
type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
30
81
|
|
|
31
|
-
|
|
82
|
+
type TokenType<Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>> = Comparison extends ReadableToken<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
32
83
|
|
|
33
|
-
|
|
84
|
+
/** @public */
|
|
85
|
+
type RegularAtomToken<T, K extends Canonical = any> = {
|
|
86
|
+
/** The unique identifier of the atom. */
|
|
87
|
+
key: string;
|
|
88
|
+
/** Discriminator. */
|
|
89
|
+
type: `atom`;
|
|
90
|
+
/** Present if the atom belongs to a family. */
|
|
91
|
+
family?: FamilyMetadata<K>;
|
|
92
|
+
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
93
|
+
__T?: T;
|
|
94
|
+
};
|
|
95
|
+
/** @public */
|
|
96
|
+
type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
|
|
97
|
+
/** The unique identifier of the atom. */
|
|
98
|
+
key: string;
|
|
99
|
+
/** Discriminator. */
|
|
100
|
+
type: `mutable_atom`;
|
|
101
|
+
/** Present if the atom belongs to a family. */
|
|
102
|
+
family?: FamilyMetadata<K>;
|
|
103
|
+
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
104
|
+
__J?: J;
|
|
105
|
+
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
106
|
+
__U?: T extends Transceiver<infer Update> ? Update : never;
|
|
107
|
+
};
|
|
108
|
+
/** @public */
|
|
109
|
+
type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
|
|
110
|
+
/** @public */
|
|
111
|
+
type WritableSelectorToken<T, K extends Canonical = any> = {
|
|
112
|
+
/** The unique identifier of the selector. */
|
|
113
|
+
key: string;
|
|
114
|
+
/** Discriminator. */
|
|
115
|
+
type: `selector`;
|
|
116
|
+
/** Present if the selector belongs to a family. */
|
|
117
|
+
family?: FamilyMetadata<K>;
|
|
118
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
119
|
+
__T?: T;
|
|
120
|
+
};
|
|
121
|
+
/** @public */
|
|
122
|
+
type ReadonlySelectorToken<T, K extends Canonical = any> = {
|
|
123
|
+
/** The unique identifier of the selector. */
|
|
124
|
+
key: string;
|
|
125
|
+
/** Discriminator. */
|
|
126
|
+
type: `readonly_selector`;
|
|
127
|
+
/** Present if the selector belongs to a family. */
|
|
128
|
+
family?: FamilyMetadata<K>;
|
|
129
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
130
|
+
__T?: T;
|
|
131
|
+
};
|
|
132
|
+
/** @public */
|
|
133
|
+
type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
|
|
134
|
+
/**
|
|
135
|
+
* @public
|
|
136
|
+
* These states can be set.
|
|
137
|
+
*/
|
|
138
|
+
type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
|
|
139
|
+
/**
|
|
140
|
+
* @public
|
|
141
|
+
* These states cannot be set.
|
|
142
|
+
*/
|
|
143
|
+
type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
|
|
144
|
+
/**
|
|
145
|
+
* @public
|
|
146
|
+
* States belonging to this family cannot be set.
|
|
147
|
+
*/
|
|
148
|
+
type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
149
|
+
/**
|
|
150
|
+
* @public
|
|
151
|
+
* Identifies a state's connection to its family.
|
|
152
|
+
*/
|
|
153
|
+
type FamilyMetadata<K extends Canonical = any> = {
|
|
154
|
+
/** The family's unique key. */
|
|
155
|
+
key: string;
|
|
156
|
+
/** The family member's unique identifier, in the form of a string. */
|
|
157
|
+
subKey: stringified<K>;
|
|
158
|
+
};
|
|
34
159
|
|
|
35
|
-
declare function
|
|
160
|
+
declare function usePullAtom<J extends Json.Serializable>(token: RegularAtomToken<J>): J;
|
|
161
|
+
|
|
162
|
+
declare function usePullAtomFamilyMember<J extends Json.Serializable, K extends Canonical, Key extends K>(family: RegularAtomFamilyToken<J, K>, subKey: Key): J;
|
|
163
|
+
|
|
164
|
+
declare function usePullMutable<T extends Transceiver<any>, J extends Json.Serializable>(token: MutableAtomToken<T, J>): T;
|
|
165
|
+
|
|
166
|
+
declare function usePullMutableAtomFamilyMember<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(familyToken: MutableAtomFamilyToken<T, J, K>, key: Key): T;
|
|
167
|
+
|
|
168
|
+
declare function usePullSelector<J extends Json.Serializable>(token: SelectorToken<J>): J;
|
|
169
|
+
|
|
170
|
+
declare function usePullSelectorFamilyMember<T, K extends Canonical, Key extends K>(familyToken: SelectorFamilyToken<T, K>, key: Key): T;
|
|
171
|
+
|
|
172
|
+
declare function usePush<J extends Json.Serializable>(token: WritableToken<J>): <New extends J>(next: New | ((old: J) => New)) => void;
|
|
173
|
+
|
|
174
|
+
declare function useServerAction<F extends Func>(token: TransactionToken<F>): (...parameters: Parameters<F>) => ReturnType<F>;
|
|
175
|
+
|
|
176
|
+
type UserKey = `user::${string}`;
|
|
177
|
+
|
|
178
|
+
type PerspectiveToken<F extends AtomFamilyToken<any>> = {
|
|
179
|
+
type: `realtime_perspective`;
|
|
180
|
+
resourceAtoms: F;
|
|
181
|
+
viewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], UserKey>;
|
|
182
|
+
};
|
|
183
|
+
type ContinuityToken = {
|
|
184
|
+
readonly type: `continuity`;
|
|
185
|
+
readonly key: string;
|
|
186
|
+
readonly globals: AtomToken<any>[];
|
|
187
|
+
readonly actions: TransactionToken<any>[];
|
|
188
|
+
readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[];
|
|
189
|
+
};
|
|
36
190
|
|
|
37
191
|
declare function useSyncContinuity(token: ContinuityToken): void;
|
|
38
192
|
|
|
@@ -1,155 +1,6 @@
|
|
|
1
|
+
export { RealtimeContext, RealtimeProvider, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity } from '../../dist/chunk-354XQWHH.js';
|
|
2
|
+
import '../../dist/chunk-Z2UJW4NQ.js';
|
|
3
|
+
import '../../dist/chunk-4LWKCEW3.js';
|
|
4
|
+
import '../../dist/chunk-5F2V7S3B.js';
|
|
5
|
+
import '../../dist/chunk-GY2XQYZY.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
|
}
|