@liveblocks/react 0.16.3 → 0.16.4-beta1

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/esm/index.js CHANGED
@@ -22,39 +22,35 @@ function useRerender() {
22
22
  }
23
23
 
24
24
  const RoomContext = React.createContext(null);
25
- function RoomProvider({
26
- id,
27
- children,
28
- defaultPresence,
29
- defaultStorageRoot
30
- }) {
25
+ function RoomProvider(props) {
26
+ const { id: roomId, defaultPresence, defaultStorageRoot } = props;
31
27
  if (process.env.NODE_ENV !== "production") {
32
- if (id == null) {
28
+ if (roomId == null) {
33
29
  throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
34
30
  }
35
- if (typeof id !== "string") {
31
+ if (typeof roomId !== "string") {
36
32
  throw new Error("RoomProvider id property should be a string.");
37
33
  }
38
34
  }
39
35
  const client = useClient();
40
- const [room, setRoom] = React.useState(() => client.enter(id, {
36
+ const [room, setRoom] = React.useState(() => client.enter(roomId, {
41
37
  defaultPresence: defaultPresence ? defaultPresence() : void 0,
42
38
  defaultStorageRoot,
43
39
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
44
40
  }));
45
41
  React.useEffect(() => {
46
- setRoom(client.enter(id, {
42
+ setRoom(client.enter(roomId, {
47
43
  defaultPresence: defaultPresence ? defaultPresence() : void 0,
48
44
  defaultStorageRoot,
49
45
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
50
46
  }));
51
47
  return () => {
52
- client.leave(id);
48
+ client.leave(roomId);
53
49
  };
54
- }, [client, id]);
50
+ }, [client, roomId]);
55
51
  return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
56
52
  value: room
57
- }, children);
53
+ }, props.children);
58
54
  }
59
55
  function useRoom() {
60
56
  const room = React.useContext(RoomContext);
package/esm/index.mjs CHANGED
@@ -22,39 +22,35 @@ function useRerender() {
22
22
  }
23
23
 
24
24
  const RoomContext = React.createContext(null);
25
- function RoomProvider({
26
- id,
27
- children,
28
- defaultPresence,
29
- defaultStorageRoot
30
- }) {
25
+ function RoomProvider(props) {
26
+ const { id: roomId, defaultPresence, defaultStorageRoot } = props;
31
27
  if (process.env.NODE_ENV !== "production") {
32
- if (id == null) {
28
+ if (roomId == null) {
33
29
  throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
34
30
  }
35
- if (typeof id !== "string") {
31
+ if (typeof roomId !== "string") {
36
32
  throw new Error("RoomProvider id property should be a string.");
37
33
  }
38
34
  }
39
35
  const client = useClient();
40
- const [room, setRoom] = React.useState(() => client.enter(id, {
36
+ const [room, setRoom] = React.useState(() => client.enter(roomId, {
41
37
  defaultPresence: defaultPresence ? defaultPresence() : void 0,
42
38
  defaultStorageRoot,
43
39
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
44
40
  }));
45
41
  React.useEffect(() => {
46
- setRoom(client.enter(id, {
42
+ setRoom(client.enter(roomId, {
47
43
  defaultPresence: defaultPresence ? defaultPresence() : void 0,
48
44
  defaultStorageRoot,
49
45
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
50
46
  }));
51
47
  return () => {
52
- client.leave(id);
48
+ client.leave(roomId);
53
49
  };
54
- }, [client, id]);
50
+ }, [client, roomId]);
55
51
  return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
56
52
  value: room
57
- }, children);
53
+ }, props.children);
58
54
  }
59
55
  function useRoom() {
60
56
  const room = React.useContext(RoomContext);
package/index.d.ts CHANGED
@@ -16,7 +16,7 @@ declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element
16
16
  */
17
17
  declare function useClient(): Client;
18
18
 
19
- declare type RoomProviderProps<TStorageRoot> = {
19
+ declare type RoomProviderProps<TStorage> = {
20
20
  /**
21
21
  * The id of the room you want to connect to
22
22
  */
@@ -26,7 +26,7 @@ declare type RoomProviderProps<TStorageRoot> = {
26
26
  * If ommited, the default presence will be an empty object
27
27
  */
28
28
  defaultPresence?: () => Presence;
29
- defaultStorageRoot?: TStorageRoot;
29
+ defaultStorageRoot?: TStorage;
30
30
  children: React.ReactNode;
31
31
  };
32
32
  /**
@@ -34,7 +34,7 @@ declare type RoomProviderProps<TStorageRoot> = {
34
34
  * When this component is unmounted, the current user leave the room.
35
35
  * That means that you can't have 2 RoomProvider with the same room id in your react tree.
36
36
  */
37
- declare function RoomProvider<TStorageRoot>({ id, children, defaultPresence, defaultStorageRoot, }: RoomProviderProps<TStorageRoot>): JSX.Element;
37
+ declare function RoomProvider<TStorage>(props: RoomProviderProps<TStorage>): JSX.Element;
38
38
  /**
39
39
  * Returns the Room of the nearest RoomProvider above in the React component
40
40
  * tree.
@@ -142,8 +142,8 @@ declare function useEventListener<TEvent extends Json>(callback: ({ connectionId
142
142
  * const user = useSelf();
143
143
  */
144
144
  declare function useSelf<TPresence extends Presence = Presence>(): User<TPresence> | null;
145
- declare function useStorage<TRoot extends Record<string, any>>(): [
146
- root: LiveObject<TRoot> | null
145
+ declare function useStorage<TStorage extends Record<string, any>>(): [
146
+ root: LiveObject<TStorage> | null
147
147
  ];
148
148
  /**
149
149
  * Returns the LiveMap associated with the provided key. If the LiveMap does not exist, a new empty LiveMap will be created.
package/index.js CHANGED
@@ -87,18 +87,17 @@ function useRerender() {
87
87
  }
88
88
 
89
89
  var RoomContext = React__namespace.createContext(null);
90
- function RoomProvider(_ref) {
91
- var id = _ref.id,
92
- children = _ref.children,
93
- defaultPresence = _ref.defaultPresence,
94
- defaultStorageRoot = _ref.defaultStorageRoot;
90
+ function RoomProvider(props) {
91
+ var roomId = props.id,
92
+ defaultPresence = props.defaultPresence,
93
+ defaultStorageRoot = props.defaultStorageRoot;
95
94
 
96
95
  if (process.env.NODE_ENV !== "production") {
97
- if (id == null) {
96
+ if (roomId == null) {
98
97
  throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
99
98
  }
100
99
 
101
- if (typeof id !== "string") {
100
+ if (typeof roomId !== "string") {
102
101
  throw new Error("RoomProvider id property should be a string.");
103
102
  }
104
103
  }
@@ -106,7 +105,7 @@ function RoomProvider(_ref) {
106
105
  var client = useClient();
107
106
 
108
107
  var _React$useState = React__namespace.useState(function () {
109
- return client.enter(id, {
108
+ return client.enter(roomId, {
110
109
  defaultPresence: defaultPresence ? defaultPresence() : undefined,
111
110
  defaultStorageRoot: defaultStorageRoot,
112
111
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
@@ -116,18 +115,18 @@ function RoomProvider(_ref) {
116
115
  setRoom = _React$useState[1];
117
116
 
118
117
  React__namespace.useEffect(function () {
119
- setRoom(client.enter(id, {
118
+ setRoom(client.enter(roomId, {
120
119
  defaultPresence: defaultPresence ? defaultPresence() : undefined,
121
120
  defaultStorageRoot: defaultStorageRoot,
122
121
  DO_NOT_USE_withoutConnecting: typeof window === "undefined"
123
122
  }));
124
123
  return function () {
125
- client.leave(id);
124
+ client.leave(roomId);
126
125
  };
127
- }, [client, id]);
126
+ }, [client, roomId]);
128
127
  return React__namespace.createElement(RoomContext.Provider, {
129
128
  value: room
130
- }, children);
129
+ }, props.children);
131
130
  }
132
131
  function useRoom() {
133
132
  var room = React__namespace.useContext(RoomContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react",
3
- "version": "0.16.3",
3
+ "version": "0.16.4-beta1",
4
4
  "description": "A set of React hooks and providers to use Liveblocks declaratively.",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -29,11 +29,13 @@
29
29
  "scripts": {
30
30
  "build": "rollup -c && cp ./package.json ./README.md ./lib",
31
31
  "start": "rollup -c -w",
32
- "test": "jest --watch"
32
+ "lint": "eslint src/",
33
+ "test": "jest --watch",
34
+ "test-ci": "jest"
33
35
  },
34
36
  "license": "Apache-2.0",
35
37
  "peerDependencies": {
36
- "@liveblocks/client": "0.16.3",
38
+ "@liveblocks/client": "0.16.4-beta1",
37
39
  "react": "^16.14.0 || ^17 || ^18"
38
40
  },
39
41
  "devDependencies": {