@liveblocks/redux 0.15.0-alpha.3 → 0.15.1

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/README.md CHANGED
@@ -0,0 +1,40 @@
1
+ <p align="center">
2
+ <a href="https://liveblocks.io">
3
+ <img src="https://liveblocks.io/images/blog/introducing-liveblocks.png">
4
+ </a>
5
+ </p>
6
+
7
+ # Liveblocks · [![Twitter Follow](https://shields.io/twitter/follow/liveblocks?label=Follow)](https://twitter.com/liveblocks)
8
+
9
+ **At [Liveblocks](https://liveblocks.io), we’re building tools to help companies create world-class collaborative products that attract, engage and retain users.** This repository is a set of open-source packages for building performant and reliable multiplayer experiences.
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ npm install @liveblocks/client @liveblocks/redux
15
+ ```
16
+
17
+ ## Documentation
18
+
19
+ - Start with the [React-Redux guide](https://liveblocks.io/docs/get-started/react-redux).
20
+ - Explore the [API Reference](https://liveblocks.io/docs/api-reference/liveblocks-redux).
21
+
22
+ ## Examples
23
+
24
+ - Browse our gallery of collaborative UI patterns. [View examples gallery](https://liveblocks.io/examples)
25
+ - Explore and clone any of our open-source examples. [View code examples](https://github.com/liveblocks/liveblocks/tree/main/examples)
26
+
27
+ ## Releases
28
+
29
+ For changelog, visit [https://github.com/liveblocks/liveblocks/releases](https://github.com/liveblocks/liveblocks/releases).
30
+
31
+ ## Community
32
+
33
+ - [Discord](https://discord.gg/X4YWJuH9VY) - To get involved with the Liveblocks community, ask questions and share tips.
34
+ - [Twitter](https://twitter.com/liveblocks) - To receive updates, announcements, blog posts, and general Liveblocks tips.
35
+
36
+ ## License
37
+
38
+ Licensed under the Apache License 2.0, Copyright © 2021-present [Liveblocks](https://liveblocks.io).
39
+
40
+ See [LICENSE](../../LICENSE) for more information.
package/lib/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { patchLiveObjectKey, liveNodeToJson, patchImmutableObject } from '@liveblocks/client';
1
+ import { internals } from '@liveblocks/client';
2
2
 
3
3
  const ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
4
4
  function missingClient() {
@@ -39,6 +39,7 @@ var __spreadValues = (a, b) => {
39
39
  return a;
40
40
  };
41
41
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
42
+ const { patchImmutableObject, patchLiveObjectKey, liveNodeToJson } = internals;
42
43
  const ACTION_TYPES = {
43
44
  ENTER: "@@LIVEBLOCKS/ENTER",
44
45
  LEAVE: "@@LIVEBLOCKS/LEAVE",
@@ -48,7 +49,7 @@ const ACTION_TYPES = {
48
49
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
49
50
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
50
51
  };
51
- const internalPlugin = (options) => {
52
+ const internalEnhancer = (options) => {
52
53
  if (process.env.NODE_ENV !== "production" && options.client == null) {
53
54
  throw missingClient();
54
55
  }
@@ -192,6 +193,10 @@ const internalPlugin = (options) => {
192
193
  });
193
194
  };
194
195
  };
196
+ const actions = {
197
+ enterRoom,
198
+ leaveRoom
199
+ };
195
200
  function enterRoom(roomId, initialState) {
196
201
  return {
197
202
  type: ACTION_TYPES.ENTER,
@@ -205,7 +210,7 @@ function leaveRoom(roomId) {
205
210
  roomId
206
211
  };
207
212
  }
208
- const enhancer = internalPlugin;
213
+ const enhancer = internalEnhancer;
209
214
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
210
215
  for (const key in mapping) {
211
216
  if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") {
@@ -274,4 +279,4 @@ function validateMapping(mapping, mappingType) {
274
279
  return result;
275
280
  }
276
281
 
277
- export { enhancer, enterRoom, leaveRoom };
282
+ export { actions, enhancer };
package/lib/esm/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { patchLiveObjectKey, liveNodeToJson, patchImmutableObject } from '@liveblocks/client';
1
+ import { internals } from '@liveblocks/client';
2
2
 
3
3
  const ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
4
4
  function missingClient() {
@@ -39,6 +39,7 @@ var __spreadValues = (a, b) => {
39
39
  return a;
40
40
  };
41
41
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
42
+ const { patchImmutableObject, patchLiveObjectKey, liveNodeToJson } = internals;
42
43
  const ACTION_TYPES = {
43
44
  ENTER: "@@LIVEBLOCKS/ENTER",
44
45
  LEAVE: "@@LIVEBLOCKS/LEAVE",
@@ -48,7 +49,7 @@ const ACTION_TYPES = {
48
49
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
49
50
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
50
51
  };
51
- const internalPlugin = (options) => {
52
+ const internalEnhancer = (options) => {
52
53
  if (process.env.NODE_ENV !== "production" && options.client == null) {
53
54
  throw missingClient();
54
55
  }
@@ -192,6 +193,10 @@ const internalPlugin = (options) => {
192
193
  });
193
194
  };
194
195
  };
196
+ const actions = {
197
+ enterRoom,
198
+ leaveRoom
199
+ };
195
200
  function enterRoom(roomId, initialState) {
196
201
  return {
197
202
  type: ACTION_TYPES.ENTER,
@@ -205,7 +210,7 @@ function leaveRoom(roomId) {
205
210
  roomId
206
211
  };
207
212
  }
208
- const enhancer = internalPlugin;
213
+ const enhancer = internalEnhancer;
209
214
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
210
215
  for (const key in mapping) {
211
216
  if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") {
@@ -274,4 +279,4 @@ function validateMapping(mapping, mappingType) {
274
279
  return result;
275
280
  }
276
281
 
277
- export { enhancer, enterRoom, leaveRoom };
282
+ export { actions, enhancer };
package/lib/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare type Mapping<T> = Partial<{
5
5
  }>;
6
6
  export declare type LiveblocksState<TState, TPresence = any> = TState & {
7
7
  /**
8
- * Liveblocks extra state attached by the middleware
8
+ * Liveblocks extra state attached by the enhancer
9
9
  */
10
10
  readonly liveblocks: {
11
11
  /**
@@ -22,12 +22,28 @@ export declare type LiveblocksState<TState, TPresence = any> = TState & {
22
22
  readonly connection: "closed" | "authenticating" | "unavailable" | "failed" | "open" | "connecting";
23
23
  };
24
24
  };
25
- export declare function enterRoom(roomId: string, initialState?: any): {
25
+ /**
26
+ * Actions used to interact with Liveblocks
27
+ */
28
+ export declare const actions: {
29
+ /**
30
+ * Enters a room and starts sync it with zustand state
31
+ * @param roomId The id of the room
32
+ * @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.
33
+ */
34
+ enterRoom: typeof enterRoom;
35
+ /**
36
+ * Leaves a room and stops sync it with zustand state.
37
+ * @param roomId The id of the room
38
+ */
39
+ leaveRoom: typeof leaveRoom;
40
+ };
41
+ declare function enterRoom(roomId: string, initialState?: any): {
26
42
  type: string;
27
43
  roomId: string;
28
44
  initialState: any;
29
45
  };
30
- export declare function leaveRoom(roomId: string): {
46
+ declare function leaveRoom(roomId: string): {
31
47
  type: string;
32
48
  roomId: string;
33
49
  };
@@ -36,3 +52,4 @@ export declare const enhancer: <T>(options: {
36
52
  storageMapping: Partial<{ [Property in keyof T]: boolean; }>;
37
53
  presenceMapping?: Partial<{ [Property in keyof T]: boolean; }> | undefined;
38
54
  }) => StoreEnhancer;
55
+ export {};
package/lib/index.js CHANGED
@@ -80,6 +80,9 @@ function mappingToFunctionIsNotAllowed(key) {
80
80
  return new Error(ERROR_PREFIX + " mapping." + key + " is invalid. Mapping to a function is not allowed.");
81
81
  }
82
82
 
83
+ var patchImmutableObject = client.internals.patchImmutableObject,
84
+ patchLiveObjectKey = client.internals.patchLiveObjectKey,
85
+ liveNodeToJson = client.internals.liveNodeToJson;
83
86
  var ACTION_TYPES = {
84
87
  ENTER: "@@LIVEBLOCKS/ENTER",
85
88
  LEAVE: "@@LIVEBLOCKS/LEAVE",
@@ -90,12 +93,12 @@ var ACTION_TYPES = {
90
93
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
91
94
  };
92
95
 
93
- var internalPlugin = function internalPlugin(options) {
96
+ var internalEnhancer = function internalEnhancer(options) {
94
97
  if (process.env.NODE_ENV !== "production" && options.client == null) {
95
98
  throw missingClient();
96
99
  }
97
100
 
98
- var client$1 = options.client;
101
+ var client = options.client;
99
102
  var mapping = validateMapping(options.storageMapping, "storageMapping");
100
103
  var presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
101
104
 
@@ -188,7 +191,7 @@ var internalPlugin = function internalPlugin(options) {
188
191
  return;
189
192
  }
190
193
 
191
- room = client$1.enter(roomId);
194
+ room = client.enter(roomId);
192
195
  broadcastInitialPresence(room, reduxState, presenceMapping);
193
196
  unsubscribeCallbacks.push(room.subscribe("connection", function () {
194
197
  store.dispatch({
@@ -209,14 +212,14 @@ var internalPlugin = function internalPlugin(options) {
209
212
  var root = _ref.root;
210
213
  var updates = {};
211
214
  room.batch(function () {
212
- for (var key in mapping) {
213
- var liveblocksStatePart = root.get(key);
215
+ for (var _key in mapping) {
216
+ var liveblocksStatePart = root.get(_key);
214
217
 
215
218
  if (liveblocksStatePart == null) {
216
- updates[key] = storageInitialState[key];
217
- client.patchLiveObjectKey(root, key, undefined, storageInitialState[key]);
219
+ updates[_key] = storageInitialState[_key];
220
+ patchLiveObjectKey(root, _key, undefined, storageInitialState[_key]);
218
221
  } else {
219
- updates[key] = client.liveNodeToJson(liveblocksStatePart);
222
+ updates[_key] = liveNodeToJson(liveblocksStatePart);
220
223
  }
221
224
  }
222
225
  });
@@ -248,7 +251,7 @@ var internalPlugin = function internalPlugin(options) {
248
251
  room = null;
249
252
  isPatching = false;
250
253
  unsubscribeCallbacks = [];
251
- client$1.leave(roomId);
254
+ client.leave(roomId);
252
255
  }
253
256
 
254
257
  function newDispatch(action, state) {
@@ -268,6 +271,11 @@ var internalPlugin = function internalPlugin(options) {
268
271
  };
269
272
  };
270
273
 
274
+ var actions = {
275
+ enterRoom: enterRoom,
276
+ leaveRoom: leaveRoom
277
+ };
278
+
271
279
  function enterRoom(roomId, initialState) {
272
280
  return {
273
281
  type: ACTION_TYPES.ENTER,
@@ -275,44 +283,46 @@ function enterRoom(roomId, initialState) {
275
283
  initialState: initialState
276
284
  };
277
285
  }
286
+
278
287
  function leaveRoom(roomId) {
279
288
  return {
280
289
  type: ACTION_TYPES.LEAVE,
281
290
  roomId: roomId
282
291
  };
283
292
  }
284
- var enhancer = internalPlugin;
293
+
294
+ var enhancer = internalEnhancer;
285
295
 
286
296
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
287
- for (var key in mapping) {
288
- if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") {
297
+ for (var _key2 in mapping) {
298
+ if (process.env.NODE_ENV !== "production" && typeof newState[_key2] === "function") {
289
299
  throw mappingToFunctionIsNotAllowed("value");
290
300
  }
291
301
 
292
- if (oldState[key] !== newState[key]) {
293
- client.patchLiveObjectKey(root, key, oldState[key], newState[key]);
302
+ if (oldState[_key2] !== newState[_key2]) {
303
+ patchLiveObjectKey(root, _key2, oldState[_key2], newState[_key2]);
294
304
  }
295
305
  }
296
306
  }
297
307
 
298
308
  function broadcastInitialPresence(room, state, mapping) {
299
- for (var key in mapping) {
309
+ for (var _key3 in mapping) {
300
310
  var _room$updatePresence;
301
311
 
302
- room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[key] = state[key], _room$updatePresence));
312
+ room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key3] = state[_key3], _room$updatePresence));
303
313
  }
304
314
  }
305
315
 
306
316
  function updatePresence(room, oldState, newState, presenceMapping) {
307
- for (var key in presenceMapping) {
308
- if (typeof newState[key] === "function") {
317
+ for (var _key4 in presenceMapping) {
318
+ if (typeof newState[_key4] === "function") {
309
319
  throw mappingToFunctionIsNotAllowed("value");
310
320
  }
311
321
 
312
- if (oldState[key] !== newState[key]) {
322
+ if (oldState[_key4] !== newState[_key4]) {
313
323
  var _room$updatePresence2;
314
324
 
315
- room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[key] = newState[key], _room$updatePresence2));
325
+ room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key4] = newState[_key4], _room$updatePresence2));
316
326
  }
317
327
  }
318
328
  }
@@ -322,9 +332,9 @@ function isObject(value) {
322
332
  }
323
333
 
324
334
  function validateNoDuplicateKeys(storageMapping, presenceMapping) {
325
- for (var key in storageMapping) {
326
- if (presenceMapping[key] !== undefined) {
327
- throw mappingShouldNotHaveTheSameKeys(key);
335
+ for (var _key5 in storageMapping) {
336
+ if (presenceMapping[_key5] !== undefined) {
337
+ throw mappingShouldNotHaveTheSameKeys(_key5);
328
338
  }
329
339
  }
330
340
  }
@@ -332,15 +342,15 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
332
342
  function patchState(state, updates, mapping) {
333
343
  var partialState = {};
334
344
 
335
- for (var key in mapping) {
336
- partialState[key] = state[key];
345
+ for (var _key6 in mapping) {
346
+ partialState[_key6] = state[_key6];
337
347
  }
338
348
 
339
- var patched = client.patchImmutableObject(partialState, updates);
349
+ var patched = patchImmutableObject(partialState, updates);
340
350
  var result = {};
341
351
 
342
- for (var _key in mapping) {
343
- result[_key] = patched[_key];
352
+ for (var _key7 in mapping) {
353
+ result[_key7] = patched[_key7];
344
354
  }
345
355
 
346
356
  return result;
@@ -359,19 +369,18 @@ function validateMapping(mapping, mappingType) {
359
369
 
360
370
  var result = {};
361
371
 
362
- for (var key in mapping) {
363
- if (process.env.NODE_ENV !== "production" && typeof mapping[key] !== "boolean") {
364
- throw mappingValueShouldBeABoolean(mappingType, key);
372
+ for (var _key8 in mapping) {
373
+ if (process.env.NODE_ENV !== "production" && typeof mapping[_key8] !== "boolean") {
374
+ throw mappingValueShouldBeABoolean(mappingType, _key8);
365
375
  }
366
376
 
367
- if (mapping[key] === true) {
368
- result[key] = true;
377
+ if (mapping[_key8] === true) {
378
+ result[_key8] = true;
369
379
  }
370
380
  }
371
381
 
372
382
  return result;
373
383
  }
374
384
 
385
+ exports.actions = actions;
375
386
  exports.enhancer = enhancer;
376
- exports.enterRoom = enterRoom;
377
- exports.leaveRoom = leaveRoom;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/redux",
3
- "version": "0.15.0-alpha.3",
3
+ "version": "0.15.1",
4
4
  "sideEffects": false,
5
5
  "description": "",
6
6
  "main": "./lib/index.js",
@@ -36,7 +36,7 @@
36
36
  "directory": "packages/liveblocks-redux"
37
37
  },
38
38
  "peerDependencies": {
39
- "@liveblocks/client": "0.15.0-alpha.3",
39
+ "@liveblocks/client": "0.15.1",
40
40
  "redux": "^4"
41
41
  },
42
42
  "devDependencies": {
@@ -60,4 +60,4 @@
60
60
  "rollup-plugin-esbuild": "^4.8.2",
61
61
  "whatwg-fetch": "^3.6.2"
62
62
  }
63
- }
63
+ }