@liveblocks/react 0.18.1 → 0.18.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/index.d.ts +0 -21
- package/index.js +32 -45
- package/package.json +2 -2
- package/.built-by-link-script +0 -1
package/index.d.ts
CHANGED
|
@@ -318,16 +318,6 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
318
318
|
* );
|
|
319
319
|
*/
|
|
320
320
|
useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
|
|
321
|
-
/**
|
|
322
|
-
* Given a connection ID (as obtained by using `useOthersConnectionIds`), you can
|
|
323
|
-
* call this selector deep down in your component stack to only have the
|
|
324
|
-
* component re-render if properties for this particular user change.
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* // Returns full user and re-renders whenever anything on the user changes
|
|
328
|
-
* const secondUser = useOther(2);
|
|
329
|
-
*/
|
|
330
|
-
useOther(connectionId: number): User<TPresence, TUserMeta>;
|
|
331
321
|
/**
|
|
332
322
|
* Given a connection ID (as obtained by using `useOthersConnectionIds`), you
|
|
333
323
|
* can call this selector deep down in your component stack to only have the
|
|
@@ -635,17 +625,6 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
635
625
|
* );
|
|
636
626
|
*/
|
|
637
627
|
useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
|
|
638
|
-
/**
|
|
639
|
-
* Given a connection ID (as obtained by using `useOthersConnectionIds`),
|
|
640
|
-
* you can call this selector deep down in your component stack to only
|
|
641
|
-
* have the component re-render if properties for this particular user
|
|
642
|
-
* change.
|
|
643
|
-
*
|
|
644
|
-
* @example
|
|
645
|
-
* // Returns full user and re-renders whenever anything on the user changes
|
|
646
|
-
* const secondUser = useOther(2);
|
|
647
|
-
*/
|
|
648
|
-
useOther(connectionId: number): User<TPresence, TUserMeta>;
|
|
649
628
|
/**
|
|
650
629
|
* Given a connection ID (as obtained by using `useOthersConnectionIds`),
|
|
651
630
|
* you can call this selector deep down in your component stack to only
|
package/index.js
CHANGED
|
@@ -164,50 +164,41 @@ function createRoomContext(client) {
|
|
|
164
164
|
);
|
|
165
165
|
return useOthers(wrappedSelector, wrappedIsEqual);
|
|
166
166
|
}
|
|
167
|
-
const
|
|
167
|
+
const NOT_FOUND = Symbol();
|
|
168
168
|
function useOther(connectionId, selector, isEqual) {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
[connectionId]
|
|
175
|
-
);
|
|
176
|
-
const other = _useOthers(selector2, _client.shallow);
|
|
177
|
-
if (other === void 0) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
`No such other user with connection id ${connectionId} exists`
|
|
169
|
+
const lastKnownValue = React2.useRef(NOT_FOUND);
|
|
170
|
+
const wrappedSelector = React2.useCallback(
|
|
171
|
+
(others) => {
|
|
172
|
+
const other2 = others.find(
|
|
173
|
+
(other3) => other3.connectionId === connectionId
|
|
180
174
|
);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
175
|
+
if (other2 !== void 0) {
|
|
176
|
+
const value = selector(other2);
|
|
177
|
+
lastKnownValue.current = value;
|
|
178
|
+
return value;
|
|
179
|
+
} else {
|
|
180
|
+
return lastKnownValue.current;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
[connectionId, selector]
|
|
184
|
+
);
|
|
185
|
+
const wrappedIsEqual = React2.useCallback(
|
|
186
|
+
(prev, curr) => {
|
|
187
|
+
if (prev === NOT_FOUND || curr === NOT_FOUND) {
|
|
188
|
+
return prev === curr;
|
|
189
|
+
}
|
|
190
|
+
const eq = isEqual != null ? isEqual : Object.is;
|
|
191
|
+
return eq(prev, curr);
|
|
192
|
+
},
|
|
193
|
+
[isEqual]
|
|
194
|
+
);
|
|
195
|
+
const other = useOthers(wrappedSelector, wrappedIsEqual);
|
|
196
|
+
if (other === NOT_FOUND) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`No such other user with connection id ${connectionId} exists`
|
|
202
199
|
);
|
|
203
|
-
const other = _useOthers(wrappedSelector, wrappedIsEqual);
|
|
204
|
-
if (other === sentinel) {
|
|
205
|
-
throw new Error(
|
|
206
|
-
`No such other user with connection id ${connectionId} exists`
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
return other;
|
|
210
200
|
}
|
|
201
|
+
return other;
|
|
211
202
|
}
|
|
212
203
|
function useBroadcastEvent() {
|
|
213
204
|
const room = useRoom();
|
|
@@ -443,11 +434,7 @@ function createRoomContext(client) {
|
|
|
443
434
|
}
|
|
444
435
|
function useOtherSuspense(connectionId, selector, isEqual) {
|
|
445
436
|
useSuspendUntilPresenceLoaded();
|
|
446
|
-
return useOther(
|
|
447
|
-
connectionId,
|
|
448
|
-
selector,
|
|
449
|
-
isEqual
|
|
450
|
-
);
|
|
437
|
+
return useOther(connectionId, selector, isEqual);
|
|
451
438
|
}
|
|
452
439
|
function useLegacyKeySuspense(key) {
|
|
453
440
|
useSuspendUntilStorageLoaded();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
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.
|
|
30
|
+
"@liveblocks/client": "0.18.2",
|
|
31
31
|
"react": "^16.14.0 || ^17 || ^18"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
package/.built-by-link-script
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ab4dc80c03188cfbc87c124cad9c824347a785b0
|