@liveblocks/zustand 0.15.0 → 0.15.4

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/zustand
15
+ ```
16
+
17
+ ## Documentation
18
+
19
+ - Start with the [React-Zustand guide](https://liveblocks.io/docs/get-started/react-zustand).
20
+ - Explore the [API Reference](https://liveblocks.io/docs/api-reference/liveblocks-zustand).
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
@@ -87,6 +87,11 @@ function middleware(config, options) {
87
87
  connection: room.getConnectionState()
88
88
  });
89
89
  }));
90
+ unsubscribeCallbacks.push(room.subscribe("my-presence", () => {
91
+ if (isPatching === false) {
92
+ set(patchPresenceState(room.getPresence(), presenceMapping));
93
+ }
94
+ }));
90
95
  room.getStorage().then(({ root }) => {
91
96
  const updates = {};
92
97
  room.batch(() => {
@@ -150,6 +155,13 @@ function patchState(state, updates, mapping) {
150
155
  }
151
156
  return result;
152
157
  }
158
+ function patchPresenceState(presence, mapping) {
159
+ const partialState = {};
160
+ for (const key in mapping) {
161
+ partialState[key] = presence[key];
162
+ }
163
+ return partialState;
164
+ }
153
165
  function updateZustandLiveblocksState(set, partial) {
154
166
  set((state) => ({ liveblocks: __spreadValues(__spreadValues({}, state.liveblocks), partial) }));
155
167
  }
package/lib/esm/index.mjs CHANGED
@@ -87,6 +87,11 @@ function middleware(config, options) {
87
87
  connection: room.getConnectionState()
88
88
  });
89
89
  }));
90
+ unsubscribeCallbacks.push(room.subscribe("my-presence", () => {
91
+ if (isPatching === false) {
92
+ set(patchPresenceState(room.getPresence(), presenceMapping));
93
+ }
94
+ }));
90
95
  room.getStorage().then(({ root }) => {
91
96
  const updates = {};
92
97
  room.batch(() => {
@@ -150,6 +155,13 @@ function patchState(state, updates, mapping) {
150
155
  }
151
156
  return result;
152
157
  }
158
+ function patchPresenceState(presence, mapping) {
159
+ const partialState = {};
160
+ for (const key in mapping) {
161
+ partialState[key] = presence[key];
162
+ }
163
+ return partialState;
164
+ }
153
165
  function updateZustandLiveblocksState(set, partial) {
154
166
  set((state) => ({ liveblocks: __spreadValues(__spreadValues({}, state.liveblocks), partial) }));
155
167
  }
package/lib/index.js CHANGED
@@ -141,6 +141,11 @@ function middleware(config, options) {
141
141
  connection: room.getConnectionState()
142
142
  });
143
143
  }));
144
+ unsubscribeCallbacks.push(room.subscribe("my-presence", function () {
145
+ if (isPatching === false) {
146
+ set(patchPresenceState(room.getPresence(), presenceMapping));
147
+ }
148
+ }));
144
149
  room.getStorage().then(function (_ref) {
145
150
  var root = _ref.root;
146
151
  var updates = {};
@@ -220,6 +225,16 @@ function patchState(state, updates, mapping) {
220
225
  return result;
221
226
  }
222
227
 
228
+ function patchPresenceState(presence, mapping) {
229
+ var partialState = {};
230
+
231
+ for (var _key4 in mapping) {
232
+ partialState[_key4] = presence[_key4];
233
+ }
234
+
235
+ return partialState;
236
+ }
237
+
223
238
  function updateZustandLiveblocksState(set, partial) {
224
239
  set(function (state) {
225
240
  return {
@@ -229,35 +244,35 @@ function updateZustandLiveblocksState(set, partial) {
229
244
  }
230
245
 
231
246
  function broadcastInitialPresence(room, state, mapping) {
232
- for (var _key4 in mapping) {
247
+ for (var _key5 in mapping) {
233
248
  var _room$updatePresence;
234
249
 
235
- room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key4] = state[_key4], _room$updatePresence));
250
+ room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key5] = state[_key5], _room$updatePresence));
236
251
  }
237
252
  }
238
253
 
239
254
  function updatePresence(room, oldState, newState, presenceMapping) {
240
- for (var _key5 in presenceMapping) {
241
- if (typeof newState[_key5] === "function") {
255
+ for (var _key6 in presenceMapping) {
256
+ if (typeof newState[_key6] === "function") {
242
257
  throw mappingToFunctionIsNotAllowed("value");
243
258
  }
244
259
 
245
- if (oldState[_key5] !== newState[_key5]) {
260
+ if (oldState[_key6] !== newState[_key6]) {
246
261
  var _room$updatePresence2;
247
262
 
248
- room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key5] = newState[_key5], _room$updatePresence2));
263
+ room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key6] = newState[_key6], _room$updatePresence2));
249
264
  }
250
265
  }
251
266
  }
252
267
 
253
268
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
254
- for (var _key6 in mapping) {
255
- if (process.env.NODE_ENV !== "production" && typeof newState[_key6] === "function") {
269
+ for (var _key7 in mapping) {
270
+ if (process.env.NODE_ENV !== "production" && typeof newState[_key7] === "function") {
256
271
  throw mappingToFunctionIsNotAllowed("value");
257
272
  }
258
273
 
259
- if (oldState[_key6] !== newState[_key6]) {
260
- patchLiveObjectKey(root, _key6, oldState[_key6], newState[_key6]);
274
+ if (oldState[_key7] !== newState[_key7]) {
275
+ patchLiveObjectKey(root, _key7, oldState[_key7], newState[_key7]);
261
276
  }
262
277
  }
263
278
  }
@@ -267,9 +282,9 @@ function isObject(value) {
267
282
  }
268
283
 
269
284
  function validateNoDuplicateKeys(storageMapping, presenceMapping) {
270
- for (var _key7 in storageMapping) {
271
- if (presenceMapping[_key7] !== undefined) {
272
- throw mappingShouldNotHaveTheSameKeys(_key7);
285
+ for (var _key8 in storageMapping) {
286
+ if (presenceMapping[_key8] !== undefined) {
287
+ throw mappingShouldNotHaveTheSameKeys(_key8);
273
288
  }
274
289
  }
275
290
  }
@@ -287,13 +302,13 @@ function validateMapping(mapping, mappingType) {
287
302
 
288
303
  var result = {};
289
304
 
290
- for (var _key8 in mapping) {
291
- if (process.env.NODE_ENV !== "production" && typeof mapping[_key8] !== "boolean") {
292
- throw mappingValueShouldBeABoolean(mappingType, _key8);
305
+ for (var _key9 in mapping) {
306
+ if (process.env.NODE_ENV !== "production" && typeof mapping[_key9] !== "boolean") {
307
+ throw mappingValueShouldBeABoolean(mappingType, _key9);
293
308
  }
294
309
 
295
- if (mapping[_key8] === true) {
296
- result[_key8] = true;
310
+ if (mapping[_key9] === true) {
311
+ result[_key9] = true;
297
312
  }
298
313
  }
299
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/zustand",
3
- "version": "0.15.0",
3
+ "version": "0.15.4",
4
4
  "sideEffects": false,
5
5
  "description": "",
6
6
  "main": "./lib/index.js",
@@ -36,7 +36,7 @@
36
36
  "directory": "packages/liveblocks-zustand"
37
37
  },
38
38
  "peerDependencies": {
39
- "@liveblocks/client": "0.15.0",
39
+ "@liveblocks/client": "0.15.4",
40
40
  "zustand": "^3"
41
41
  },
42
42
  "devDependencies": {
@@ -59,4 +59,4 @@
59
59
  "whatwg-fetch": "^3.6.2",
60
60
  "zustand": "^3.6.9"
61
61
  }
62
- }
62
+ }