@liveblocks/redux 0.15.1 → 0.15.5

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/lib/esm/index.js CHANGED
@@ -4,9 +4,6 @@ const ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
4
4
  function missingClient() {
5
5
  return new Error(`${ERROR_PREFIX} client is missing`);
6
6
  }
7
- function missingMapping(mappingType) {
8
- return new Error(`${ERROR_PREFIX} ${mappingType} is missing.`);
9
- }
10
7
  function mappingShouldBeAnObject(mappingType) {
11
8
  return new Error(`${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`);
12
9
  }
@@ -45,7 +42,7 @@ const ACTION_TYPES = {
45
42
  LEAVE: "@@LIVEBLOCKS/LEAVE",
46
43
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
47
44
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
48
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
45
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
49
46
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
50
47
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
51
48
  };
@@ -54,7 +51,7 @@ const internalEnhancer = (options) => {
54
51
  throw missingClient();
55
52
  }
56
53
  const client = options.client;
57
- const mapping = validateMapping(options.storageMapping, "storageMapping");
54
+ const mapping = validateMapping(options.storageMapping || {}, "storageMapping");
58
55
  const presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
59
56
  if (process.env.NODE_ENV !== "production") {
60
57
  validateNoDuplicateKeys(mapping, presenceMapping);
@@ -66,7 +63,7 @@ const internalEnhancer = (options) => {
66
63
  let unsubscribeCallbacks = [];
67
64
  const newReducer = (state, action) => {
68
65
  switch (action.type) {
69
- case ACTION_TYPES.PATCH_STORAGE:
66
+ case ACTION_TYPES.PATCH_REDUX_STATE:
70
67
  return __spreadValues(__spreadValues({}, state), action.state);
71
68
  case ACTION_TYPES.INIT_STORAGE:
72
69
  return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
@@ -138,6 +135,14 @@ const internalEnhancer = (options) => {
138
135
  others: others.toArray()
139
136
  });
140
137
  }));
138
+ unsubscribeCallbacks.push(room.subscribe("my-presence", () => {
139
+ if (isPatching === false) {
140
+ store.dispatch({
141
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
142
+ state: patchPresenceState(room.getPresence(), presenceMapping)
143
+ });
144
+ }
145
+ }));
141
146
  store.dispatch({
142
147
  type: ACTION_TYPES.START_LOADING_STORAGE
143
148
  });
