@liveblocks/react
Advanced tools
Comparing version 0.16.0 to 0.16.1
@@ -1,12 +0,6 @@ | ||
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client'; | ||
import * as React from 'react'; | ||
import { useReducer } from 'react'; | ||
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client'; | ||
function useRerender() { | ||
const [, update] = useReducer((x) => x + 1, 0); | ||
return update; | ||
} | ||
const ClientContext = React.createContext(null); | ||
const RoomContext = React.createContext(null); | ||
function LiveblocksProvider(props) { | ||
@@ -24,2 +18,9 @@ return /* @__PURE__ */ React.createElement(ClientContext.Provider, { | ||
} | ||
function useRerender() { | ||
const [, update] = useReducer((x) => x + 1, 0); | ||
return update; | ||
} | ||
const RoomContext = React.createContext(null); | ||
function RoomProvider({ | ||
@@ -40,3 +41,13 @@ id, | ||
const client = useClient(); | ||
const [room, setRoom] = React.useState(client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : void 0, | ||
defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
})); | ||
React.useEffect(() => { | ||
setRoom(client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : void 0, | ||
defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
})); | ||
return () => { | ||
@@ -46,7 +57,2 @@ client.leave(id); | ||
}, [client, id]); | ||
const room = client.getRoom(id) || client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : void 0, | ||
defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
}); | ||
return /* @__PURE__ */ React.createElement(RoomContext.Provider, { | ||
@@ -213,2 +219,2 @@ value: room | ||
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence }; | ||
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence }; |
@@ -1,4 +0,4 @@ | ||
import { Room, Presence, Others, BroadcastOptions, Json, User, LiveObject, Lson, LiveMap, LiveList, LsonObject, History, Client } from '@liveblocks/client'; | ||
import * as React from 'react'; | ||
import { Client, Room, Presence, Others, BroadcastOptions, Json, User, LiveObject, Lson, LiveMap, LiveList, LsonObject, History } from '@liveblocks/client'; | ||
export { Json, JsonObject } from '@liveblocks/client'; | ||
import * as React from 'react'; | ||
@@ -13,2 +13,8 @@ declare type LiveblocksProviderProps = { | ||
declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element; | ||
/** | ||
* Returns the Client of the nearest LiveblocksProvider above in the React | ||
* component tree. | ||
*/ | ||
declare function useClient(): Client; | ||
declare type RoomProviderProps<TStorageRoot> = { | ||
@@ -34,3 +40,4 @@ /** | ||
/** | ||
* Returns the room of the nearest RoomProvider above in the react component tree | ||
* Returns the Room of the nearest RoomProvider above in the React component | ||
* tree. | ||
*/ | ||
@@ -206,2 +213,2 @@ declare function useRoom(): Room; | ||
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence }; | ||
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence }; |
@@ -5,4 +5,4 @@ 'use strict'; | ||
var React = require('react'); | ||
var client = require('@liveblocks/client'); | ||
var React = require('react'); | ||
@@ -29,2 +29,18 @@ function _interopNamespace(e) { | ||
var ClientContext = React__namespace.createContext(null); | ||
function LiveblocksProvider(props) { | ||
return React__namespace.createElement(ClientContext.Provider, { | ||
value: props.client | ||
}, props.children); | ||
} | ||
function useClient() { | ||
var client = React__namespace.useContext(ClientContext); | ||
if (client == null) { | ||
throw new Error("LiveblocksProvider is missing from the react tree"); | ||
} | ||
return client; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -75,20 +91,3 @@ try { | ||
var ClientContext = React__namespace.createContext(null); | ||
var RoomContext = React__namespace.createContext(null); | ||
function LiveblocksProvider(props) { | ||
return React__namespace.createElement(ClientContext.Provider, { | ||
value: props.client | ||
}, props.children); | ||
} | ||
function useClient() { | ||
var client = React__namespace.useContext(ClientContext); | ||
if (client == null) { | ||
throw new Error("LiveblocksProvider is missing from the react tree"); | ||
} | ||
return client; | ||
} | ||
function RoomProvider(_ref) { | ||
@@ -111,3 +110,17 @@ var id = _ref.id, | ||
var client = useClient(); | ||
var _React$useState = React__namespace.useState(client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : undefined, | ||
defaultStorageRoot: defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
})), | ||
room = _React$useState[0], | ||
setRoom = _React$useState[1]; | ||
React__namespace.useEffect(function () { | ||
setRoom(client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : undefined, | ||
defaultStorageRoot: defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
})); | ||
return function () { | ||
@@ -117,7 +130,2 @@ client.leave(id); | ||
}, [client, id]); | ||
var room = client.getRoom(id) || client.enter(id, { | ||
defaultPresence: defaultPresence ? defaultPresence() : undefined, | ||
defaultStorageRoot: defaultStorageRoot, | ||
DO_NOT_USE_withoutConnecting: typeof window === "undefined" | ||
}); | ||
return React__namespace.createElement(RoomContext.Provider, { | ||
@@ -230,5 +238,5 @@ value: room | ||
var _React$useState = React__namespace.useState(null), | ||
root = _React$useState[0], | ||
setState = _React$useState[1]; | ||
var _React$useState2 = React__namespace.useState(null), | ||
root = _React$useState2[0], | ||
setState = _React$useState2[1]; | ||
@@ -345,2 +353,3 @@ React__namespace.useEffect(function () { | ||
exports.useBroadcastEvent = useBroadcastEvent; | ||
exports.useClient = useClient; | ||
exports.useErrorListener = useErrorListener; | ||
@@ -347,0 +356,0 @@ exports.useEventListener = useEventListener; |
{ | ||
"name": "@liveblocks/react", | ||
"version": "0.16.0", | ||
"version": "0.16.1", | ||
"description": "A set of React hooks and providers to use Liveblocks declaratively.", | ||
@@ -36,3 +36,3 @@ "main": "./lib/index.js", | ||
"peerDependencies": { | ||
"@liveblocks/client": "0.16.0", | ||
"@liveblocks/client": "0.16.1", | ||
"react": "^16.14.0 || ^17 || ^18" | ||
@@ -49,3 +49,3 @@ }, | ||
"@testing-library/jest-dom": "^5.11.9", | ||
"@testing-library/react": "^11.2.5", | ||
"@testing-library/react": "^13.1.1", | ||
"@types/jest": "^26.0.20", | ||
@@ -52,0 +52,0 @@ "@types/react": "^16.14.0", |
Sorry, the diff of this file is not supported yet
34173
949