@liveblocks/redux 1.4.8-test1 → 1.5.0-test2

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.mts CHANGED
@@ -56,8 +56,7 @@ declare const actions: {
56
56
  */
57
57
  enterRoom: typeof enterRoom;
58
58
  /**
59
- * Leaves a room and stops sync it with Redux state.
60
- * @param roomId The id of the room
59
+ * Leaves the currently entered room and stops sync it with Redux state.
61
60
  */
62
61
  leaveRoom: typeof leaveRoom;
63
62
  };
@@ -65,9 +64,8 @@ declare function enterRoom(roomId: string): {
65
64
  type: string;
66
65
  roomId: string;
67
66
  };
68
- declare function leaveRoom(roomId: string): {
67
+ declare function leaveRoom(): {
69
68
  type: string;
70
- roomId: string;
71
69
  };
72
70
  /**
73
71
  * Redux store enhancer that will make the `liveblocks` key available on your
package/dist/index.d.ts CHANGED
@@ -56,8 +56,7 @@ declare const actions: {
56
56
  */
57
57
  enterRoom: typeof enterRoom;
58
58
  /**
59
- * Leaves a room and stops sync it with Redux state.
60
- * @param roomId The id of the room
59
+ * Leaves the currently entered room and stops sync it with Redux state.
61
60
  */
62
61
  leaveRoom: typeof leaveRoom;
63
62
  };
@@ -65,9 +64,8 @@ declare function enterRoom(roomId: string): {
65
64
  type: string;
66
65
  roomId: string;
67
66
  };
68
- declare function leaveRoom(roomId: string): {
67
+ declare function leaveRoom(): {
69
68
  type: string;
70
- roomId: string;
71
69
  };
72
70
  /**
73
71
  * Redux store enhancer that will make the `liveblocks` key available on your
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
2
 
3
3
 
4
4
 
@@ -34,7 +34,7 @@ function mappingToFunctionIsNotAllowed(key) {
34
34
 
35
35
  // src/version.ts
36
36
  var PKG_NAME = "@liveblocks/redux";
37
- var PKG_VERSION = "1.4.8-test1";
37
+ var PKG_VERSION = "1.5.0-test2";
38
38
  var PKG_FORMAT = "cjs";
39
39
 
40
40
  // src/index.ts
@@ -66,10 +66,12 @@ var internalEnhancer = (options) => {
66
66
  }
67
67
  return (createStore) => {
68
68
  return (reducer, initialState, enhancer2) => {
69
- let room = null;
69
+ let maybeRoom = null;
70
70
  let isPatching = false;
71
71
  let storageRoot = null;
72
72
  let unsubscribeCallbacks = [];
73
+ let lastRoomId = null;
74
+ let lastLeaveFn = null;
73
75
  const newReducer = (state, action) => {
74
76
  switch (action.type) {
75
77
  case ACTION_TYPES.PATCH_REDUX_STATE:
@@ -115,10 +117,15 @@ var internalEnhancer = (options) => {
115
117
  }
116
118
  default: {
117
119
  const newState = reducer(state, action);
118
- if (room) {
120
+ if (maybeRoom) {
119
121
  isPatching = true;
120
- updatePresence(room, state, newState, presenceMapping);
121
- room.batch(() => {
122
+ updatePresence(
123
+ maybeRoom,
124
+ state,
125
+ newState,
126
+ presenceMapping
127
+ );
128
+ maybeRoom.batch(() => {
122
129
  if (storageRoot) {
123
130
  patchLiveblocksStorage(
124
131
  storageRoot,
@@ -146,15 +153,22 @@ var internalEnhancer = (options) => {
146
153
  }
147
154
  };
148
155
  const store = createStore(newReducer, initialState, enhancer2);
149
- function enterRoom2(roomId) {
150
- if (storageRoot) {
156
+ function enterRoom2(newRoomId) {
157
+ if (lastRoomId === newRoomId) {
151
158
  return;
152
159
  }
160
+ lastRoomId = newRoomId;
161
+ if (lastLeaveFn !== null) {
162
+ lastLeaveFn();
163
+ }
153
164
  const initialPresence = selectFields(
154
165
  store.getState(),
155
166
  presenceMapping
156
167
  );
157
- room = client.enter(roomId, { initialPresence });
168
+ const { room, leave } = client.enterRoom(newRoomId, {
169
+ initialPresence
170
+ });
171
+ maybeRoom = room;
158
172
  unsubscribeCallbacks.push(
159
173
  room.events.connection.subscribe(() => {
160
174
  store.dispatch({
@@ -187,7 +201,7 @@ var internalEnhancer = (options) => {
187
201
  });
188
202
  void room.getStorage().then(({ root }) => {
189
203
  const updates = {};
190
- room.batch(() => {
204
+ maybeRoom.batch(() => {
191
205
  for (const key in mapping) {
192
206
  const liveblocksStatePart = root.get(key);
193
207
  if (liveblocksStatePart == null) {
@@ -204,7 +218,7 @@ var internalEnhancer = (options) => {
204
218
  });
205
219
  storageRoot = root;
206
220
  unsubscribeCallbacks.push(
207
- room.subscribe(
221
+ maybeRoom.subscribe(
208
222
  root,
209
223
  (updates2) => {
210
224
  if (isPatching === false) {
@@ -222,22 +236,27 @@ var internalEnhancer = (options) => {
222
236
  )
223
237
  );
224
238
  });
239
+ lastLeaveFn = () => {
240
+ for (const unsubscribe of unsubscribeCallbacks) {
241
+ unsubscribe();
242
+ }
243
+ unsubscribeCallbacks = [];
244
+ storageRoot = null;
245
+ maybeRoom = null;
246
+ isPatching = false;
247
+ lastRoomId = null;
248
+ lastLeaveFn = null;
249
+ leave();
250
+ };
225
251
  }
226
- function leaveRoom2(roomId) {
227
- for (const unsubscribe of unsubscribeCallbacks) {
228
- unsubscribe();
229
- }
230
- storageRoot = null;
231
- room = null;
232
- isPatching = false;
233
- unsubscribeCallbacks = [];
234
- client.leave(roomId);
252
+ function leaveRoom2() {
253
+ _optionalChain([lastLeaveFn, 'optionalCall', _ => _()]);
235
254
  }
236
255
  function newDispatch(action) {
237
256
  if (action.type === ACTION_TYPES.ENTER) {
238
257
  enterRoom2(action.roomId);
239
258
  } else if (action.type === ACTION_TYPES.LEAVE) {
240
- leaveRoom2(action.roomId);
259
+ leaveRoom2();
241
260
  } else {
242
261
  store.dispatch(action);
243
262
  }
@@ -256,8 +275,7 @@ var actions = {
256
275
  */
257
276
  enterRoom,
258
277
  /**
259
- * Leaves a room and stops sync it with Redux state.
260
- * @param roomId The id of the room
278
+ * Leaves the currently entered room and stops sync it with Redux state.
261
279
  */
262
280
  leaveRoom
263
281
  };
