@liveblocks/redux 0.15.3 → 0.15.6

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
@@ -42,7 +42,7 @@ const ACTION_TYPES = {
42
42
  LEAVE: "@@LIVEBLOCKS/LEAVE",
43
43
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
44
44
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
45
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
45
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
46
46
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
47
47
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
48
48
  };
@@ -63,7 +63,7 @@ const internalEnhancer = (options) => {
63
63
  let unsubscribeCallbacks = [];
64
64
  const newReducer = (state, action) => {
65
65
  switch (action.type) {
66
- case ACTION_TYPES.PATCH_STORAGE:
66
+ case ACTION_TYPES.PATCH_REDUX_STATE:
67
67
  return __spreadValues(__spreadValues({}, state), action.state);
68
68
  case ACTION_TYPES.INIT_STORAGE:
69
69
  return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
@@ -135,6 +135,14 @@ const internalEnhancer = (options) => {
135
135
  others: others.toArray()
136
136
  });
137
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
+ }));
138
146
  store.dispatch({
139
147
  type: ACTION_TYPES.START_LOADING_STORAGE
140
148
  });
@@ -159,7 +167,7 @@ const internalEnhancer = (options) => {
159
167
  unsubscribeCallbacks.push(room.subscribe(root, (updates2) => {
160
168
  if (isPatching === false) {
161
169
  store.dispatch({
162
- type: ACTION_TYPES.PATCH_STORAGE,
170
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
163
171
  state: patchState(store.getState(), updates2, mapping)
164
172
  });
165
173
  }
@@ -243,6 +251,13 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
243
251
  }
244
252
  }
245
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
+ }
246
261
  function patchState(state, updates, mapping) {
247
262
  const partialState = {};
248
263
  for (const key in mapping) {
package/lib/esm/index.mjs CHANGED
@@ -42,7 +42,7 @@ const ACTION_TYPES = {
42
42
  LEAVE: "@@LIVEBLOCKS/LEAVE",
43
43
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
44
44
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
45
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
45
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
46
46
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
47
47
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
48
48
  };
@@ -63,7 +63,7 @@ const internalEnhancer = (options) => {
63
63
  let unsubscribeCallbacks = [];
64
64
  const newReducer = (state, action) => {
65
65
  switch (action.type) {
66
- case ACTION_TYPES.PATCH_STORAGE:
66
+ case ACTION_TYPES.PATCH_REDUX_STATE:
67
67
  return __spreadValues(__spreadValues({}, state), action.state);
68
68
  case ACTION_TYPES.INIT_STORAGE:
69
69
  return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
@@ -135,6 +135,14 @@ const internalEnhancer = (options) => {
135
135
  others: others.toArray()
136
136
  });
137
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
+ }));
138
146
  store.dispatch({
139
147
  type: ACTION_TYPES.START_LOADING_STORAGE
140
148
  });
@@ -159,7 +167,7 @@ const internalEnhancer = (options) => {
159
167
  unsubscribeCallbacks.push(room.subscribe(root, (updates2) => {
160
168
  if (isPatching === false) {
161
169
  store.dispatch({
162
- type: ACTION_TYPES.PATCH_STORAGE,
170
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
163
171
  state: patchState(store.getState(), updates2, mapping)
164
172
  });
165
173
  }
@@ -243,6 +251,13 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
243
251
  }
244
252
  }
245
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
+ }
246
261
  function patchState(state, updates, mapping) {
247
262
  const partialState = {};
248
263
  for (const key in mapping) {
package/lib/index.js CHANGED
@@ -85,7 +85,7 @@ var ACTION_TYPES = {
85
85
  LEAVE: "@@LIVEBLOCKS/LEAVE",
86
86
  START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
87
87
  INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
88
- PATCH_STORAGE: "@@LIVEBLOCKS/PATCH_STORAGE",
88
+ PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
89
89
  UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
90
90
  UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
91
91
  };
@@ -112,7 +112,7 @@ var internalEnhancer = function internalEnhancer(options) {
112
112
 
113
113
  var newReducer = function newReducer(state, action) {
114
114
  switch (action.type) {
115
- case ACTION_TYPES.PATCH_STORAGE:
115
+ case ACTION_TYPES.PATCH_REDUX_STATE:
116
116
  return _extends({}, state, action.state);
117
117
 
118
118
  case ACTION_TYPES.INIT_STORAGE:
@@ -202,6 +202,14 @@ var internalEnhancer = function internalEnhancer(options) {
202
202
  others: others.toArray()
203
203
  });
204
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
+ }));
205
213
  store.dispatch({
206
214
  type: ACTION_TYPES.START_LOADING_STORAGE
207
215
  });
@@ -228,7 +236,7 @@ var internalEnhancer = function internalEnhancer(options) {
228
236
  unsubscribeCallbacks.push(room.subscribe(root, function (updates) {
229
237
  if (isPatching === false) {
230
238
  store.dispatch({
231
- type: ACTION_TYPES.PATCH_STORAGE,
239
+ type: ACTION_TYPES.PATCH_REDUX_STATE,
232
240
  state: patchState(store.getState(), updates, mapping)
233
241
  });
234
242
  }
@@ -336,18 +344,28 @@ function validateNoDuplicateKeys(storageMapping, presenceMapping) {
336
344
  }
337
345
  }
338
346
 
339
- function patchState(state, updates, mapping) {
347
+ function patchPresenceState(presence, mapping) {
340
348
  var partialState = {};
341
349
 
342
350
  for (var _key6 in mapping) {
343
- 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];
344
362
  }
345
363
 
346
364
  var patched = patchImmutableObject(partialState, updates);
347
365
  var result = {};
348
366
 
349
- for (var _key7 in mapping) {
350
- result[_key7] = patched[_key7];
367
+ for (var _key8 in mapping) {
368
+ result[_key8] = patched[_key8];
351
369
  }
352
370
 
353
371
  return result;
@@ -362,13 +380,13 @@ function validateMapping(mapping, mappingType) {
362
380
 
363
381
  var result = {};
364
382
 
365
- for (var _key8 in mapping) {
366
- if (process.env.NODE_ENV !== "production" && typeof mapping[_key8] !== "boolean") {
367
- 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);
368
386
  }
369
387
 
370
- if (mapping[_key8] === true) {
371
- result[_key8] = true;
388
+ if (mapping[_key9] === true) {
389
+ result[_key9] = true;
372
390
  }
373
391
  }
374
392
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/redux",
3
- "version": "0.15.3",
3
+ "version": "0.15.6",
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.3",
39
+ "@liveblocks/client": "0.15.5",
40
40
  "redux": "^4"
41
41
  },
42
42
  "devDependencies": {