@liveblocks/redux 0.18.4 → 0.19.0-beta0

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/index.d.ts CHANGED
@@ -1,57 +1,72 @@
1
- import { JsonObject, BaseUserMeta, User, Client } from '@liveblocks/client';
1
+ import { JsonObject, BaseUserMeta, Client, User } from '@liveblocks/client';
2
2
  import { StoreEnhancer } from 'redux';
3
3
 
4
4
  declare type Mapping<T> = {
5
5
  [K in keyof T]?: boolean;
6
6
  };
7
- declare type LiveblocksState<TState, TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = TState & {
7
+ declare type LiveblocksContext<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
8
8
  /**
9
- * Liveblocks extra state attached by the enhancer
9
+ * Other users in the room. Empty no room is currently synced
10
10
  */
11
- readonly liveblocks: {
12
- /**
13
- * Other users in the room. Empty no room is currently synced
14
- */
15
- readonly others: Array<User<TPresence, TUserMeta>>;
16
- /**
17
- * Whether or not the room storage is currently loading
18
- */
19
- readonly isStorageLoading: boolean;
20
- /**
21
- * Connection state of the room
22
- */
23
- readonly connection: "closed" | "authenticating" | "unavailable" | "failed" | "open" | "connecting";
24
- };
11
+ readonly others: Array<User<TPresence, TUserMeta>>;
12
+ /**
13
+ * Whether or not the room storage is currently loading
14
+ */
15
+ readonly isStorageLoading: boolean;
16
+ /**
17
+ * Connection state of the room
18
+ */
19
+ readonly connection: "closed" | "authenticating" | "unavailable" | "failed" | "open" | "connecting";
20
+ };
21
+ /**
22
+ * @deprecated Please rename to WithLiveblocks<...>
23
+ */
24
+ declare type LiveblocksState<TState, TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = WithLiveblocks<TState, TPresence, TUserMeta>;
25
+ /**
26
+ * Adds the `liveblocks` property to your custom Redux state.
27
+ */
28
+ declare type WithLiveblocks<TState, TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = TState & {
29
+ readonly liveblocks: LiveblocksContext<TPresence, TUserMeta>;
25
30
  };
26
31
  /**
27
32
  * Actions used to interact with Liveblocks
28
33
  */
29
34
  declare const actions: {
30
35
  /**
31
- * Enters a room and starts sync it with zustand state
36
+ * Enters a room and starts sync it with Redux state
32
37
  * @param roomId The id of the room
33
- * @param initialState The initial state of the room storage. If a key does not exist if your room storage root, initialState[key] will be used.
34
38
  */
35
39
  enterRoom: typeof enterRoom;
36
40
  /**
37
- * Leaves a room and stops sync it with zustand state.
41
+ * Leaves a room and stops sync it with Redux state.
38
42
  * @param roomId The id of the room
39
43
  */
40
44
  leaveRoom: typeof leaveRoom;
41
45
  };
42
- declare function enterRoom<T>(roomId: string, initialState?: T): {
46
+ declare function enterRoom(roomId: string): {
43
47
  type: string;
44
48
  roomId: string;
45
- initialState?: T;
46
49
  };
47
50
  declare function leaveRoom(roomId: string): {
48
51
  type: string;
49
52
  roomId: string;
50
53
  };
54
+ /**
55
+ * Redux store enhancer that will make the `liveblocks` key available on your
56
+ * Redux store.
57
+ */
58
+ declare const liveblocksEnhancer: <T>(options: {
59
+ client: Client;
60
+ storageMapping?: Mapping<T> | undefined;
61
+ presenceMapping?: Mapping<T> | undefined;
62
+ }) => StoreEnhancer;
63
+ /**
64
+ * @deprecated Renamed to `liveblocksEnhancer`.
65
+ */
51
66
  declare const enhancer: <T>(options: {
52
67
  client: Client;
53
68
  storageMapping?: Mapping<T> | undefined;
54
69
  presenceMapping?: Mapping<T> | undefined;
55
70
  }) => StoreEnhancer;
56
71
 
57
- export { LiveblocksState, Mapping, actions, enhancer };
72
+ export { LiveblocksState, Mapping, WithLiveblocks, actions, enhancer, liveblocksEnhancer };
package/dist/index.js CHANGED
@@ -143,12 +143,15 @@ var internalEnhancer = (options) => {
143
143
  }
144
144
  };