@@ -267,11 +285,8 @@ function enterRoom(roomId) {
267
285
  roomId
268
286
  };
269
287
  }
270
- function leaveRoom(roomId) {
271
- return {
272
- type: ACTION_TYPES.LEAVE,
273
- roomId
274
- };
288
+ function leaveRoom() {
289
+ return { type: ACTION_TYPES.LEAVE };
275
290
  }
276
291
  var liveblocksEnhancer = internalEnhancer;
277
292
  var enhancer = liveblocksEnhancer;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/version.ts"],"names":["enhancer","enterRoom","updates","leaveRoom"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBA,IAAM,eAAe;AAErB,SAAS,gBAAuB;AACrC,SAAO,IAAI,MAAM,GAAG,YAAY,oBAAoB;AACtD;AAEO,SAAS,wBACd,aACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW;AAAA,EAChC;AACF;AAEO,SAAS,6BACd,aACA,KACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW,IAAI,GAAG;AAAA,EACvC;AACF;AAEO,SAAS,gCAAgC,KAAoB;AAClE,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,KAAK,GAAG;AAAA,EACzB;AACF;AAEO,SAAS,8BAA8B,KAAoB;AAChE,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,YAAY,GAAG;AAAA,EAChC;AACF;;;AC9BO,IAAM,WAAW;AACjB,IAAM,cAAiD;AACvD,IAAM,aAAgD;;;AFwB7D,YAAY,UAAU,aAAa,UAAU;AAM7C,IAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,OA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AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus } from \"@liveblocks/core\";\nimport {\n detectDupes,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StoreEnhancer } from \"redux\";\n\nimport {\n mappingShouldBeAnObject,\n mappingShouldNotHaveTheSameKeys,\n mappingToFunctionIsNotAllowed,\n mappingValueShouldBeABoolean,\n missingClient,\n} from \"./errors\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\nconst ACTION_TYPES = {\n ENTER: \"@@LIVEBLOCKS/ENTER\",\n LEAVE: \"@@LIVEBLOCKS/LEAVE\",\n START_LOADING_STORAGE: \"@@LIVEBLOCKS/START_LOADING_STORAGE\",\n INIT_STORAGE: \"@@LIVEBLOCKS/INIT_STORAGE\",\n PATCH_REDUX_STATE: \"@@LIVEBLOCKS/PATCH_REDUX_STATE\",\n UPDATE_CONNECTION: \"@@LIVEBLOCKS/UPDATE_CONNECTION\",\n UPDATE_OTHERS: \"@@LIVEBLOCKS/UPDATE_OTHERS\",\n};\n\ntype LiveblocksContext<\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = {\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Please rename to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = WithLiveblocks<TState, TPresence, TUserMeta>;\n\n/**\n * Adds the `liveblocks` property to your custom Redux state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = TState & { readonly liveblocks: LiveblocksContext<TPresence, TUserMeta> };\n\nconst internalEnhancer = <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => {\n type OpaqueRoom = Room<JsonObject, LsonObject, BaseUserMeta, Json>;\n\n if (process.env.NODE_ENV !== \"production\" && options.client == null) {\n throw missingClient();\n }\n const client = options.client;\n const mapping = validateMapping(\n options.storageMapping || {},\n \"storageMapping\"\n );\n const presenceMapping = validateMapping(\n options.presenceMapping || {},\n \"presenceMapping\"\n );\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(mapping, presenceMapping);\n }\n\n return (createStore: any) => {\n return (reducer: any, initialState: any, enhancer: any) => {\n let room: OpaqueRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<LsonObject> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n\n const newReducer = (state: any, action: any) => {\n switch (action.type) {\n case ACTION_TYPES.PATCH_REDUX_STATE:\n return {\n ...state,\n ...action.state,\n };\n case ACTION_TYPES.INIT_STORAGE:\n return {\n ...state,\n ...action.state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: false,\n },\n };\n case ACTION_TYPES.START_LOADING_STORAGE:\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: true,\n },\n };\n case ACTION_TYPES.UPDATE_CONNECTION: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n connection: action.connection,\n status: action.status,\n },\n };\n }\n case ACTION_TYPES.UPDATE_OTHERS: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n others: action.others,\n },\n };\n }\n default: {\n const newState = reducer(state, action);\n\n if (room) {\n isPatching = true;\n updatePresence(room, state, newState, presenceMapping as any);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n state,\n newState,\n mapping as any\n );\n }\n });\n isPatching = false;\n }\n\n if (newState.liveblocks == null) {\n return {\n ...newState,\n liveblocks: {\n others: [],\n isStorageLoading: false,\n connection: \"closed\",\n status: \"initial\",\n },\n };\n }\n return newState;\n }\n }\n };\n\n const store = createStore(newReducer, initialState, enhancer);\n\n function enterRoom(roomId: string) {\n if (storageRoot) {\n return;\n }\n\n const initialPresence = selectFields(\n store.getState(),\n presenceMapping\n ) as any;\n\n room = client.enter(roomId, { initialPresence });\n\n unsubscribeCallbacks.push(\n room.events.connection.subscribe(() => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_CONNECTION,\n connection: room!.getConnectionState(),\n status: room!.getStatus(),\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_OTHERS,\n others,\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: selectFields(room!.getPresence(), presenceMapping),\n });\n }\n })\n );\n\n store.dispatch({\n type: ACTION_TYPES.START_LOADING_STORAGE,\n });\n\n void room.getStorage().then(({ root }) => {\n const updates: any = {};\n\n room!.batch(() => {\n for (const key in mapping) {\n const liveblocksStatePart = root.get(key);\n\n if (liveblocksStatePart == null) {\n updates[key] = store.getState()[key];\n patchLiveObjectKey(root, key, undefined, store.getState()[key]);\n } else {\n updates[key] = lsonToJson(liveblocksStatePart);\n }\n }\n });\n\n store.dispatch({\n type: ACTION_TYPES.INIT_STORAGE,\n state: updates,\n });\n\n storageRoot = root;\n unsubscribeCallbacks.push(\n room!.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: patchState(\n store.getState(),\n updates,\n mapping as any\n ),\n });\n }\n },\n { isDeep: true }\n )\n );\n });\n }\n\n function leaveRoom(roomId: string) {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n\n storageRoot = null;\n room = null;\n isPatching = false;\n unsubscribeCallbacks = [];\n\n client.leave(roomId);\n }\n\n function newDispatch(action: any) {\n if (action.type === ACTION_TYPES.ENTER) {\n enterRoom(action.roomId);\n } else if (action.type === ACTION_TYPES.LEAVE) {\n leaveRoom(action.roomId);\n } else {\n store.dispatch(action);\n }\n }\n\n return {\n ...store,\n dispatch: newDispatch,\n };\n };\n };\n};\n\n/**\n * Actions used to interact with Liveblocks\n */\nexport const actions = {\n /**\n * Enters a room and starts sync it with Redux state\n * @param roomId The id of the room\n */\n enterRoom,\n /**\n * Leaves a room and stops sync it with Redux state.\n * @param roomId The id of the room\n */\n leaveRoom,\n};\n\nfunction enterRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.ENTER,\n roomId,\n };\n}\n\nfunction leaveRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.LEAVE,\n roomId,\n };\n}\n\n/**\n * Redux store enhancer that will make the `liveblocks` key available on your\n * Redux store.\n */\nexport const liveblocksEnhancer = internalEnhancer as <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => StoreEnhancer;\n\n/**\n * @deprecated Renamed to `liveblocksEnhancer`.\n */\nexport const enhancer = liveblocksEnhancer;\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal as any, newVal);\n }\n }\n}\n\nfunction updatePresence<TPresence extends JsonObject>(\n room: Room<TPresence, any, any, any>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n room.updatePresence({ [key]: newState[key] } as TPresence);\n }\n }\n}\n\nfunction isObject(value: any): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<TState>(\n storageMapping: Mapping<TState>,\n presenceMapping: Mapping<TState>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw mappingShouldNotHaveTheSameKeys(key);\n }\n }\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction patchState<TState extends JsonObject>(\n state: TState,\n updates: any[], // StorageUpdate\n mapping: Mapping<TState>\n) {\n const partialState: Partial<TState> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<TState> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<TState>(\n mapping: Mapping<TState>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<TState> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isObject(mapping)) {\n throw mappingShouldBeAnObject(mappingType);\n }\n }\n\n const result: Mapping<TState> = {};\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof mapping[key] !== \"boolean\"\n ) {\n throw mappingValueShouldBeABoolean(mappingType, key);\n }\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n","export const ERROR_PREFIX = \"Invalid @liveblocks/redux middleware config.\";\n\nexport function missingClient(): Error {\n return new Error(`${ERROR_PREFIX} client is missing`);\n}\n\nexport function mappingShouldBeAnObject(\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n}\n\nexport function mappingValueShouldBeABoolean(\n mappingType: \"storageMapping\" | \"presenceMapping\",\n key: string\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n}\n\nexport function mappingShouldNotHaveTheSameKeys(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n}\n\nexport function mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/redux\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/version.ts"],"names":["enhancer","enterRoom","updates","leaveRoom"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBA,IAAM,eAAe;AAErB,SAAS,gBAAuB;AACrC,SAAO,IAAI,MAAM,GAAG,YAAY,oBAA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AS;AACzB,iBAAa,GAAG,IAAI,SAAS,GAAG;AAAA,EAClC;AACA,SAAO;AACT;AAEA,SAAS,WACP,OACA,SACA,SACA;AACA,QAAM,eAAgC,CAAC;AAEvC,aAAW,OAAO,SAAS;AACzB,iBAAa,GAAG,IAAI,MAAM,GAAG;AAAA,EAC/B;AAEA,QAAM,UAAU,4BAA4B,cAAc,OAAO;AAEjE,QAAM,SAA0B,CAAC;AAEjC,aAAW,OAAO,SAAS;AACzB,WAAO,GAAG,IAAI,QAAQ,GAAG;AAAA,EAC3B;AAEA,SAAO;AACT;AAKA,SAAS,gBACP,SACA,aACiB;AACjB,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,SAAS,OAAO,GAAG;AACtB,YAAM,wBAAwB,WAAW;AAAA,IAC3C;AAAA,EACF;AAEA,QAAM,SAA0B,CAAC;AACjC,aAAW,OAAO,SAAS;AACzB,QACE,QAAQ,IAAI,aAAa,gBACzB,OAAO,QAAQ,GAAG,MAAM,WACxB;AACA,YAAM,6BAA6B,aAAa,GAAG;AAAA,IACrD;AAEA,QAAI,QAAQ,GAAG,MAAM,MAAM;AACzB,aAAO,GAAG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus } from \"@liveblocks/core\";\nimport {\n detectDupes,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StoreEnhancer } from \"redux\";\n\nimport {\n mappingShouldBeAnObject,\n mappingShouldNotHaveTheSameKeys,\n mappingToFunctionIsNotAllowed,\n mappingValueShouldBeABoolean,\n missingClient,\n} from \"./errors\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\nconst ACTION_TYPES = {\n ENTER: \"@@LIVEBLOCKS/ENTER\",\n LEAVE: \"@@LIVEBLOCKS/LEAVE\",\n START_LOADING_STORAGE: \"@@LIVEBLOCKS/START_LOADING_STORAGE\",\n INIT_STORAGE: \"@@LIVEBLOCKS/INIT_STORAGE\",\n PATCH_REDUX_STATE: \"@@LIVEBLOCKS/PATCH_REDUX_STATE\",\n UPDATE_CONNECTION: \"@@LIVEBLOCKS/UPDATE_CONNECTION\",\n UPDATE_OTHERS: \"@@LIVEBLOCKS/UPDATE_OTHERS\",\n};\n\ntype LiveblocksContext<\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = {\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Please rename to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = WithLiveblocks<TState, TPresence, TUserMeta>;\n\n/**\n * Adds the `liveblocks` property to your custom Redux state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = TState & { readonly liveblocks: LiveblocksContext<TPresence, TUserMeta> };\n\nconst internalEnhancer = <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => {\n type OpaqueRoom = Room<JsonObject, LsonObject, BaseUserMeta, Json>;\n\n if (process.env.NODE_ENV !== \"production\" && options.client == null) {\n throw missingClient();\n }\n const client = options.client;\n const mapping = validateMapping(\n options.storageMapping || {},\n \"storageMapping\"\n );\n const presenceMapping = validateMapping(\n options.presenceMapping || {},\n \"presenceMapping\"\n );\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(mapping, presenceMapping);\n }\n\n return (createStore: any) => {\n return (reducer: any, initialState: any, enhancer: any) => {\n let maybeRoom: OpaqueRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<LsonObject> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n const newReducer = (state: any, action: any) => {\n switch (action.type) {\n case ACTION_TYPES.PATCH_REDUX_STATE:\n return {\n ...state,\n ...action.state,\n };\n case ACTION_TYPES.INIT_STORAGE:\n return {\n ...state,\n ...action.state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: false,\n },\n };\n case ACTION_TYPES.START_LOADING_STORAGE:\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: true,\n },\n };\n case ACTION_TYPES.UPDATE_CONNECTION: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n connection: action.connection,\n status: action.status,\n },\n };\n }\n case ACTION_TYPES.UPDATE_OTHERS: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n others: action.others,\n },\n };\n }\n default: {\n const newState = reducer(state, action);\n\n if (maybeRoom) {\n isPatching = true;\n updatePresence(\n maybeRoom,\n state,\n newState,\n presenceMapping as any\n );\n\n maybeRoom.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n state,\n newState,\n mapping as any\n );\n }\n });\n isPatching = false;\n }\n\n if (newState.liveblocks == null) {\n return {\n ...newState,\n liveblocks: {\n others: [],\n isStorageLoading: false,\n connection: \"closed\",\n status: \"initial\",\n },\n };\n }\n return newState;\n }\n }\n };\n\n const store = createStore(newReducer, initialState, enhancer);\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n store.getState(),\n presenceMapping\n ) as any;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n });\n maybeRoom = room as OpaqueRoom;\n\n unsubscribeCallbacks.push(\n room.events.connection.subscribe(() => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_CONNECTION,\n connection: room.getConnectionState(),\n status: room.getStatus(),\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_OTHERS,\n others,\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: selectFields(room.getPresence(), presenceMapping),\n });\n }\n })\n );\n\n store.dispatch({\n type: ACTION_TYPES.START_LOADING_STORAGE,\n });\n\n void room.getStorage().then(({ root }) => {\n const updates: any = {};\n\n maybeRoom!.batch(() => {\n for (const key in mapping) {\n const liveblocksStatePart = root.get(key);\n\n if (liveblocksStatePart == null) {\n updates[key] = store.getState()[key];\n patchLiveObjectKey(root, key, undefined, store.getState()[key]);\n } else {\n updates[key] = lsonToJson(liveblocksStatePart);\n }\n }\n });\n\n store.dispatch({\n type: ACTION_TYPES.INIT_STORAGE,\n state: updates,\n });\n\n storageRoot = root;\n unsubscribeCallbacks.push(\n maybeRoom!.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: patchState(\n store.getState(),\n updates,\n mapping as any\n ),\n });\n }\n },\n { isDeep: true }\n )\n );\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n function newDispatch(action: any) {\n if (action.type === ACTION_TYPES.ENTER) {\n enterRoom(action.roomId);\n } else if (action.type === ACTION_TYPES.LEAVE) {\n leaveRoom();\n } else {\n store.dispatch(action);\n }\n }\n\n return {\n ...store,\n dispatch: newDispatch,\n };\n };\n };\n};\n\n/**\n * Actions used to interact with Liveblocks\n */\nexport const actions = {\n /**\n * Enters a room and starts sync it with Redux state\n * @param roomId The id of the room\n */\n enterRoom,\n /**\n * Leaves the currently entered room and stops sync it with Redux state.\n */\n leaveRoom,\n};\n\nfunction enterRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.ENTER,\n roomId,\n };\n}\n\nfunction leaveRoom(): {\n type: string;\n} {\n return { type: ACTION_TYPES.LEAVE };\n}\n\n/**\n * Redux store enhancer that will make the `liveblocks` key available on your\n * Redux store.\n */\nexport const liveblocksEnhancer = internalEnhancer as <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => StoreEnhancer;\n\n/**\n * @deprecated Renamed to `liveblocksEnhancer`.\n */\nexport const enhancer = liveblocksEnhancer;\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal as any, newVal);\n }\n }\n}\n\nfunction updatePresence<TPresence extends JsonObject>(\n room: Room<TPresence, any, any, any>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n room.updatePresence({ [key]: newState[key] } as TPresence);\n }\n }\n}\n\nfunction isObject(value: any): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<TState>(\n storageMapping: Mapping<TState>,\n presenceMapping: Mapping<TState>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw mappingShouldNotHaveTheSameKeys(key);\n }\n }\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction patchState<TState extends JsonObject>(\n state: TState,\n updates: any[], // StorageUpdate\n mapping: Mapping<TState>\n) {\n const partialState: Partial<TState> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<TState> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<TState>(\n mapping: Mapping<TState>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<TState> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isObject(mapping)) {\n throw mappingShouldBeAnObject(mappingType);\n }\n }\n\n const result: Mapping<TState> = {};\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof mapping[key] !== \"boolean\"\n ) {\n throw mappingValueShouldBeABoolean(mappingType, key);\n }\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n","export const ERROR_PREFIX = \"Invalid @liveblocks/redux middleware config.\";\n\nexport function missingClient(): Error {\n return new Error(`${ERROR_PREFIX} client is missing`);\n}\n\nexport function mappingShouldBeAnObject(\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n}\n\nexport function mappingValueShouldBeABoolean(\n mappingType: \"storageMapping\" | \"presenceMapping\",\n key: string\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n}\n\nexport function mappingShouldNotHaveTheSameKeys(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n}\n\nexport function mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/redux\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"]}
