@liveblocks/react 0.18.0-beta3 → 0.18.0-beta4
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/.built-by-link-script +1 -1
- package/index.d.ts +26 -31
- package/index.js +21 -18
- package/package.json +2 -2
package/.built-by-link-script
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
ff5604e48f99b968e9dae639dfc5bace0e57087c
|
package/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ declare type RoomProviderProps<TPresence extends JsonObject, TStorage extends Ls
|
|
|
39
39
|
*/
|
|
40
40
|
declare type OmitFirstArg<F> = F extends (first: any, ...rest: infer A) => infer R ? (...args: A) => R : never;
|
|
41
41
|
declare type MutationContext<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta> = {
|
|
42
|
-
|
|
42
|
+
storage: LiveObject<TStorage>;
|
|
43
43
|
self: User<TPresence, TUserMeta>;
|
|
44
44
|
others: Others<TPresence, TUserMeta>;
|
|
45
45
|
setMyPresence: (patch: Partial<TPresence>, options?: {
|
|
@@ -296,10 +296,10 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
296
296
|
* for each user in the room, e.g. cursors.
|
|
297
297
|
*
|
|
298
298
|
* @example
|
|
299
|
-
* const ids =
|
|
299
|
+
* const ids = useOthersConnectionIds();
|
|
300
300
|
* // [2, 4, 7]
|
|
301
301
|
*/
|
|
302
|
-
|
|
302
|
+
useOthersConnectionIds(): readonly number[];
|
|
303
303
|
/**
|
|
304
304
|
* Related to useOthers(), but optimized for selecting only "subsets" of
|
|
305
305
|
* others. This is useful for performance reasons in particular, because
|
|
@@ -307,11 +307,11 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
307
307
|
* re-renders that will be triggered.
|
|
308
308
|
*
|
|
309
309
|
* @example
|
|
310
|
-
* const avatars =
|
|
310
|
+
* const avatars = useOthersMapped(user => user.info.avatar);
|
|
311
311
|
* // ^^^^^^^
|
|
312
312
|
* // { connectionId: number; data: string }[]
|
|
313
313
|
*
|
|
314
|
-
* The selector function you pass to
|
|
314
|
+
* The selector function you pass to useOthersMapped() is called an "item
|
|
315
315
|
* selector", and operates on a single user at a time. If you provide an
|
|
316
316
|
* (optional) "item comparison" function, it will be used to compare each
|
|
317
317
|
* item pairwise.
|
|
@@ -319,17 +319,14 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
319
319
|
* For example, to select multiple properties:
|
|
320
320
|
*
|
|
321
321
|
* @example
|
|
322
|
-
* const avatarsAndCursors =
|
|
322
|
+
* const avatarsAndCursors = useOthersMapped(
|
|
323
323
|
* user => [u.info.avatar, u.presence.cursor],
|
|
324
324
|
* shallow, // 👈
|
|
325
325
|
* );
|
|
326
326
|
*/
|
|
327
|
-
|
|
328
|
-
readonly connectionId: number;
|
|
329
|
-
readonly data: T;
|
|
330
|
-
}[];
|
|
327
|
+
useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
|
|
331
328
|
/**
|
|
332
|
-
* Given a connection ID (as obtained by using `
|
|
329
|
+
* Given a connection ID (as obtained by using `useOthersConnectionIds`), you can
|
|
333
330
|
* call this selector deep down in your component stack to only have the
|
|
334
331
|
* component re-render if properties for this particular user change.
|
|
335
332
|
*
|
|
@@ -339,8 +336,8 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
339
336
|
*/
|
|
340
337
|
useOther(connectionId: number): User<TPresence, TUserMeta>;
|
|
341
338
|
/**
|
|
342
|
-
* Given a connection ID (as obtained by using `
|
|
343
|
-
* call this selector deep down in your component stack to only have the
|
|
339
|
+
* Given a connection ID (as obtained by using `useOthersConnectionIds`), you
|
|
340
|
+
* can call this selector deep down in your component stack to only have the
|
|
344
341
|
* component re-render if properties for this particular user change.
|
|
345
342
|
*
|
|
346
343
|
* @example
|
|
@@ -363,7 +360,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
363
360
|
addToHistory: boolean;
|
|
364
361
|
}) => void;
|
|
365
362
|
/**
|
|
366
|
-
* Create a callback function that
|
|
363
|
+
* Create a callback function that lets you mutate Liveblocks state.
|
|
367
364
|
*
|
|
368
365
|
* The first argument that gets passed into your callback will be a "mutation
|
|
369
366
|
* context", which exposes the following:
|
|
@@ -623,10 +620,10 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
623
620
|
* for each user in the room, e.g. cursors.
|
|
624
621
|
*
|
|
625
622
|
* @example
|
|
626
|
-
* const ids =
|
|
623
|
+
* const ids = useOthersConnectionIds();
|
|
627
624
|
* // [2, 4, 7]
|
|
628
625
|
*/
|
|
629
|
-
|
|
626
|
+
useOthersConnectionIds(): readonly number[];
|
|
630
627
|
/**
|
|
631
628
|
* Related to useOthers(), but optimized for selecting only "subsets" of
|
|
632
629
|
* others. This is useful for performance reasons in particular, because
|
|
@@ -634,11 +631,11 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
634
631
|
* re-renders that will be triggered.
|
|
635
632
|
*
|
|
636
633
|
* @example
|
|
637
|
-
* const avatars =
|
|
634
|
+
* const avatars = useOthersMapped(user => user.info.avatar);
|
|
638
635
|
* // ^^^^^^^
|
|
639
636
|
* // { connectionId: number; data: string }[]
|
|
640
637
|
*
|
|
641
|
-
* The selector function you pass to
|
|
638
|
+
* The selector function you pass to useOthersMapped() is called an "item
|
|
642
639
|
* selector", and operates on a single user at a time. If you provide an
|
|
643
640
|
* (optional) "item comparison" function, it will be used to compare each
|
|
644
641
|
* item pairwise.
|
|
@@ -646,19 +643,17 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
646
643
|
* For example, to select multiple properties:
|
|
647
644
|
*
|
|
648
645
|
* @example
|
|
649
|
-
* const avatarsAndCursors =
|
|
646
|
+
* const avatarsAndCursors = useOthersMapped(
|
|
650
647
|
* user => [u.info.avatar, u.presence.cursor],
|
|
651
648
|
* shallow, // 👈
|
|
652
649
|
* );
|
|
653
650
|
*/
|
|
654
|
-
|
|
655
|
-
readonly connectionId: number;
|
|
656
|
-
readonly data: T;
|
|
657
|
-
}[];
|
|
651
|
+
useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
|
|
658
652
|
/**
|
|
659
|
-
* Given a connection ID (as obtained by using `
|
|
660
|
-
* can call this selector deep down in your component stack to only
|
|
661
|
-
* the component re-render if properties for this particular user
|
|
653
|
+
* Given a connection ID (as obtained by using `useOthersConnectionIds`),
|
|
654
|
+
* you can call this selector deep down in your component stack to only
|
|
655
|
+
* have the component re-render if properties for this particular user
|
|
656
|
+
* change.
|
|
662
657
|
*
|
|
663
658
|
* @example
|
|
664
659
|
* // Returns full user and re-renders whenever anything on the user changes
|
|
@@ -666,9 +661,10 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
666
661
|
*/
|
|
667
662
|
useOther(connectionId: number): User<TPresence, TUserMeta>;
|
|
668
663
|
/**
|
|
669
|
-
* Given a connection ID (as obtained by using `
|
|
670
|
-
* can call this selector deep down in your component stack to only
|
|
671
|
-
* the component re-render if properties for this particular user
|
|
664
|
+
* Given a connection ID (as obtained by using `useOthersConnectionIds`),
|
|
665
|
+
* you can call this selector deep down in your component stack to only
|
|
666
|
+
* have the component re-render if properties for this particular user
|
|
667
|
+
* change.
|
|
672
668
|
*
|
|
673
669
|
* @example
|
|
674
670
|
* // Returns only the selected values re-renders whenever that selection changes)
|
|
@@ -690,8 +686,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
690
686
|
addToHistory: boolean;
|
|
691
687
|
}) => void;
|
|
692
688
|
/**
|
|
693
|
-
* Create a callback function that
|
|
694
|
-
* state.
|
|
689
|
+
* Create a callback function that lets you mutate Liveblocks state.
|
|
695
690
|
*
|
|
696
691
|
* The first argument that gets passed into your callback will be
|
|
697
692
|
* a "mutation context", which exposes the following:
|
package/index.js
CHANGED
|
@@ -43,12 +43,12 @@ function getEmptyOthers() {
|
|
|
43
43
|
function makeMutationContext(room) {
|
|
44
44
|
const errmsg = "This mutation cannot be used until connected to the Liveblocks room";
|
|
45
45
|
return {
|
|
46
|
-
get
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
46
|
+
get storage() {
|
|
47
|
+
const mutableRoot = room.getStorageSnapshot();
|
|
48
|
+
if (mutableRoot === null) {
|
|
49
49
|
throw new Error(errmsg);
|
|
50
50
|
}
|
|
51
|
-
return
|
|
51
|
+
return mutableRoot;
|
|
52
52
|
},
|
|
53
53
|
get self() {
|
|
54
54
|
const self = room.getSelf();
|
|
@@ -142,15 +142,14 @@ function createRoomContext(client) {
|
|
|
142
142
|
isEqual
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function useOthersConnectionIds() {
|
|
146
146
|
return useOthers(connectionIdSelector, _client.shallow);
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function useOthersMapped(itemSelector, itemIsEqual) {
|
|
149
149
|
const wrappedSelector = React2.useCallback(
|
|
150
|
-
(others) => others.map(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})),
|
|
150
|
+
(others) => others.map(
|
|
151
|
+
(other) => [other.connectionId, itemSelector(other)]
|
|
152
|
+
),
|
|
154
153
|
[itemSelector]
|
|
155
154
|
);
|
|
156
155
|
const wrappedIsEqual = React2.useCallback(
|
|
@@ -158,7 +157,7 @@ function createRoomContext(client) {
|
|
|
158
157
|
const eq = itemIsEqual != null ? itemIsEqual : Object.is;
|
|
159
158
|
return a.length === b.length && a.every((atuple, index) => {
|
|
160
159
|
const btuple = b[index];
|
|
161
|
-
return atuple
|
|
160
|
+
return atuple[0] === btuple[0] && eq(atuple[1], btuple[1]);
|
|
162
161
|
});
|
|
163
162
|
},
|
|
164
163
|
[itemIsEqual]
|
|
@@ -379,7 +378,7 @@ function createRoomContext(client) {
|
|
|
379
378
|
function ensureNotServerSide() {
|
|
380
379
|
if (typeof window === "undefined") {
|
|
381
380
|
throw new Error(
|
|
382
|
-
"You cannot
|
|
381
|
+
"You cannot use the Suspense version of this hook on the server side. Make sure to only call them on the client side.\nFor tips, see https://liveblocks.io/docs/api-reference/liveblocks-react#suspense-avoid-ssr"
|
|
383
382
|
);
|
|
384
383
|
}
|
|
385
384
|
}
|
|
@@ -435,9 +434,13 @@ function createRoomContext(client) {
|
|
|
435
434
|
isEqual
|
|
436
435
|
);
|
|
437
436
|
}
|
|
438
|
-
function
|
|
437
|
+
function useOthersConnectionIdsSuspense() {
|
|
438
|
+
useSuspendUntilPresenceLoaded();
|
|
439
|
+
return useOthersConnectionIds();
|
|
440
|
+
}
|
|
441
|
+
function useOthersMappedSuspense(itemSelector, itemIsEqual) {
|
|
439
442
|
useSuspendUntilPresenceLoaded();
|
|
440
|
-
return
|
|
443
|
+
return useOthersMapped(itemSelector, itemIsEqual);
|
|
441
444
|
}
|
|
442
445
|
function useOtherSuspense(connectionId, selector, isEqual) {
|
|
443
446
|
useSuspendUntilPresenceLoaded();
|
|
@@ -473,8 +476,8 @@ function createRoomContext(client) {
|
|
|
473
476
|
useMyPresence,
|
|
474
477
|
useUpdateMyPresence,
|
|
475
478
|
useOthers,
|
|
476
|
-
|
|
477
|
-
|
|
479
|
+
useOthersMapped,
|
|
480
|
+
useOthersConnectionIds,
|
|
478
481
|
useOther,
|
|
479
482
|
useMutation,
|
|
480
483
|
suspense: {
|
|
@@ -499,8 +502,8 @@ function createRoomContext(client) {
|
|
|
499
502
|
useMyPresence,
|
|
500
503
|
useUpdateMyPresence,
|
|
501
504
|
useOthers: useOthersSuspense,
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
useOthersMapped: useOthersMappedSuspense,
|
|
506
|
+
useOthersConnectionIds: useOthersConnectionIdsSuspense,
|
|
504
507
|
useOther: useOtherSuspense,
|
|
505
508
|
useMutation
|
|
506
509
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.18.0-
|
|
3
|
+
"version": "0.18.0-beta4",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"use-sync-external-store": "^1.2.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@liveblocks/client": "0.18.0-
|
|
30
|
+
"@liveblocks/client": "0.18.0-beta4",
|
|
31
31
|
"react": "^16.14.0 || ^17 || ^18"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|