145
145
  const store = createStore(newReducer, initialState, enhancer2);
146
- function enterRoom2(roomId, storageInitialState = {}, reduxState) {
146
+ function enterRoom2(roomId) {
147
147
  if (storageRoot) {
148
148
  return;
149
149
  }
150
- room = client.enter(roomId, { initialPresence: {} });
151
- broadcastInitialPresence(room, reduxState, presenceMapping);
150
+ const initialPresence = selectFields(
151
+ store.getState(),
152
+ presenceMapping
153
+ );
154
+ room = client.enter(roomId, { initialPresence });
152
155
  unsubscribeCallbacks.push(
153
156
  room.events.connection.subscribe(() => {
154
157
  store.dispatch({
@@ -170,7 +173,7 @@ var internalEnhancer = (options) => {
170
173
  if (isPatching === false) {
171
174
  store.dispatch({
172
175
  type: ACTION_TYPES.PATCH_REDUX_STATE,
173
- state: patchPresenceState(
176
+ state: selectFields(
174
177
  room.getPresence(),
175
178
  presenceMapping
176
179
  )
@@ -187,13 +190,8 @@ var internalEnhancer = (options) => {
187
190
  for (const key in mapping) {
188
191
  const liveblocksStatePart = root.get(key);
189
192
  if (liveblocksStatePart == null) {
190
- updates[key] = storageInitialState[key];
191
- _core.patchLiveObjectKey.call(void 0,
192
- root,
193
- key,
194
- void 0,
195
- storageInitialState[key]
196
- );
193
+ updates[key] = store.getState()[key];
194
+ _core.patchLiveObjectKey.call(void 0, root, key, void 0, store.getState()[key]);
197
195
  } else {
198
196
  updates[key] = _core.lsonToJson.call(void 0, liveblocksStatePart);
199
197
  }
@@ -236,7 +234,7 @@ var internalEnhancer = (options) => {
236
234
  }
237
235
  function newDispatch(action, state) {
238
236
  if (action.type === ACTION_TYPES.ENTER) {
239
- enterRoom2(action.roomId, action.initialState, store.getState());
237
+ enterRoom2(action.roomId);
240
238
  } else if (action.type === ACTION_TYPES.LEAVE) {
241
239
  leaveRoom2(action.roomId);
242
240
  } else {
@@ -252,11 +250,10 @@ var actions = {
252
250
  enterRoom,
253
251
  leaveRoom
254
252
  };
255
- function enterRoom(roomId, initialState) {
253
+ function enterRoom(roomId) {
256
254
  return {
257
255
  type: ACTION_TYPES.ENTER,
258
- roomId,
259
- initialState
256
+ roomId
260
257
  };
261
258
  }
262
259
  function leaveRoom(roomId) {
@@ -265,22 +262,20 @@ function leaveRoom(roomId) {
265
262
  roomId
266
263
  };
267
264
  }
268
- var enhancer = internalEnhancer;
265
+ var liveblocksEnhancer = internalEnhancer;
266
+ var enhancer = liveblocksEnhancer;
269
267
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
270
268
  for (const key in mapping) {
271
269
  if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") {
272
270
  throw mappingToFunctionIsNotAllowed("value");
273
271
  }
274
272
  if (oldState[key] !== newState[key]) {
275
- _core.patchLiveObjectKey.call(void 0, root, key, oldState[key], newState[key]);
273
+ const oldVal = oldState[key];
274
+ const newVal = newState[key];
275
+ _core.patchLiveObjectKey.call(void 0, root, key, oldVal, newVal);
276
276
  }
277
277
  }
278
278
  }
279
- function broadcastInitialPresence(room, state, mapping) {
280
- for (const key in mapping) {
281
- room == null ? void 0 : room.updatePresence({ [key]: state[key] });
282
- }
283
- }
284
279
  function updatePresence(room, oldState, newState, presenceMapping) {
285
280
  for (const key in presenceMapping) {
286
281
  if (typeof newState[key] === "function") {
@@ -301,7 +296,7 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
301
296
  }
302
297
  }
303
298
  }
304
- function patchPresenceState(presence, mapping) {
299
+ function selectFields(presence, mapping) {
305
300
  const partialState = {};
306
301
  for (const key in mapping) {
307
302
  partialState[key] = presence[key];
@@ -340,4 +335,5 @@ function validateMapping(mapping, mappingType) {
340
335
 
341
336
 
342
337
 
343
- exports.actions = actions; exports.enhancer = enhancer;
338
+
339
+ exports.actions = actions; exports.enhancer = enhancer; exports.liveblocksEnhancer = liveblocksEnhancer;
package/dist/index.mjs CHANGED
@@ -3,3 +3,4 @@ import mod from "./index.js";
3
3
  export default mod;
4
4
  export const actions = mod.actions;
5
5
  export const enhancer = mod.enhancer;
6
+ export const liveblocksEnhancer = mod.liveblocksEnhancer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/redux",
3
- "version": "0.18.4",
3
+ "version": "0.19.0-beta0",
4
4
  "description": "A store enhancer to integrate Liveblocks into Redux stores.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -18,12 +18,12 @@
18
18
  "collaborative"
19
19
  ],
20
20
  "scripts": {
21
+ "dev": "tsup --watch --onSuccess ../../scripts/build.sh",
21
22
  "build": "tsup && ../../scripts/build.sh",
22
23
  "format": "eslint --fix src/ && prettier --write src/",
23
24
  "lint": "eslint src/",
24
- "test": "jest --watch --silent --verbose",
25
- "test-ci": "jest --silent --verbose",
26
- "dtslint": "dtslint --localTs node_modules/typescript/lib --expectOnly types"
25
+ "test": "jest --silent --verbose",
26
+ "test:watch": "jest --silent --verbose --watch"
27
27
  },
28
28
  "license": "Apache-2.0",
29
29
  "repository": {
@@ -32,31 +32,19 @@
32
32
  "directory": "packages/liveblocks-redux"
33
33
  },
34
34
  "dependencies": {
35
- "@liveblocks/core": "0.18.4",
36
- "@liveblocks/client": "0.18.4"
35
+ "@liveblocks/client": "0.19.0-beta0",
36
+ "@liveblocks/core": "0.19.0-beta0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "redux": "^4"
40
40
  },
41
41
  "devDependencies": {
42
- "@definitelytyped/dtslint": "^0.0.103",
42
+ "@liveblocks/eslint-config": "*",
43
+ "@liveblocks/jest-config": "*",
43
44
  "@reduxjs/toolkit": "^1.7.2",
44
45
  "@testing-library/jest-dom": "^5.16.5",
45
- "@types/jest": "^29.1.2",
46
- "@typescript-eslint/eslint-plugin": "^5.26.0",
47
- "@typescript-eslint/parser": "^5.26.0",
48
- "eslint": "^8.12.0",
49
- "eslint-plugin-import": "^2.26.0",
50
- "eslint-plugin-simple-import-sort": "^7.0.0",
51
- "jest": "^29.1.2",
52
- "jest-environment-jsdom": "^29.1.2",
53
46
  "msw": "^0.36.4",
54
- "prettier": "^2.7.1",
55
- "redux": "^4.1.2",
56
- "ts-jest": "^29.0.3",
57
- "tsup": "^6.2.2",
58
- "typescript": "^4.7.2",
59
- "whatwg-fetch": "^3.6.2"
47
+ "redux": "^4.1.2"
60
48
  },
61
49
  "sideEffects": false
62
50
  }
@@ -1 +0,0 @@
1
- db5ed9af49cb3b74907a11800c64d721bda1fd95