package/dist/index.mjs CHANGED
@@ -34,7 +34,7 @@ function mappingToFunctionIsNotAllowed(key) {
34
34
 
35
35
  // src/version.ts
36
36
  var PKG_NAME = "@liveblocks/redux";
37
- var PKG_VERSION = "1.4.8-test1";
37
+ var PKG_VERSION = "1.5.0-test2";
38
38
  var PKG_FORMAT = "esm";
39
39
 
40
40
  // src/index.ts
@@ -66,10 +66,12 @@ var internalEnhancer = (options) => {
66
66
  }
67
67
  return (createStore) => {
68
68
  return (reducer, initialState, enhancer2) => {
69
- let room = null;
69
+ let maybeRoom = null;
70
70
  let isPatching = false;
71
71
  let storageRoot = null;
72
72
  let unsubscribeCallbacks = [];
73
+ let lastRoomId = null;
74
+ let lastLeaveFn = null;
73
75
  const newReducer = (state, action) => {
74
76
  switch (action.type) {
75
77
  case ACTION_TYPES.PATCH_REDUX_STATE:
@@ -115,10 +117,15 @@ var internalEnhancer = (options) => {
115
117
  }
116
118
  default: {
117
119
  const newState = reducer(state, action);
118
- if (room) {
120
+ if (maybeRoom) {
119
121
  isPatching = true;
120
- updatePresence(room, state, newState, presenceMapping);
121
- room.batch(() => {
122
+ updatePresence(
123
+ maybeRoom,
124
+ state,
125
+ newState,
126
+ presenceMapping
127
+ );
128
+ maybeRoom.batch(() => {
122
129
  if (storageRoot) {
123
130
  patchLiveblocksStorage(
124
131
  storageRoot,
@@ -146,15 +153,22 @@ var internalEnhancer = (options) => {
146
153
  }
147
154
  };
148
155
  const store = createStore(newReducer, initialState, enhancer2);
149
- function enterRoom2(roomId) {
150
- if (storageRoot) {
156
+ function enterRoom2(newRoomId) {
157
+ if (lastRoomId === newRoomId) {
151
158
  return;
152
159
  }
160
+ lastRoomId = newRoomId;
161
+ if (lastLeaveFn !== null) {
162
+ lastLeaveFn();
163
+ }
153
164
  const initialPresence = selectFields(
154
165
  store.getState(),
155
166
  presenceMapping
156
167
  );
157
- room = client.enter(roomId, { initialPresence });
168
+ const { room, leave } = client.enterRoom(newRoomId, {
169
+ initialPresence
170
+ });
171
+ maybeRoom = room;
158
172
  unsubscribeCallbacks.push(
159
173
  room.events.connection.subscribe(() => {
160
174
  store.dispatch({
@@ -187,7 +201,7 @@ var internalEnhancer = (options) => {
187
201
  });
188
202
  void room.getStorage().then(({ root }) => {
189
203
  const updates = {};
190
- room.batch(() => {
204
+ maybeRoom.batch(() => {
191
205
  for (const key in mapping) {
192
206
  const liveblocksStatePart = root.get(key);
193
207
  if (liveblocksStatePart == null) {
@@ -204,7 +218,7 @@ var internalEnhancer = (options) => {
204
218
  });
205
219
  storageRoot = root;
206
220
  unsubscribeCallbacks.push(
207
- room.subscribe(
221
+ maybeRoom.subscribe(
208
222
  root,
209
223
  (updates2) => {
210
224
  if (isPatching === false) {
@@ -222,22 +236,27 @@ var internalEnhancer = (options) => {
222
236
  )
223
237
  );
224
238
  });
239
+ lastLeaveFn = () => {
240
+ for (const unsubscribe of unsubscribeCallbacks) {
241
+ unsubscribe();
242
+ }
243
+ unsubscribeCallbacks = [];
244
+ storageRoot = null;
245
+ maybeRoom = null;
246
+ isPatching = false;
247
+ lastRoomId = null;
248
+ lastLeaveFn = null;
249
+ leave();
250
+ };
225
251
  }
226
- function leaveRoom2(roomId) {
227
- for (const unsubscribe of unsubscribeCallbacks) {
228
- unsubscribe();
229
- }
230
- storageRoot = null;
231
- room = null;
232
- isPatching = false;
233
- unsubscribeCallbacks = [];
234
- client.leave(roomId);
252
+ function leaveRoom2() {
253
+ lastLeaveFn?.();
235
254
  }
236
255
  function newDispatch(action) {
237
256
  if (action.type === ACTION_TYPES.ENTER) {
238
257
  enterRoom2(action.roomId);
239
258
  } else if (action.type === ACTION_TYPES.LEAVE) {
240
- leaveRoom2(action.roomId);
259
+ leaveRoom2();
241
260
  } else {
242
261
  store.dispatch(action);
243
262
  }
@@ -256,8 +275,7 @@ var actions = {
256
275
  */
257
276
  enterRoom,
258
277
  /**
259
- * Leaves a room and stops sync it with Redux state.
260
- * @param roomId The id of the room
278
+ * Leaves the currently entered room and stops sync it with Redux state.
261
279
  */
262
280
  leaveRoom
263
281
  };
@@ -267,11 +285,8 @@ function enterRoom(roomId) {
267
285
  roomId
268
286
  };
269
287
  }
270
- function leaveRoom(roomId) {
271
- return {
272
- type: ACTION_TYPES.LEAVE,
273
- roomId
274
- };
288
+ function leaveRoom() {
289
+ return { type: ACTION_TYPES.LEAVE };
275
290
  }
276
291
  var liveblocksEnhancer = internalEnhancer;
277
292
  var enhancer = liveblocksEnhancer;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/version.ts"],"sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus } from \"@liveblocks/core\";\nimport {\n detectDupes,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StoreEnhancer } from \"redux\";\n\nimport {\n mappingShouldBeAnObject,\n mappingShouldNotHaveTheSameKeys,\n mappingToFunctionIsNotAllowed,\n mappingValueShouldBeABoolean,\n missingClient,\n} from \"./errors\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\nconst ACTION_TYPES = {\n ENTER: \"@@LIVEBLOCKS/ENTER\",\n LEAVE: \"@@LIVEBLOCKS/LEAVE\",\n START_LOADING_STORAGE: \"@@LIVEBLOCKS/START_LOADING_STORAGE\",\n INIT_STORAGE: \"@@LIVEBLOCKS/INIT_STORAGE\",\n PATCH_REDUX_STATE: \"@@LIVEBLOCKS/PATCH_REDUX_STATE\",\n UPDATE_CONNECTION: \"@@LIVEBLOCKS/UPDATE_CONNECTION\",\n UPDATE_OTHERS: \"@@LIVEBLOCKS/UPDATE_OTHERS\",\n};\n\ntype LiveblocksContext<\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = {\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Please rename to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = WithLiveblocks<TState, TPresence, TUserMeta>;\n\n/**\n * Adds the `liveblocks` property to your custom Redux state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = TState & { readonly liveblocks: LiveblocksContext<TPresence, TUserMeta> };\n\nconst internalEnhancer = <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => {\n type OpaqueRoom = Room<JsonObject, LsonObject, BaseUserMeta, Json>;\n\n if (process.env.NODE_ENV !== \"production\" && options.client == null) {\n throw missingClient();\n }\n const client = options.client;\n const mapping = validateMapping(\n options.storageMapping || {},\n \"storageMapping\"\n );\n const presenceMapping = validateMapping(\n options.presenceMapping || {},\n \"presenceMapping\"\n );\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(mapping, presenceMapping);\n }\n\n return (createStore: any) => {\n return (reducer: any, initialState: any, enhancer: any) => {\n let room: OpaqueRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<LsonObject> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n\n const newReducer = (state: any, action: any) => {\n switch (action.type) {\n case ACTION_TYPES.PATCH_REDUX_STATE:\n return {\n ...state,\n ...action.state,\n };\n case ACTION_TYPES.INIT_STORAGE:\n return {\n ...state,\n ...action.state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: false,\n },\n };\n case ACTION_TYPES.START_LOADING_STORAGE:\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: true,\n },\n };\n case ACTION_TYPES.UPDATE_CONNECTION: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n connection: action.connection,\n status: action.status,\n },\n };\n }\n case ACTION_TYPES.UPDATE_OTHERS: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n others: action.others,\n },\n };\n }\n default: {\n const newState = reducer(state, action);\n\n if (room) {\n isPatching = true;\n updatePresence(room, state, newState, presenceMapping as any);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n state,\n newState,\n mapping as any\n );\n }\n });\n isPatching = false;\n }\n\n if (newState.liveblocks == null) {\n return {\n ...newState,\n liveblocks: {\n others: [],\n isStorageLoading: false,\n connection: \"closed\",\n status: \"initial\",\n },\n };\n }\n return newState;\n }\n }\n };\n\n const store = createStore(newReducer, initialState, enhancer);\n\n function enterRoom(roomId: string) {\n if (storageRoot) {\n return;\n }\n\n const initialPresence = selectFields(\n store.getState(),\n presenceMapping\n ) as any;\n\n room = client.enter(roomId, { initialPresence });\n\n unsubscribeCallbacks.push(\n room.events.connection.subscribe(() => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_CONNECTION,\n connection: room!.getConnectionState(),\n status: room!.getStatus(),\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_OTHERS,\n others,\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: selectFields(room!.getPresence(), presenceMapping),\n });\n }\n })\n );\n\n store.dispatch({\n type: ACTION_TYPES.START_LOADING_STORAGE,\n });\n\n void room.getStorage().then(({ root }) => {\n const updates: any = {};\n\n room!.batch(() => {\n for (const key in mapping) {\n const liveblocksStatePart = root.get(key);\n\n if (liveblocksStatePart == null) {\n updates[key] = store.getState()[key];\n patchLiveObjectKey(root, key, undefined, store.getState()[key]);\n } else {\n updates[key] = lsonToJson(liveblocksStatePart);\n }\n }\n });\n\n store.dispatch({\n type: ACTION_TYPES.INIT_STORAGE,\n state: updates,\n });\n\n storageRoot = root;\n unsubscribeCallbacks.push(\n room!.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: patchState(\n store.getState(),\n updates,\n mapping as any\n ),\n });\n }\n },\n { isDeep: true }\n )\n );\n });\n }\n\n function leaveRoom(roomId: string) {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n\n storageRoot = null;\n room = null;\n isPatching = false;\n unsubscribeCallbacks = [];\n\n client.leave(roomId);\n }\n\n function newDispatch(action: any) {\n if (action.type === ACTION_TYPES.ENTER) {\n enterRoom(action.roomId);\n } else if (action.type === ACTION_TYPES.LEAVE) {\n leaveRoom(action.roomId);\n } else {\n store.dispatch(action);\n }\n }\n\n return {\n ...store,\n dispatch: newDispatch,\n };\n };\n };\n};\n\n/**\n * Actions used to interact with Liveblocks\n */\nexport const actions = {\n /**\n * Enters a room and starts sync it with Redux state\n * @param roomId The id of the room\n */\n enterRoom,\n /**\n * Leaves a room and stops sync it with Redux state.\n * @param roomId The id of the room\n */\n leaveRoom,\n};\n\nfunction enterRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.ENTER,\n roomId,\n };\n}\n\nfunction leaveRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.LEAVE,\n roomId,\n };\n}\n\n/**\n * Redux store enhancer that will make the `liveblocks` key available on your\n * Redux store.\n */\nexport const liveblocksEnhancer = internalEnhancer as <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => StoreEnhancer;\n\n/**\n * @deprecated Renamed to `liveblocksEnhancer`.\n */\nexport const enhancer = liveblocksEnhancer;\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal as any, newVal);\n }\n }\n}\n\nfunction updatePresence<TPresence extends JsonObject>(\n room: Room<TPresence, any, any, any>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n room.updatePresence({ [key]: newState[key] } as TPresence);\n }\n }\n}\n\nfunction isObject(value: any): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<TState>(\n storageMapping: Mapping<TState>,\n presenceMapping: Mapping<TState>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw mappingShouldNotHaveTheSameKeys(key);\n }\n }\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction patchState<TState extends JsonObject>(\n state: TState,\n updates: any[], // StorageUpdate\n mapping: Mapping<TState>\n) {\n const partialState: Partial<TState> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<TState> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<TState>(\n mapping: Mapping<TState>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<TState> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isObject(mapping)) {\n throw mappingShouldBeAnObject(mappingType);\n }\n }\n\n const result: Mapping<TState> = {};\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof mapping[key] !== \"boolean\"\n ) {\n throw mappingValueShouldBeABoolean(mappingType, key);\n }\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n","export const ERROR_PREFIX = \"Invalid @liveblocks/redux middleware config.\";\n\nexport function missingClient(): Error {\n return new Error(`${ERROR_PREFIX} client is missing`);\n}\n\nexport function mappingShouldBeAnObject(\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n}\n\nexport function mappingValueShouldBeABoolean(\n mappingType: \"storageMapping\" | \"presenceMapping\",\n key: string\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n}\n\nexport function mappingShouldNotHaveTheSameKeys(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n}\n\nexport function mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/redux\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBA,IAAM,eAAe;AAErB,SAAS,gBAAuB;AACrC,SAAO,IAAI,MAAM,GAAG,YAAY,oBAAoB;AACtD;AAEO,SAAS,wBACd,aACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW;AAAA,EAChC;AACF;AAEO,SAAS,6BACd,aACA,KACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW,IAAI,GAAG;AAAA,EACvC;AACF;AAEO,SAAS,gCAAgC,KAAoB;AAClE,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,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ACtB,YAAM,wBAAwB,WAAW;AAAA,IAC3C;AAAA,EACF;AAEA,QAAM,SAA0B,CAAC;AACjC,aAAW,OAAO,SAAS;AACzB,QACE,QAAQ,IAAI,aAAa,gBACzB,OAAO,QAAQ,GAAG,MAAM,WACxB;AACA,YAAM,6BAA6B,aAAa,GAAG;AAAA,IACrD;AAEA,QAAI,QAAQ,GAAG,MAAM,MAAM;AACzB,aAAO,GAAG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;","names":["enhancer","enterRoom","updates","leaveRoom"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/version.ts"],"sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus } from \"@liveblocks/core\";\nimport {\n detectDupes,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StoreEnhancer } from \"redux\";\n\nimport {\n mappingShouldBeAnObject,\n mappingShouldNotHaveTheSameKeys,\n mappingToFunctionIsNotAllowed,\n mappingValueShouldBeABoolean,\n missingClient,\n} from \"./errors\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\nconst ACTION_TYPES = {\n ENTER: \"@@LIVEBLOCKS/ENTER\",\n LEAVE: \"@@LIVEBLOCKS/LEAVE\",\n START_LOADING_STORAGE: \"@@LIVEBLOCKS/START_LOADING_STORAGE\",\n INIT_STORAGE: \"@@LIVEBLOCKS/INIT_STORAGE\",\n PATCH_REDUX_STATE: \"@@LIVEBLOCKS/PATCH_REDUX_STATE\",\n UPDATE_CONNECTION: \"@@LIVEBLOCKS/UPDATE_CONNECTION\",\n UPDATE_OTHERS: \"@@LIVEBLOCKS/UPDATE_OTHERS\",\n};\n\ntype LiveblocksContext<\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = {\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Please rename to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = WithLiveblocks<TState, TPresence, TUserMeta>;\n\n/**\n * Adds the `liveblocks` property to your custom Redux state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject,\n TUserMeta extends BaseUserMeta,\n> = TState & { readonly liveblocks: LiveblocksContext<TPresence, TUserMeta> };\n\nconst internalEnhancer = <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => {\n type OpaqueRoom = Room<JsonObject, LsonObject, BaseUserMeta, Json>;\n\n if (process.env.NODE_ENV !== \"production\" && options.client == null) {\n throw missingClient();\n }\n const client = options.client;\n const mapping = validateMapping(\n options.storageMapping || {},\n \"storageMapping\"\n );\n const presenceMapping = validateMapping(\n options.presenceMapping || {},\n \"presenceMapping\"\n );\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(mapping, presenceMapping);\n }\n\n return (createStore: any) => {\n return (reducer: any, initialState: any, enhancer: any) => {\n let maybeRoom: OpaqueRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<LsonObject> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n const newReducer = (state: any, action: any) => {\n switch (action.type) {\n case ACTION_TYPES.PATCH_REDUX_STATE:\n return {\n ...state,\n ...action.state,\n };\n case ACTION_TYPES.INIT_STORAGE:\n return {\n ...state,\n ...action.state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: false,\n },\n };\n case ACTION_TYPES.START_LOADING_STORAGE:\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n isStorageLoading: true,\n },\n };\n case ACTION_TYPES.UPDATE_CONNECTION: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n connection: action.connection,\n status: action.status,\n },\n };\n }\n case ACTION_TYPES.UPDATE_OTHERS: {\n return {\n ...state,\n liveblocks: {\n ...state.liveblocks,\n others: action.others,\n },\n };\n }\n default: {\n const newState = reducer(state, action);\n\n if (maybeRoom) {\n isPatching = true;\n updatePresence(\n maybeRoom,\n state,\n newState,\n presenceMapping as any\n );\n\n maybeRoom.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n state,\n newState,\n mapping as any\n );\n }\n });\n isPatching = false;\n }\n\n if (newState.liveblocks == null) {\n return {\n ...newState,\n liveblocks: {\n others: [],\n isStorageLoading: false,\n connection: \"closed\",\n status: \"initial\",\n },\n };\n }\n return newState;\n }\n }\n };\n\n const store = createStore(newReducer, initialState, enhancer);\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n store.getState(),\n presenceMapping\n ) as any;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n });\n maybeRoom = room as OpaqueRoom;\n\n unsubscribeCallbacks.push(\n room.events.connection.subscribe(() => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_CONNECTION,\n connection: room.getConnectionState(),\n status: room.getStatus(),\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n store.dispatch({\n type: ACTION_TYPES.UPDATE_OTHERS,\n others,\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: selectFields(room.getPresence(), presenceMapping),\n });\n }\n })\n );\n\n store.dispatch({\n type: ACTION_TYPES.START_LOADING_STORAGE,\n });\n\n void room.getStorage().then(({ root }) => {\n const updates: any = {};\n\n maybeRoom!.batch(() => {\n for (const key in mapping) {\n const liveblocksStatePart = root.get(key);\n\n if (liveblocksStatePart == null) {\n updates[key] = store.getState()[key];\n patchLiveObjectKey(root, key, undefined, store.getState()[key]);\n } else {\n updates[key] = lsonToJson(liveblocksStatePart);\n }\n }\n });\n\n store.dispatch({\n type: ACTION_TYPES.INIT_STORAGE,\n state: updates,\n });\n\n storageRoot = root;\n unsubscribeCallbacks.push(\n maybeRoom!.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n store.dispatch({\n type: ACTION_TYPES.PATCH_REDUX_STATE,\n state: patchState(\n store.getState(),\n updates,\n mapping as any\n ),\n });\n }\n },\n { isDeep: true }\n )\n );\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n function newDispatch(action: any) {\n if (action.type === ACTION_TYPES.ENTER) {\n enterRoom(action.roomId);\n } else if (action.type === ACTION_TYPES.LEAVE) {\n leaveRoom();\n } else {\n store.dispatch(action);\n }\n }\n\n return {\n ...store,\n dispatch: newDispatch,\n };\n };\n };\n};\n\n/**\n * Actions used to interact with Liveblocks\n */\nexport const actions = {\n /**\n * Enters a room and starts sync it with Redux state\n * @param roomId The id of the room\n */\n enterRoom,\n /**\n * Leaves the currently entered room and stops sync it with Redux state.\n */\n leaveRoom,\n};\n\nfunction enterRoom(roomId: string): {\n type: string;\n roomId: string;\n} {\n return {\n type: ACTION_TYPES.ENTER,\n roomId,\n };\n}\n\nfunction leaveRoom(): {\n type: string;\n} {\n return { type: ACTION_TYPES.LEAVE };\n}\n\n/**\n * Redux store enhancer that will make the `liveblocks` key available on your\n * Redux store.\n */\nexport const liveblocksEnhancer = internalEnhancer as <TState>(options: {\n client: Client;\n storageMapping?: Mapping<TState>;\n presenceMapping?: Mapping<TState>;\n}) => StoreEnhancer;\n\n/**\n * @deprecated Renamed to `liveblocksEnhancer`.\n */\nexport const enhancer = liveblocksEnhancer;\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal as any, newVal);\n }\n }\n}\n\nfunction updatePresence<TPresence extends JsonObject>(\n room: Room<TPresence, any, any, any>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(\"value\");\n }\n\n if (oldState[key] !== newState[key]) {\n room.updatePresence({ [key]: newState[key] } as TPresence);\n }\n }\n}\n\nfunction isObject(value: any): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<TState>(\n storageMapping: Mapping<TState>,\n presenceMapping: Mapping<TState>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw mappingShouldNotHaveTheSameKeys(key);\n }\n }\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction patchState<TState extends JsonObject>(\n state: TState,\n updates: any[], // StorageUpdate\n mapping: Mapping<TState>\n) {\n const partialState: Partial<TState> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<TState> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<TState>(\n mapping: Mapping<TState>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<TState> {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isObject(mapping)) {\n throw mappingShouldBeAnObject(mappingType);\n }\n }\n\n const result: Mapping<TState> = {};\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof mapping[key] !== \"boolean\"\n ) {\n throw mappingValueShouldBeABoolean(mappingType, key);\n }\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n","export const ERROR_PREFIX = \"Invalid @liveblocks/redux middleware config.\";\n\nexport function missingClient(): Error {\n return new Error(`${ERROR_PREFIX} client is missing`);\n}\n\nexport function mappingShouldBeAnObject(\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n}\n\nexport function mappingValueShouldBeABoolean(\n mappingType: \"storageMapping\" | \"presenceMapping\",\n key: string\n): Error {\n return new Error(\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n}\n\nexport function mappingShouldNotHaveTheSameKeys(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n}\n\nexport function mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/redux\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBA,IAAM,eAAe;AAErB,SAAS,gBAAuB;AACrC,SAAO,IAAI,MAAM,GAAG,YAAY,oBAAoB;AACtD;AAEO,SAAS,wBACd,aACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW;AAAA,EAChC;AACF;AAEO,SAAS,6BACd,aACA,KACO;AACP,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,IAAI,WAAW,IAAI,GAAG;AAAA,EACvC;AACF;AAEO,SAAS,gCAAgC,KAAoB;AAClE,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,KAAK,GAAG;AAAA,EACzB;AACF;AAEO,SAAS,8BAA8B,KAAoB;AAChE,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,YAAY,GAAG;AAAA,EAChC;AACF;;;AC9BO,IAAM,WAAW;AACjB,IAAM,cAAiD;AACvD,IAAM,aAAgD;;;AFwB7D,YAAY,UAAU,aAAa,UAAU;AAM7C,IAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,uBAAuB;AAAA,EACvB,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,eAAe;AACjB;AAuDA,IAAM,mBAAmB,CAAS,YAI5B;AAGJ,MAAI,QAAQ,IAAI,aAAa,g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AG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;","names":["enhancer","enterRoom","updates","leaveRoom"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/redux",
3
- "version": "1.4.8-test1",
3
+ "version": "1.5.0-test2",
4
4
  "description": "A store enhancer to integrate Liveblocks into Redux stores. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -32,8 +32,8 @@
32
32
  "test:watch": "jest --silent --verbose --color=always --watch"
33
33
  },
34
34
  "dependencies": {
35
- "@liveblocks/client": "1.4.8-test1",
36
- "@liveblocks/core": "1.4.8-test1"
35
+ "@liveblocks/client": "1.5.0-test2",
36
+ "@liveblocks/core": "1.5.0-test2"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "redux": "^4"