@@ -162,7 +167,7 @@ const internalEnhancer = (options) => {
162
167
  unsubscribeCallbacks.push(room.subscribe(root, (updates2) => {
163
168
  if (isPatching === false) {
164
169
  store.dispatch({
165
- type: ACTION_TYPES.PATCH_STORAGE,
170
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
166
171
  state: patchState(store.getState(), updates2, mapping)
167
172
  });
168
173
  }
@@ -246,6 +251,13 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
246
251
  }
247
252
  }
248
253
  }
254
+ function patchPresenceState(presence, mapping) {
255
+ const partialState = {};
256
+ for (const key in mapping) {
257
+ partialState[key] = presence[key];
258
+ }
259
+ return partialState;
260
+ }
249
261
  function patchState(state, updates, mapping) {
250
262
  const partialState = {};
251
263
  for (const key in mapping) {
@@ -260,9 +272,6 @@ function patchState(state, updates, mapping) {
260
272
  }
261
273
  function validateMapping(mapping, mappingType) {
262
274
  if (process.env.NODE_ENV !== "production") {
263
- if (mapping == null) {
264
- throw missingMapping(mappingType);
265
- }
266
275
  if (!isObject(mapping)) {
267
276
  throw mappingShouldBeAnObject(mappingType);
268
277
  }
package/lib/esm/index.mjs CHANGED
@@ -4,9 +4,6 @@ const ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
4
4
  function missingClient() {
5
5
  return new Error(`${ERROR_PREFIX} client is missing`);
6
6
  }
7
- function missingMapping(mappingType) {
8
- return new Error(`${ERROR_PREFIX} ${mappingType} is missing.`);
9
- }
10
7
  function mappingShouldBeAnObject(mappingType) {
11
8
  return new Error(`${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`);
12
9
  }
@@ -45,7 +42,7 @@ const ACTION_TYPES = {
45
42
  LEAVE: "@@LIVEBLOCKS/LEAVE",
46
43
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
47
44
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
48
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
45
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
49
46
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
50
47
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
51
48
  };
@@ -54,7 +51,7 @@ const internalEnhancer = (options) => {
54
51
  throw missingClient();
55
52
  }
56
53
  const client = options.client;
57
- const mapping = validateMapping(options.storageMapping, "storageMapping");
54
+ const mapping = validateMapping(options.storageMapping || {}, "storageMapping");
58
55
  const presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
59
56
  if (process.env.NODE_ENV !== "production") {
60
57
  validateNoDuplicateKeys(mapping, presenceMapping);
@@ -66,7 +63,7 @@ const internalEnhancer = (options) => {
66
63
  let unsubscribeCallbacks = [];
67
64
  const newReducer = (state, action) => {
68
65
  switch (action.type) {
69
- case ACTION_TYPES.PATCH_STORAGE:
66
+ case ACTION_TYPES.PATCH_REDUX_STATE:
70
67
  return __spreadValues(__spreadValues({}, state), action.state);
71
68
  case ACTION_TYPES.INIT_STORAGE:
72
69
  return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
@@ -138,6 +135,14 @@ const internalEnhancer = (options) => {
138
135
  others: others.toArray()
139
136
  });
140
137
  }));
138
+ unsubscribeCallbacks.push(room.subscribe("my-presence", () => {
139
+ if (isPatching === false) {
140
+ store.dispatch({
141
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
142
+ state: patchPresenceState(room.getPresence(), presenceMapping)
143
+ });
144
+ }
145
+ }));
141
146
  store.dispatch({
142
147
  type: ACTION_TYPES.START_LOADING_STORAGE
143
148
  });
@@ -162,7 +167,7 @@ const internalEnhancer = (options) => {
162
167
  unsubscribeCallbacks.push(room.subscribe(root, (updates2) => {
163
168
  if (isPatching === false) {
164
169
  store.dispatch({
165
- type: ACTION_TYPES.PATCH_STORAGE,
170
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
166
171
  state: patchState(store.getState(), updates2, mapping)
167
172
  });
168
173
  }
@@ -246,6 +251,13 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
246
251
  }
247
252
  }
248
253
  }
254
+ function patchPresenceState(presence, mapping) {
255
+ const partialState = {};
256
+ for (const key in mapping) {
257
+ partialState[key] = presence[key];
258
+ }
259
+ return partialState;
260
+ }
249
261
  function patchState(state, updates, mapping) {
250
262
  const partialState = {};
251
263
  for (const key in mapping) {
@@ -260,9 +272,6 @@ function patchState(state, updates, mapping) {
260
272
  }
261
273
  function validateMapping(mapping, mappingType) {
262
274
  if (process.env.NODE_ENV !== "production") {
263
- if (mapping == null) {
264
- throw missingMapping(mappingType);
265
- }
266
275
  if (!isObject(mapping)) {
267
276
  throw mappingShouldBeAnObject(mappingType);
268
277
  }
package/lib/index.d.ts CHANGED
@@ -49,7 +49,7 @@ declare function leaveRoom(roomId: string): {
49
49
  };
50
50
  export declare const enhancer: <T>(options: {
51
51
  client: Client;
52
- storageMapping: Partial<{ [Property in keyof T]: boolean; }>;
52
+ storageMapping?: Partial<{ [Property in keyof T]: boolean; }> | undefined;
53
53
  presenceMapping?: Partial<{ [Property in keyof T]: boolean; }> | undefined;
54
54
  }) => StoreEnhancer;
55
55
  export {};
package/lib/index.js CHANGED
@@ -64,9 +64,6 @@ var ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
64
64
  function missingClient() {
65
65
  return new Error(ERROR_PREFIX + " client is missing");
66
66
  }
67
- function missingMapping(mappingType) {
68
- return new Error(ERROR_PREFIX + " " + mappingType + " is missing.");
69
- }
70
67
  function mappingShouldBeAnObject(mappingType) {
71
68
  return new Error(ERROR_PREFIX + " " + mappingType + " should be an object where the values are boolean.");
72
69
  }
@@ -88,7 +85,7 @@ var ACTION_TYPES = {
88
85
  LEAVE: "@@LIVEBLOCKS/LEAVE",
89
86
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
90
87
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
91
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
88
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
92
89
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
93
90
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
94
91
  };
@@ -99,7 +96,7 @@ var internalEnhancer = function internalEnhancer(options) {
99
96
  }
100
97
 
101
98
  var client = options.client;
102
- var mapping = validateMapping(options.storageMapping, "storageMapping");
99
+ var mapping = validateMapping(options.storageMapping || {}, "storageMapping");
103
100
  var presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
104
101
 
105
102
  if (process.env.NODE_ENV !== "production") {
@@ -115,7 +112,7 @@ var internalEnhancer = function internalEnhancer(options) {
115
112
 
116
113
  var newReducer = function newReducer(state, action) {
117
114
  switch (action.type) {
118
- case ACTION_TYPES.PATCH_STORAGE:
115
+ case ACTION_TYPES.PATCH_REDUX_STATE:
119
116
  return _extends({}, state, action.state);
120
117
 
121
118
  case ACTION_TYPES.INIT_STORAGE:
@@ -205,6 +202,14 @@ var internalEnhancer = function internalEnhancer(options) {
205
202
  others: others.toArray()
206
203
  });
207
204
  }));
205
+ unsubscribeCallbacks.push(room.subscribe("my-presence", function () {
206
+ if (isPatching === false) {
207
+ store.dispatch({
208
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
209
+ state: patchPresenceState(room.getPresence(), presenceMapping)
210
+ });
211
+ }
212
+ }));
208
213
  store.dispatch({
209
214
  type: ACTION_TYPES.START_LOADING_STORAGE
210
215
  });
@@ -231,7 +236,7 @@ var internalEnhancer = function internalEnhancer(options) {
231
236
  unsubscribeCallbacks.push(room.subscribe(root, function (updates) {
232
237
  if (isPatching === false) {
233
238
  store.dispatch({
234
- type: ACTION_TYPES.PATCH_STORAGE,
239
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
235
240
  state: patchState(store.getState(), updates, mapping)
236
241
  });
237
242
  }
@@ -339,18 +344,28 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
339
344
  }
340
345
  }
341
346
 
342
- function patchState(state, updates, mapping) {
347
+ function patchPresenceState(presence, mapping) {
343
348
  var partialState = {};
344
349
 
345
350
  for (var _key6 in mapping) {
346
- partialState[_key6] = state[_key6];
351
+ partialState[_key6] = presence[_key6];
352
+ }
353
+
354
+ return partialState;
355
+ }
356
+
357
+ function patchState(state, updates, mapping) {
358
+ var partialState = {};
359
+
360
+ for (var _key7 in mapping) {
361
+ partialState[_key7] = state[_key7];
347
362
  }
348
363
 
349
364
  var patched = patchImmutableObject(partialState, updates);
350
365
  var result = {};
351
366
 
352
- for (var _key7 in mapping) {
353
- result[_key7] = patched[_key7];
367
+ for (var _key8 in mapping) {
368
+ result[_key8] = patched[_key8];
354
369
  }
355
370
 
356
371
  return result;
@@ -358,10 +373,6 @@ function patchState(state, updates, mapping) {
358
373
 
359
374
  function validateMapping(mapping, mappingType) {
360
375
  if (process.env.NODE_ENV !== "production") {
361
- if (mapping == null) {
362
- throw missingMapping(mappingType);
363
- }
364
-
365
376
  if (!isObject(mapping)) {
366
377
  throw mappingShouldBeAnObject(mappingType);
367
378
  }
@@ -369,13 +380,13 @@ function validateMapping(mapping, mappingType) {
369
380
 
370
381
  var result = {};
371
382
 
372
- for (var _key8 in mapping) {
373
- if (process.env.NODE_ENV !== "production" && typeof mapping[_key8] !== "boolean") {
374
- throw mappingValueShouldBeABoolean(mappingType, _key8);
383
+ for (var _key9 in mapping) {
384
+ if (process.env.NODE_ENV !== "production" && typeof mapping[_key9] !== "boolean") {
385
+ throw mappingValueShouldBeABoolean(mappingType, _key9);
375
386
  }
376
387
 
377
- if (mapping[_key8] === true) {
378
- result[_key8] = true;
388
+ if (mapping[_key9] === true) {
389
+ result[_key9] = true;
379
390
  }
380
391
  }
381
392
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/redux",
3
- "version": "0.15.1",
3
+ "version": "0.15.5",
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.1",
39
+ "@liveblocks/client": "0.15.5",
40
40
  "redux": "^4"
41
41
  },
42
42
  "devDependencies": {