use-everywhere 1.0.0 → 1.0.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/dist/devtools/index.cjs +436 -436
- package/dist/devtools/index.d.cts +19 -18
- package/dist/devtools/index.d.ts +19 -18
- package/dist/devtools/index.js +434 -327
- package/dist/index.cjs +665 -621
- package/dist/index.d.cts +177 -160
- package/dist/index.d.ts +177 -160
- package/dist/index.js +449 -340
- package/dist/shared-worker.cjs +12 -30
- package/dist/shared-worker.d.cts +3 -2
- package/dist/shared-worker.d.ts +3 -2
- package/dist/shared-worker.js +2 -7
- package/dist/testing.cjs +12 -30
- package/dist/testing.d.cts +3 -1
- package/dist/testing.d.ts +3 -1
- package/dist/testing.js +1 -6
- package/dist/use-peers-DtpHGzXE.js +315 -0
- package/dist/use-peers-RhIB77TV.cjs +380 -0
- package/package.json +6 -5
- package/dist/chunk-YPQ6PLD5.js +0 -259
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SharedStore, LeaderOptions, Leader, MessageMap, ReplyMap, Channel, MessageMeta, ChannelOptions, PersistAdapter, RestoreError, Peer, LeaderSnapshot, Namespace, OpenedWindow, WindowClosedError } from '@use-everywhere/core';
|
|
2
|
-
export { AskOptions, BroadcastChannelTransport, BusEvent, BusObserver, BusWire, CID_PARAM, Channel, ChannelOptions, CommonOptions, ConnectToOpenerOptions, DEFAULT_NAME, DebugOptions, HandshakeTimeoutError, IndexedDbAdapterOptions, InvalidPayload, Leader, LeaderOptions, LeaderSnapshot, LeaderStrategy, LockManagerLike, MessageEventLike, MessageMap, MessageMeta, MessagePortLike, Namespace, NoopTransport, OnInvalid, OnOptions, OpenWindowOptions, OpenedWindow, OpenerConnection, Peer, PeerKind, PersistAdapter, PersistOptions, Persisted, PostOptions, Presence, PresenceOptions, ReplyMap, RestoreError, SchemaMap, SchemaOptions, Serializer, SharedReducer, SharedReducerOptions, SharedStore, SharedStoreOptions, SharedWorkerLike, SharedWorkerTransport, SharedWorkerTransportOptions, StandardSchemaV1, StorageLike, StorageTransport, Transport, TransportKind, Version, WIRE_VERSION, WebStorageAdapterOptions, WindowClosedError, WindowEventTarget, WindowLike, connectToOpener, createChannel, createLeader, createPresence, createSharedReducer, createSharedStore, defaultTransport, enableDebug, getBusNames, getTransportKind, getWireSkew, indexedDbAdapter, isBroadcastChannelAvailable, isSharedWorkerAvailable, isStorageEventAvailable, jsonSerializer, localStorageAdapter, newer, observeBus, openWindow, sessionStorageAdapter, webStorageAdapter } from '@use-everywhere/core';
|
|
3
1
|
|
|
2
|
+
import { AskOptions, BroadcastChannelTransport, BusEvent, BusObserver, BusWire, CID_PARAM, Channel, Channel as Channel$1, ChannelOptions, ChannelOptions as ChannelOptions$1, CommonOptions, ConnectToOpenerOptions, DEFAULT_NAME, DebugOptions, HandshakeTimeoutError, IndexedDbAdapterOptions, InvalidPayload, Leader, Leader as Leader$1, LeaderOptions, LeaderOptions as LeaderOptions$1, LeaderSnapshot, LeaderSnapshot as LeaderSnapshot$1, LeaderStrategy, LockManagerLike, MessageEventLike, MessageMap, MessageMap as MessageMap$1, MessageMeta, MessageMeta as MessageMeta$1, MessagePortLike, Namespace, Namespace as Namespace$1, NoopTransport, OnInvalid, OnOptions, OpenWindowOptions, OpenedWindow, OpenedWindow as OpenedWindow$1, OpenerConnection, Peer, Peer as Peer$1, PeerKind, PersistAdapter, PersistAdapter as PersistAdapter$1, PersistOptions, Persisted, PostOptions, Presence, PresenceOptions, ReplyMap, ReplyMap as ReplyMap$1, RestoreError, RestoreError as RestoreError$1, SchemaMap, SchemaOptions, Serializer, SharedReducer, SharedReducerOptions, SharedStore, SharedStore as SharedStore$1, SharedStoreOptions, SharedWorkerLike, SharedWorkerTransport, SharedWorkerTransportOptions, StandardSchemaV1, StorageLike, StorageTransport, Transport, TransportKind, Version, WIRE_VERSION, WebStorageAdapterOptions, WindowClosedError, WindowClosedError as WindowClosedError$1, WindowEventTarget, WindowLike, connectToOpener, createChannel, createLeader, createPresence, createSharedReducer, createSharedStore, defaultTransport, enableDebug, getBusNames, getTransportKind, getWireSkew, indexedDbAdapter, isBroadcastChannelAvailable, isSharedWorkerAvailable, isStorageEventAvailable, jsonSerializer, localStorageAdapter, newer, observeBus, openWindow, sessionStorageAdapter, webStorageAdapter } from "@use-everywhere/core";
|
|
3
|
+
//#region src/use-shared-state.types.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* How far a shared value travels:
|
|
6
6
|
* - 'everywhere' — every tab, window, and worker on this origin (default)
|
|
@@ -9,12 +9,13 @@ export { AskOptions, BroadcastChannelTransport, BusEvent, BusObserver, BusWire,
|
|
|
9
9
|
*/
|
|
10
10
|
type ShareScope = 'everywhere' | 'tabs' | 'tab';
|
|
11
11
|
interface UseSharedStateOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/** Store name; keys live in a namespace per store. Default 'use-everywhere'. */
|
|
13
|
+
store?: string;
|
|
14
|
+
/** How much to share. Default 'everywhere'. */
|
|
15
|
+
scope?: ShareScope;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/use-shared-state.d.ts
|
|
18
19
|
/**
|
|
19
20
|
* Like useState, but the value exists in every tab, window, and worker on
|
|
20
21
|
* this origin. Late-joining tabs hydrate to the current value; concurrent
|
|
@@ -27,13 +28,14 @@ interface UseSharedStateOptions {
|
|
|
27
28
|
* writes, drive them from a single tab (useLeaderEffect) until an op-based
|
|
28
29
|
* primitive lands.
|
|
29
30
|
*/
|
|
30
|
-
declare function useSharedState<T>(key: string, initial: T, options?: UseSharedStateOptions): [T, (next: T | ((prev: T) => T)) => void];
|
|
31
|
-
|
|
31
|
+
export declare function useSharedState<T>(key: string, initial: T, options?: UseSharedStateOptions): [T, (next: T | ((prev: T) => T)) => void];
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/use-shared-reducer.d.ts
|
|
32
34
|
interface UseSharedReducerOptions {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/** Bus name. Default 'use-everywhere'. */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** Which reducer this is, when several share a bus. Default 'default'. */
|
|
38
|
+
key?: string;
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* Like `useReducer`, but every tab, window, and worker on this origin applies
|
|
@@ -70,17 +72,18 @@ interface UseSharedReducerOptions {
|
|
|
70
72
|
* moments of the first tab — dispatches are held locally and ordered once it
|
|
71
73
|
* is. They are never lost, only pending.
|
|
72
74
|
*/
|
|
73
|
-
declare function useSharedReducer<S, A>(reducer: (state: S, action: A) => S, initial: S, options?: UseSharedReducerOptions): [S, (action: A) => void];
|
|
74
|
-
|
|
75
|
+
export declare function useSharedReducer<S, A>(reducer: (state: S, action: A) => S, initial: S, options?: UseSharedReducerOptions): [S, (action: A) => void];
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/use-shared-selector.d.ts
|
|
75
78
|
interface UseSharedSelectorOptions extends UseSharedStateOptions {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Whether two selected values count as the same. Default `Object.is`.
|
|
81
|
+
*
|
|
82
|
+
* A selector returning an object or array builds a new one every time it
|
|
83
|
+
* runs, so `Object.is` never matches and the component re-renders on every
|
|
84
|
+
* write to the store. Pass a shallow comparison for those.
|
|
85
|
+
*/
|
|
86
|
+
equal?: (a: unknown, b: unknown) => boolean;
|
|
84
87
|
}
|
|
85
88
|
/**
|
|
86
89
|
* Read a derived value from a shared store, re-rendering only when it changes.
|
|
@@ -111,42 +114,45 @@ interface UseSharedSelectorOptions extends UseSharedStateOptions {
|
|
|
111
114
|
* selector runs against `{}`, and its result is what the server-rendered markup
|
|
112
115
|
* shows.
|
|
113
116
|
*/
|
|
114
|
-
declare function useSharedSelector<S extends Record<string, unknown>, T>(selector: (state: S) => T, options?: UseSharedSelectorOptions): T;
|
|
117
|
+
export declare function useSharedSelector<S extends Record<string, unknown>, T>(selector: (state: S) => T, options?: UseSharedSelectorOptions): T;
|
|
115
118
|
/** Shallow equality over an object or array, for selectors that build one. */
|
|
116
|
-
declare function shallowEqual(a: unknown, b: unknown): boolean;
|
|
117
|
-
|
|
119
|
+
export declare function shallowEqual(a: unknown, b: unknown): boolean;
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/registry.types.d.ts
|
|
118
122
|
/** Registry stores hold arbitrary keys — shape is decided by the hooks using them. */
|
|
119
|
-
type AnyStore = SharedStore<Record<string, unknown>>;
|
|
120
|
-
|
|
123
|
+
type AnyStore = SharedStore$1<Record<string, unknown>>;
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/registry.d.ts
|
|
121
126
|
/** Imperative access to the store behind useSharedState (patch logs, non-React code). */
|
|
122
|
-
declare function getSharedStore(name?: string, scope?: ShareScope): AnyStore;
|
|
127
|
+
export declare function getSharedStore(name?: string, scope?: ShareScope): AnyStore;
|
|
123
128
|
/**
|
|
124
129
|
* One Leader per name per tab. Eligibility is deliberately *not* part of the
|
|
125
130
|
* key: two Leaders on one name would share a bus and a clientId, and since a
|
|
126
131
|
* post never loops back locally, neither would ever see the other's claims.
|
|
127
132
|
* Timing options are first-wins, like every other engine here.
|
|
128
133
|
*/
|
|
129
|
-
declare function getLeader(name: string, options?: LeaderOptions): Leader;
|
|
130
|
-
|
|
134
|
+
export declare function getLeader(name: string, options?: LeaderOptions$1): Leader$1;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/use-on-message.d.ts
|
|
131
137
|
/** Get the page-wide typed channel for `name` (one instance per name). */
|
|
132
|
-
declare function useChannel<M extends MessageMap, R extends ReplyMap<M> = Record<never, never>>(name: string): Channel<M, R>;
|
|
138
|
+
export declare function useChannel<M extends MessageMap$1, R extends ReplyMap$1<M> = Record<never, never>>(name: string): Channel$1<M, R>;
|
|
133
139
|
interface UseOnMessageOptions {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Subscribe at all. Default true.
|
|
142
|
+
*
|
|
143
|
+
* `false` unsubscribes rather than filtering inside the handler, so a
|
|
144
|
+
* component that is not interested costs nothing — and the alternative,
|
|
145
|
+
* calling the hook conditionally, is not allowed.
|
|
146
|
+
*/
|
|
147
|
+
enabled?: boolean;
|
|
148
|
+
/** Unsubscribe after the first message. */
|
|
149
|
+
once?: boolean;
|
|
144
150
|
}
|
|
145
151
|
/**
|
|
146
152
|
* Subscribe to one message type. The handler is kept fresh without
|
|
147
153
|
* resubscribing, so it may close over render state.
|
|
148
154
|
*/
|
|
149
|
-
declare function useOnMessage<M extends MessageMap, R extends ReplyMap<M>, K extends keyof M & string>(channel: Channel<M, R>, type: K, handler: (payload: M[K], meta: MessageMeta) => void, options?: UseOnMessageOptions): void;
|
|
155
|
+
export declare function useOnMessage<M extends MessageMap$1, R extends ReplyMap$1<M>, K extends keyof M & string>(channel: Channel$1<M, R>, type: K, handler: (payload: M[K], meta: MessageMeta$1) => void, options?: UseOnMessageOptions): void;
|
|
150
156
|
/**
|
|
151
157
|
* Answer `ask`s of one type for as long as this component is mounted.
|
|
152
158
|
*
|
|
@@ -157,27 +163,29 @@ declare function useOnMessage<M extends MessageMap, R extends ReplyMap<M>, K ext
|
|
|
157
163
|
* One responder per type per channel — registering a second replaces the first,
|
|
158
164
|
* which is the same first-wins-then-replace rule `answer` has in core.
|
|
159
165
|
*/
|
|
160
|
-
declare function useAnswer<M extends MessageMap, R extends ReplyMap<M>, K extends keyof M & keyof R & string>(channel: Channel<M, R>, type: K, responder: (payload: M[K], meta: MessageMeta) => R[K], options?: {
|
|
161
|
-
|
|
166
|
+
export declare function useAnswer<M extends MessageMap$1, R extends ReplyMap$1<M>, K extends keyof M & keyof R & string>(channel: Channel$1<M, R>, type: K, responder: (payload: M[K], meta: MessageMeta$1) => R[K], options?: {
|
|
167
|
+
enabled?: boolean;
|
|
162
168
|
}): void;
|
|
163
169
|
/** The channel's post function (stable identity per channel). */
|
|
164
|
-
declare function useSend<M extends MessageMap, R extends ReplyMap<M>>(channel: Channel<M, R>): Channel<M, R>['post'];
|
|
170
|
+
export declare function useSend<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['post'];
|
|
165
171
|
/** The channel's ask function (stable identity per channel). */
|
|
166
|
-
declare function useAsk<M extends MessageMap, R extends ReplyMap<M>>(channel: Channel<M, R>): Channel<M, R>['ask'];
|
|
167
|
-
|
|
172
|
+
export declare function useAsk<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['ask'];
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/define-channel.types.d.ts
|
|
168
175
|
/** A channel bound to a name and message map: typed hooks with no per-call generics. */
|
|
169
|
-
interface ChannelHooks<M extends MessageMap> {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
interface ChannelHooks<M extends MessageMap$1> {
|
|
177
|
+
/** The underlying channel instance (the same one the hooks use) — for non-React code. */
|
|
178
|
+
get: () => Channel$1<M>;
|
|
179
|
+
/** The channel's post function (stable identity). */
|
|
180
|
+
useSend: () => Channel$1<M>['post'];
|
|
181
|
+
/**
|
|
182
|
+
* Subscribe to one message type. Same contract as the standalone
|
|
183
|
+
* `useOnMessage`: the handler is kept fresh without resubscribing.
|
|
184
|
+
*/
|
|
185
|
+
useOnMessage: <K extends keyof M & string>(type: K, handler: (payload: M[K], meta: MessageMeta$1) => void) => void;
|
|
179
186
|
}
|
|
180
|
-
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/define-channel.d.ts
|
|
181
189
|
/**
|
|
182
190
|
* Bind a channel name and message map once, at module level, and get fully
|
|
183
191
|
* typed hooks back. Sugar over useChannel/useOnMessage/useSend — the same
|
|
@@ -187,35 +195,37 @@ interface ChannelHooks<M extends MessageMap> {
|
|
|
187
195
|
* Options are registered here and applied when the channel is first needed, so
|
|
188
196
|
* declaring a `schema` at module scope still constructs nothing on import.
|
|
189
197
|
*/
|
|
190
|
-
declare function defineChannel<M extends MessageMap>(name: string, options?: ChannelOptions<M>): ChannelHooks<M>;
|
|
191
|
-
|
|
198
|
+
export declare function defineChannel<M extends MessageMap$1>(name: string, options?: ChannelOptions$1<M>): ChannelHooks<M>;
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/create-store-hooks.types.d.ts
|
|
192
201
|
interface CreateStoreHooksOptions {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
202
|
+
/** Restore this store from disk on first use, and write it back as it changes. */
|
|
203
|
+
persist?: PersistAdapter$1;
|
|
204
|
+
/** Persist only these keys. Default: every key that has been written. */
|
|
205
|
+
persistKeys?: string[];
|
|
206
|
+
/** Coalesce disk writes for this long. Default 100. */
|
|
207
|
+
persistDebounceMs?: number;
|
|
208
|
+
/**
|
|
209
|
+
* The version of your persisted state's shape. Bump it whenever a key changes
|
|
210
|
+
* meaning or type, and supply `migrate` to carry old data forward. Default 0,
|
|
211
|
+
* which is also what anything written before this existed reads as.
|
|
212
|
+
*/
|
|
213
|
+
persistVersion?: number;
|
|
214
|
+
/** Bring persisted state written at an older `persistVersion` up to the current one. */
|
|
215
|
+
migrate?: (state: Record<string, unknown>, from: number) => Record<string, unknown>;
|
|
216
|
+
/** Called when persisted state is refused instead of restored. Defaults to a development warning. */
|
|
217
|
+
onRestoreError?: (error: RestoreError$1) => void;
|
|
218
|
+
/** How far this store is shared. Default 'everywhere'. */
|
|
219
|
+
scope?: ShareScope;
|
|
211
220
|
}
|
|
212
221
|
/** A store bound to a name and a shape: typed hooks with no per-call generics. */
|
|
213
222
|
interface StoreHooks<S extends Record<string, unknown>> {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
223
|
+
/** The underlying store instance (the same one the hooks use) — for non-React code. */
|
|
224
|
+
store: () => AnyStore;
|
|
225
|
+
useSharedState: <K extends keyof S & string>(key: K, initial: S[K]) => [S[K], (next: S[K] | ((prev: S[K]) => S[K])) => void];
|
|
217
226
|
}
|
|
218
|
-
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/create-store-hooks.d.ts
|
|
219
229
|
/**
|
|
220
230
|
* Bind a store name — and optionally persistence — once, at module level.
|
|
221
231
|
*
|
|
@@ -230,19 +240,20 @@ interface StoreHooks<S extends Record<string, unknown>> {
|
|
|
230
240
|
* so intended usage is automatic; if it does run late it throws rather than
|
|
231
241
|
* quietly handing back a store with no persistence.
|
|
232
242
|
*/
|
|
233
|
-
declare function createStoreHooks<S extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: CreateStoreHooksOptions): StoreHooks<S>;
|
|
234
|
-
|
|
243
|
+
export declare function createStoreHooks<S extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: CreateStoreHooksOptions): StoreHooks<S>;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/use-peers.d.ts
|
|
235
246
|
interface UsePeersOptions {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
247
|
+
/** Bus name. Default 'use-everywhere'. */
|
|
248
|
+
name?: string;
|
|
249
|
+
/**
|
|
250
|
+
* Include this client in the list. Default false.
|
|
251
|
+
*
|
|
252
|
+
* The default answers "who *else* is here", which is what a presence strip
|
|
253
|
+
* asks. Turn it on for an avatar list, where leaving yourself out means every
|
|
254
|
+
* tab renders a different list of the same room.
|
|
255
|
+
*/
|
|
256
|
+
includeSelf?: boolean;
|
|
246
257
|
}
|
|
247
258
|
/**
|
|
248
259
|
* The tabs/windows/workers currently alive on this origin.
|
|
@@ -250,7 +261,7 @@ interface UsePeersOptions {
|
|
|
250
261
|
* Each peer carries whatever it published about itself as `metadata` — see
|
|
251
262
|
* {@link usePresenceMetadata} for publishing this client's.
|
|
252
263
|
*/
|
|
253
|
-
declare function usePeers(options?: UsePeersOptions): readonly Peer[];
|
|
264
|
+
export declare function usePeers(options?: UsePeersOptions): readonly Peer$1[];
|
|
254
265
|
/**
|
|
255
266
|
* This client's own id on the presence bus (matches patch origin ids).
|
|
256
267
|
*
|
|
@@ -261,8 +272,8 @@ declare function usePeers(options?: UsePeersOptions): readonly Peer[];
|
|
|
261
272
|
* React also uses for the client's hydrating render, so markup matches; the
|
|
262
273
|
* real id arrives in the commit straight after. Treat `''` as "not known yet".
|
|
263
274
|
*/
|
|
264
|
-
declare function useClientId(options?: {
|
|
265
|
-
|
|
275
|
+
export declare function useClientId(options?: {
|
|
276
|
+
name?: string;
|
|
266
277
|
}): string;
|
|
267
278
|
/**
|
|
268
279
|
* Publish what this client wants peers to know about it — a display name, a tab
|
|
@@ -279,8 +290,9 @@ declare function useClientId(options?: {
|
|
|
279
290
|
* side effect on every other tab — and a render that React throws away must not
|
|
280
291
|
* be one other tabs already saw.
|
|
281
292
|
*/
|
|
282
|
-
declare function usePresenceMetadata(metadata: unknown, options?: UsePeersOptions): void;
|
|
283
|
-
|
|
293
|
+
export declare function usePresenceMetadata(metadata: unknown, options?: UsePeersOptions): void;
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/use-hydrated.d.ts
|
|
284
296
|
/**
|
|
285
297
|
* Whether a persisted store has finished restoring.
|
|
286
298
|
*
|
|
@@ -308,27 +320,30 @@ declare function usePresenceMetadata(metadata: unknown, options?: UsePeersOption
|
|
|
308
320
|
* restored by the time the store is handed back, so there is no gap to guard
|
|
309
321
|
* and this simply flips to `true` in the commit after mount.
|
|
310
322
|
*/
|
|
311
|
-
declare function useHydrated(options?: UseSharedStateOptions): boolean;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
323
|
+
export declare function useHydrated(options?: UseSharedStateOptions): boolean;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/use-leader.types.d.ts
|
|
326
|
+
interface UseLeaderOptions extends LeaderOptions$1 {
|
|
327
|
+
/** Which bus to elect on. Defaults to the shared default name. */
|
|
328
|
+
name?: string;
|
|
316
329
|
}
|
|
317
|
-
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/use-leader.d.ts
|
|
318
332
|
/**
|
|
319
333
|
* Who currently holds the seat on this bus, and whether it is us. Exactly one
|
|
320
334
|
* tab leads; opening another does not steal it, and closing the leader hands it
|
|
321
335
|
* over at once.
|
|
322
336
|
*/
|
|
323
|
-
declare function useLeader(options?: UseLeaderOptions): LeaderSnapshot;
|
|
337
|
+
export declare function useLeader(options?: UseLeaderOptions): LeaderSnapshot$1;
|
|
324
338
|
/** Is this tab the leader? */
|
|
325
|
-
declare function useIsLeader(options?: UseLeaderOptions): boolean;
|
|
339
|
+
export declare function useIsLeader(options?: UseLeaderOptions): boolean;
|
|
326
340
|
/**
|
|
327
341
|
* Run an effect only in the tab that holds the seat, and tear it down when the
|
|
328
342
|
* seat moves. The one place to put "exactly one tab owns the socket".
|
|
329
343
|
*/
|
|
330
|
-
declare function useLeaderEffect(effect: () => void | (() => void), options?: UseLeaderOptions): void;
|
|
331
|
-
|
|
344
|
+
export declare function useLeaderEffect(effect: () => void | (() => void), options?: UseLeaderOptions): void;
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/namespace.d.ts
|
|
332
347
|
/**
|
|
333
348
|
* The React half of a namespace: the same hooks, with every bus name prefixed.
|
|
334
349
|
*
|
|
@@ -336,21 +351,21 @@ declare function useLeaderEffect(effect: () => void | (() => void), options?: Us
|
|
|
336
351
|
* `scope` still says how far a value travels, which is a different axis from
|
|
337
352
|
* which namespace it lives in.
|
|
338
353
|
*/
|
|
339
|
-
interface ReactNamespace extends Namespace {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
interface ReactNamespace extends Namespace$1 {
|
|
355
|
+
createStoreHooks<S extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: CreateStoreHooksOptions): StoreHooks<S>;
|
|
356
|
+
defineChannel<M extends MessageMap$1>(name?: string, options?: ChannelOptions$1<M>): ChannelHooks<M>;
|
|
357
|
+
getSharedStore(name?: string, scope?: UseSharedStateOptions['scope']): AnyStore;
|
|
358
|
+
useSharedState<T>(key: string, initial: T, options?: UseSharedStateOptions): [T, (next: T | ((prev: T) => T)) => void];
|
|
359
|
+
useSharedSelector<S extends Record<string, unknown>, T>(selector: (state: S) => T, options?: UseSharedSelectorOptions): T;
|
|
360
|
+
usePeers(options?: UsePeersOptions): readonly Peer$1[];
|
|
361
|
+
usePresenceMetadata(metadata: unknown, options?: UsePeersOptions): void;
|
|
362
|
+
useHydrated(options?: UseSharedStateOptions): boolean;
|
|
363
|
+
useClientId(options?: {
|
|
364
|
+
name?: string;
|
|
365
|
+
}): string;
|
|
366
|
+
useLeader(options?: UseLeaderOptions): LeaderSnapshot$1;
|
|
367
|
+
useIsLeader(options?: UseLeaderOptions): boolean;
|
|
368
|
+
useLeaderEffect(effect: () => void | (() => void), options?: UseLeaderOptions): void;
|
|
354
369
|
}
|
|
355
370
|
/**
|
|
356
371
|
* Namespaced hooks and factories, so two independently deployed apps on one
|
|
@@ -373,8 +388,9 @@ interface ReactNamespace extends Namespace {
|
|
|
373
388
|
* See the core `createNamespace` for what a namespace does and does not
|
|
374
389
|
* guarantee. In short: it prevents collision, not access.
|
|
375
390
|
*/
|
|
376
|
-
declare function createNamespace(namespace: string): ReactNamespace;
|
|
377
|
-
|
|
391
|
+
export declare function createNamespace(namespace: string): ReactNamespace;
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/use-window-result.types.d.ts
|
|
378
394
|
type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-early' | 'error';
|
|
379
395
|
/**
|
|
380
396
|
* The flow's state as a discriminated union, so `status` narrows `result` and
|
|
@@ -383,43 +399,44 @@ type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-ea
|
|
|
383
399
|
* non-null assertion at every call site.
|
|
384
400
|
*/
|
|
385
401
|
type OpenedWindowState<R> = {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
402
|
+
status: 'idle';
|
|
403
|
+
result: undefined;
|
|
404
|
+
error: undefined;
|
|
389
405
|
} | {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
406
|
+
status: 'opening';
|
|
407
|
+
result: undefined;
|
|
408
|
+
error: undefined;
|
|
393
409
|
} | {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
410
|
+
status: 'connected';
|
|
411
|
+
result: undefined;
|
|
412
|
+
error: undefined;
|
|
397
413
|
} | {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
414
|
+
status: 'done';
|
|
415
|
+
result: R;
|
|
416
|
+
error: undefined;
|
|
417
|
+
} |
|
|
402
418
|
/** The child window went away before calling finish(). */
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
419
|
+
{
|
|
420
|
+
status: 'closed-early';
|
|
421
|
+
result: undefined;
|
|
422
|
+
error: WindowClosedError$1;
|
|
423
|
+
} |
|
|
408
424
|
/** The handshake timed out, the popup was blocked, or the factory threw. */
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
425
|
+
{
|
|
426
|
+
status: 'error';
|
|
427
|
+
result: undefined;
|
|
428
|
+
error: unknown;
|
|
413
429
|
};
|
|
414
|
-
interface OpenedWindowControls<Out extends MessageMap, In extends MessageMap, R> {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
430
|
+
interface OpenedWindowControls<Out extends MessageMap$1, In extends MessageMap$1, R> {
|
|
431
|
+
/** Call from a click handler (popup blockers require a user gesture). */
|
|
432
|
+
open: () => void;
|
|
433
|
+
/** Post to the child; no-op while nothing is open. */
|
|
434
|
+
post: OpenedWindow$1<Out, In, R>['post'];
|
|
435
|
+
close: () => void;
|
|
420
436
|
}
|
|
421
|
-
type UseWindowResult<Out extends MessageMap, In extends MessageMap, R> = OpenedWindowState<R> & OpenedWindowControls<Out, In, R>;
|
|
422
|
-
|
|
437
|
+
type UseWindowResult<Out extends MessageMap$1, In extends MessageMap$1, R> = OpenedWindowState<R> & OpenedWindowControls<Out, In, R>;
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/use-window-result.d.ts
|
|
423
440
|
/**
|
|
424
441
|
* Drive an openWindow() flow from a component: the factory is called on
|
|
425
442
|
* open(), and the child window's lifecycle is folded into render state.
|
|
@@ -429,6 +446,6 @@ type UseWindowResult<Out extends MessageMap, In extends MessageMap, R> = OpenedW
|
|
|
429
446
|
* because a route changed would lose the user's in-flight transaction. Call
|
|
430
447
|
* close() if the component owns the window's lifetime.
|
|
431
448
|
*/
|
|
432
|
-
declare function useWindowResult<Out extends MessageMap, In extends MessageMap, R = unknown>(factory: () => OpenedWindow<Out, In, R>): UseWindowResult<Out, In, R>;
|
|
433
|
-
|
|
434
|
-
export { type AnyStore, type ChannelHooks, type CreateStoreHooksOptions, type OpenedWindowControls, type OpenedWindowState, type OpenedWindowStatus, type ReactNamespace, type ShareScope, type StoreHooks, type UseLeaderOptions, type UseOnMessageOptions, type UsePeersOptions, type UseSharedReducerOptions, type UseSharedSelectorOptions, type UseSharedStateOptions, type UseWindowResult,
|
|
449
|
+
export declare function useWindowResult<Out extends MessageMap$1, In extends MessageMap$1, R = unknown>(factory: () => OpenedWindow$1<Out, In, R>): UseWindowResult<Out, In, R>;
|
|
450
|
+
//#endregion
|
|
451
|
+
export { type AnyStore, type AskOptions, BroadcastChannelTransport, type BusEvent, type BusObserver, type BusWire, CID_PARAM, type Channel, type ChannelHooks, type ChannelOptions, type CommonOptions, type ConnectToOpenerOptions, type CreateStoreHooksOptions, DEFAULT_NAME, type DebugOptions, HandshakeTimeoutError, type IndexedDbAdapterOptions, type InvalidPayload, type Leader, type LeaderOptions, type LeaderSnapshot, type LeaderStrategy, type LockManagerLike, type MessageEventLike, type MessageMap, type MessageMeta, type MessagePortLike, type Namespace, NoopTransport, type OnInvalid, type OnOptions, type OpenWindowOptions, type OpenedWindow, type OpenedWindowControls, type OpenedWindowState, type OpenedWindowStatus, type OpenerConnection, type Peer, type PeerKind, type PersistAdapter, type PersistOptions, type Persisted, type PostOptions, type Presence, type PresenceOptions, type ReactNamespace, type ReplyMap, type RestoreError, type SchemaMap, type SchemaOptions, type Serializer, type ShareScope, type SharedReducer, type SharedReducerOptions, type SharedStore, type SharedStoreOptions, type SharedWorkerLike, SharedWorkerTransport, type SharedWorkerTransportOptions, type StandardSchemaV1, type StorageLike, StorageTransport, type StoreHooks, type Transport, type TransportKind, type UseLeaderOptions, type UseOnMessageOptions, type UsePeersOptions, type UseSharedReducerOptions, type UseSharedSelectorOptions, type UseSharedStateOptions, type UseWindowResult, type Version, WIRE_VERSION, type WebStorageAdapterOptions, WindowClosedError, type WindowEventTarget, type WindowLike, connectToOpener, createChannel, createLeader, createPresence, createSharedReducer, createSharedStore, defaultTransport, enableDebug, getBusNames, getTransportKind, getWireSkew, indexedDbAdapter, isBroadcastChannelAvailable, isSharedWorkerAvailable, isStorageEventAvailable, jsonSerializer, localStorageAdapter, newer, observeBus, openWindow, sessionStorageAdapter, webStorageAdapter };
|