@liveblocks/zustand 0.16.4-beta2 → 0.16.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.
Files changed (3) hide show
  1. package/index.js +31 -34
  2. package/index.mjs +1 -2
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('@liveblocks/client');
5
+ var internal = require('@liveblocks/client/internal');
6
6
 
7
7
  function _extends() {
8
8
  _extends = Object.assign || function (target) {
@@ -80,9 +80,6 @@ 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 patchLiveObjectKey = client.internals.patchLiveObjectKey,
84
- patchImmutableObject = client.internals.patchImmutableObject,
85
- lsonToJson = client.internals.lsonToJson;
86
83
  function middleware(config, options) {
87
84
  if (process.env.NODE_ENV !== "production" && options.client == null) {
88
85
  throw missingClient();
@@ -150,14 +147,14 @@ function middleware(config, options) {
150
147
  var root = _ref.root;
151
148
  var updates = {};
152
149
  room.batch(function () {
153
- for (var _key in storageMapping) {
154
- var liveblocksStatePart = root.get(_key);
150
+ for (var key in storageMapping) {
151
+ var liveblocksStatePart = root.get(key);
155
152
 
156
153
  if (liveblocksStatePart == null) {
157
- updates[_key] = initialState[_key];
158
- patchLiveObjectKey(root, _key, undefined, initialState[_key]);
154
+ updates[key] = initialState[key];
155
+ internal.patchLiveObjectKey(root, key, undefined, initialState[key]);
159
156
  } else {
160
- updates[_key] = lsonToJson(liveblocksStatePart);
157
+ updates[key] = internal.lsonToJson(liveblocksStatePart);
161
158
  }
162
159
  }
163
160
  });
@@ -211,15 +208,15 @@ function middleware(config, options) {
211
208
  function patchState(state, updates, mapping) {
212
209
  var partialState = {};
213
210
 
214
- for (var _key2 in mapping) {
215
- partialState[_key2] = state[_key2];
211
+ for (var key in mapping) {
212
+ partialState[key] = state[key];
216
213
  }
217
214
 
218
- var patched = patchImmutableObject(partialState, updates);
215
+ var patched = internal.patchImmutableObject(partialState, updates);
219
216
  var result = {};
220
217
 
221
- for (var _key3 in mapping) {
222
- result[_key3] = patched[_key3];
218
+ for (var _key in mapping) {
219
+ result[_key] = patched[_key];
223
220
  }
224
221
 
225
222
  return result;
@@ -228,8 +225,8 @@ function patchState(state, updates, mapping) {
228
225
  function patchPresenceState(presence, mapping) {
229
226
  var partialState = {};
230
227
 
231
- for (var _key4 in mapping) {
232
- partialState[_key4] = presence[_key4];
228
+ for (var key in mapping) {
229
+ partialState[key] = presence[key];
233
230
  }
234
231
 
235
232
  return partialState;
@@ -244,35 +241,35 @@ function updateZustandLiveblocksState(set, partial) {
244
241
  }
245
242
 
246
243
  function broadcastInitialPresence(room, state, mapping) {
247
- for (var _key5 in mapping) {
244
+ for (var key in mapping) {
248
245
  var _room$updatePresence;
249
246
 
250
- room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key5] = state[_key5], _room$updatePresence));
247
+ room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[key] = state[key], _room$updatePresence));
251
248
  }
252
249
  }
253
250
 
254
251
  function updatePresence(room, oldState, newState, presenceMapping) {
255
- for (var _key6 in presenceMapping) {
256
- if (typeof newState[_key6] === "function") {
252
+ for (var key in presenceMapping) {
253
+ if (typeof newState[key] === "function") {
257
254
  throw mappingToFunctionIsNotAllowed("value");
258
255
  }
259
256
 
260
- if (oldState[_key6] !== newState[_key6]) {
257
+ if (oldState[key] !== newState[key]) {
261
258
  var _room$updatePresence2;
262
259
 
263
- room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key6] = newState[_key6], _room$updatePresence2));
260
+ room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[key] = newState[key], _room$updatePresence2));
264
261
  }
265
262
  }
266
263
  }
267
264
 
268
265
  function patchLiveblocksStorage(root, oldState, newState, mapping) {
269
- for (var _key7 in mapping) {
270
- if (process.env.NODE_ENV !== "production" && typeof newState[_key7] === "function") {
266
+ for (var key in mapping) {
267
+ if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") {
271
268
  throw mappingToFunctionIsNotAllowed("value");
272
269
  }
273
270
 
274
- if (oldState[_key7] !== newState[_key7]) {
275
- patchLiveObjectKey(root, _key7, oldState[_key7], newState[_key7]);
271
+ if (oldState[key] !== newState[key]) {
272
+ internal.patchLiveObjectKey(root, key, oldState[key], newState[key]);
276
273
  }
277
274
  }
278
275
  }
@@ -282,9 +279,9 @@ function isObject(value) {
282
279
  }
283
280
 
284
281
  function validateNoDuplicateKeys(storageMapping, presenceMapping) {
285
- for (var _key8 in storageMapping) {
286
- if (presenceMapping[_key8] !== undefined) {
287
- throw mappingShouldNotHaveTheSameKeys(_key8);
282
+ for (var key in storageMapping) {
283
+ if (presenceMapping[key] !== undefined) {
284
+ throw mappingShouldNotHaveTheSameKeys(key);
288
285
  }
289
286
  }
290
287
  }
@@ -302,13 +299,13 @@ function validateMapping(mapping, mappingType) {
302
299
 
303
300
  var result = {};
304
301
 
305
- for (var _key9 in mapping) {
306
- if (process.env.NODE_ENV !== "production" && typeof mapping[_key9] !== "boolean") {
307
- throw mappingValueShouldBeABoolean(mappingType, _key9);
302
+ for (var key in mapping) {
303
+ if (process.env.NODE_ENV !== "production" && typeof mapping[key] !== "boolean") {
304
+ throw mappingValueShouldBeABoolean(mappingType, key);
308
305
  }
309
306
 
310
- if (mapping[_key9] === true) {
311
- result[_key9] = true;
307
+ if (mapping[key] === true) {
308
+ result[key] = true;
312
309
  }
313
310
  }
314
311
 
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { internals } from '@liveblocks/client';
1
+ import { patchLiveObjectKey, lsonToJson, patchImmutableObject } from '@liveblocks/client/internal';
2
2
 
3
3
  const ERROR_PREFIX = "Invalid @liveblocks/zustand middleware config.";
4
4
  function missingClient() {
@@ -20,7 +20,6 @@ function mappingToFunctionIsNotAllowed(key) {
20
20
  return new Error(`${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`);
21
21
  }
22
22
 
23
- const { patchLiveObjectKey, patchImmutableObject, lsonToJson } = internals;
24
23
  function middleware(config, options) {
25
24
  if (process.env.NODE_ENV !== "production" && options.client == null) {
26
25
  throw missingClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/zustand",
3
- "version": "0.16.4-beta2",
3
+ "version": "0.16.4",
4
4
  "description": "A middleware to integrate Liveblocks into Zustand stores.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -30,7 +30,7 @@
30
30
  "directory": "packages/liveblocks-zustand"
31
31
  },
32
32
  "peerDependencies": {
33
- "@liveblocks/client": "0.16.4-beta2",
33
+ "@liveblocks/client": "0.16.4",
34
34
  "zustand": "^3"
35
35
  },
36
36
  "devDependencies": {