@liveblocks/redux 0.16.4-beta1 → 0.16.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/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { Client, User, Presence } from "@liveblocks/client";
2
- import { StoreEnhancer } from "redux";
3
- export declare type Mapping<T> = Partial<{
1
+ import { Presence, User, Client } from '@liveblocks/client';
2
+ import { StoreEnhancer } from 'redux';
3
+
4
+ declare type Mapping<T> = Partial<{
4
5
  [Property in keyof T]: boolean;
5
6
  }>;
6
- export declare type LiveblocksState<TState, TPresence extends Presence = Presence> = TState & {
7
+ declare type LiveblocksState<TState, TPresence extends Presence = Presence> = TState & {
7
8
  /**
8
9
  * Liveblocks extra state attached by the enhancer
9
10
  */
@@ -25,7 +26,7 @@ export declare type LiveblocksState<TState, TPresence extends Presence = Presenc
25
26
  /**
26
27
  * Actions used to interact with Liveblocks
27
28
  */
28
- export declare const actions: {
29
+ declare const actions: {
29
30
  /**
30
31
  * Enters a room and starts sync it with zustand state
31
32
  * @param roomId The id of the room
@@ -47,9 +48,10 @@ declare function leaveRoom(roomId: string): {
47
48
  type: string;
48
49
  roomId: string;
49
50
  };
50
- export declare const enhancer: <T>(options: {
51
+ declare const enhancer: <T>(options: {
51
52
  client: Client;
52
53
  storageMapping?: Partial<{ [Property in keyof T]: boolean; }> | undefined;
53
54
  presenceMapping?: Partial<{ [Property in keyof T]: boolean; }> | undefined;
54
55
  }) => StoreEnhancer;
55
- export {};
56
+
57
+ export { LiveblocksState, Mapping, actions, enhancer };
package/index.js CHANGED
@@ -1,397 +1,227 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ });
4
6
 
5
- var client = require('@liveblocks/client');
7
+ var internal = require("@liveblocks/client/internal");
6
8
 
7
9
  function _extends() {
8
- _extends = Object.assign || function (target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
-
12
- for (var key in source) {
13
- if (Object.prototype.hasOwnProperty.call(source, key)) {
14
- target[key] = source[key];
15
- }
16
- }
17
- }
18
-
19
- return target;
20
- };
21
-
22
- return _extends.apply(this, arguments);
23
- }
24
-
25
- function _unsupportedIterableToArray(o, minLen) {
26
- if (!o) return;
27
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
28
- var n = Object.prototype.toString.call(o).slice(8, -1);
29
- if (n === "Object" && o.constructor) n = o.constructor.name;
30
- if (n === "Map" || n === "Set") return Array.from(o);
31
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
10
+ return _extends = Object.assign || function(target) {
11
+ for (var i = 1; i < arguments.length; i++) {
12
+ var source = arguments[i];
13
+ for (var key in source) Object.prototype.hasOwnProperty.call(source, key) && (target[key] = source[key]);
14
+ }
15
+ return target;
16
+ }, _extends.apply(this, arguments);
32
17
  }
33
18
 
34
19
  function _arrayLikeToArray(arr, len) {
35
- if (len == null || len > arr.length) len = arr.length;
36
-
37
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
38
-
39
- return arr2;
20
+ (null == len || len > arr.length) && (len = arr.length);
21
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
22
+ return arr2;
40
23
  }
41
24
 
42
25
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
43
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
44
- if (it) return (it = it.call(o)).next.bind(it);
45
-
46
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
47
- if (it) o = it;
48
- var i = 0;
49
- return function () {
50
- if (i >= o.length) return {
51
- done: true
52
- };
53
- return {
54
- done: false,
55
- value: o[i++]
56
- };
57
- };
26
+ var it = "undefined" != typeof Symbol && o[Symbol.iterator] || o["@@iterator"];
27
+ if (it) return (it = it.call(o)).next.bind(it);
28
+ if (Array.isArray(o) || (it = function(o, minLen) {
29
+ if (o) {
30
+ if ("string" == typeof o) return _arrayLikeToArray(o, minLen);
31
+ var n = Object.prototype.toString.call(o).slice(8, -1);
32
+ return "Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n ? Array.from(o) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? _arrayLikeToArray(o, minLen) : void 0;
58
33
  }
59
-
60
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
34
+ }(o)) || allowArrayLike && o && "number" == typeof o.length) {
35
+ it && (o = it);
36
+ var i = 0;
37
+ return function() {
38
+ return i >= o.length ? {
39
+ done: !0
40
+ } : {
41
+ done: !1,
42
+ value: o[i++]
43
+ };
44
+ };
45
+ }
46
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
61
47
  }
62
48
 
63
49
  var ERROR_PREFIX = "Invalid @liveblocks/redux middleware config.";
64
- function missingClient() {
65
- return new Error(ERROR_PREFIX + " client is missing");
66
- }
67
- function mappingShouldBeAnObject(mappingType) {
68
- return new Error(ERROR_PREFIX + " " + mappingType + " should be an object where the values are boolean.");
69
- }
50
+
70
51
  function mappingValueShouldBeABoolean(mappingType, key) {
71
- return new Error(ERROR_PREFIX + " " + mappingType + "." + key + " value should be a boolean");
52
+ return new Error(ERROR_PREFIX + " " + mappingType + "." + key + " value should be a boolean");
72
53
  }
54
+
73
55
  function mappingShouldNotHaveTheSameKeys(key) {
74
- return new Error(ERROR_PREFIX + " \"" + key + "\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.");
56
+ return new Error(ERROR_PREFIX + ' "' + key + "\" is mapped on presenceMapping and storageMapping. A key shouldn't exist on both mapping.");
75
57
  }
58
+
76
59
  function mappingToFunctionIsNotAllowed(key) {
77
- return new Error(ERROR_PREFIX + " mapping." + key + " is invalid. Mapping to a function is not allowed.");
60
+ return new Error(ERROR_PREFIX + " mapping." + key + " is invalid. Mapping to a function is not allowed.");
78
61
  }
79
62
 
80
- var patchImmutableObject = client.internals.patchImmutableObject,
81
- patchLiveObjectKey = client.internals.patchLiveObjectKey,
82
- lsonToJson = client.internals.lsonToJson;
83
- var ACTION_TYPES = {
84
- ENTER: "@@LIVEBLOCKS/ENTER",
85
- LEAVE: "@@LIVEBLOCKS/LEAVE",
86
- START_LOADING_STORAGE: "@@LIVEBLOCKS/START_LOADING_STORAGE",
87
- INIT_STORAGE: "@@LIVEBLOCKS/INIT_STORAGE",
88
- PATCH_REDUX_STATE: "@@LIVEBLOCKS/PATCH_REDUX_STATE",
89
- UPDATE_CONNECTION: "@@LIVEBLOCKS/UPDATE_CONNECTION",
90
- UPDATE_OTHERS: "@@LIVEBLOCKS/UPDATE_OTHERS"
63
+ var ACTION_TYPES_ENTER = "@@LIVEBLOCKS/ENTER", ACTION_TYPES_LEAVE = "@@LIVEBLOCKS/LEAVE", ACTION_TYPES_START_LOADING_STORAGE = "@@LIVEBLOCKS/START_LOADING_STORAGE", ACTION_TYPES_INIT_STORAGE = "@@LIVEBLOCKS/INIT_STORAGE", ACTION_TYPES_PATCH_REDUX_STATE = "@@LIVEBLOCKS/PATCH_REDUX_STATE", ACTION_TYPES_UPDATE_CONNECTION = "@@LIVEBLOCKS/UPDATE_CONNECTION", ACTION_TYPES_UPDATE_OTHERS = "@@LIVEBLOCKS/UPDATE_OTHERS", actions = {
64
+ enterRoom: function(roomId, initialState) {
65
+ return {
66
+ type: ACTION_TYPES_ENTER,
67
+ roomId: roomId,
68
+ initialState: initialState
69
+ };
70
+ },
71
+ leaveRoom: function(roomId) {
72
+ return {
73
+ type: ACTION_TYPES_LEAVE,
74
+ roomId: roomId
75
+ };
76
+ }
91
77
  };
92
78
 
93
- var internalEnhancer = function internalEnhancer(options) {
94
- if (process.env.NODE_ENV !== "production" && options.client == null) {
95
- throw missingClient();
96
- }
97
-
98
- var client = options.client;
99
- var mapping = validateMapping(options.storageMapping || {}, "storageMapping");
100
- var presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
101
-
102
- if (process.env.NODE_ENV !== "production") {
103
- validateNoDuplicateKeys(mapping, presenceMapping);
104
- }
105
-
106
- return function (createStore) {
107
- return function (reducer, initialState, enhancer) {
108
- var room = null;
109
- var isPatching = false;
110
- var storageRoot = null;
111
- var unsubscribeCallbacks = [];
112
-
113
- var newReducer = function newReducer(state, action) {
114
- switch (action.type) {
115
- case ACTION_TYPES.PATCH_REDUX_STATE:
116
- return _extends({}, state, action.state);
117
-
118
- case ACTION_TYPES.INIT_STORAGE:
119
- return _extends({}, state, action.state, {
120
- liveblocks: _extends({}, state.liveblocks, {
121
- isStorageLoading: false
122
- })
123
- });
124
-
125
- case ACTION_TYPES.START_LOADING_STORAGE:
126
- return _extends({}, state, {
127
- liveblocks: _extends({}, state.liveblocks, {
128
- isStorageLoading: true
129
- })
130
- });
131
-
132
- case ACTION_TYPES.UPDATE_CONNECTION:
133
- {
134
- return _extends({}, state, {
135
- liveblocks: _extends({}, state.liveblocks, {
136
- connection: action.connection
137
- })
138
- });
139
- }
140
-
141
- case ACTION_TYPES.UPDATE_OTHERS:
142
- {
143
- return _extends({}, state, {
144
- liveblocks: _extends({}, state.liveblocks, {
145
- others: action.others
146
- })
147
- });
148
- }
149
-
150
- default:
151
- {
152
- var newState = reducer(state, action);
153
-
154
- if (room) {
155
- isPatching = true;
156
- updatePresence(room, state, newState, presenceMapping);
157
- room.batch(function () {
158
- if (storageRoot) {
159
- patchLiveblocksStorage(storageRoot, state, newState, mapping);
160
- }
161
- });
162
- isPatching = false;
163
- }
164
-
165
- if (newState.liveblocks == null) {
166
- return _extends({}, newState, {
167
- liveblocks: {
168
- others: [],
169
- isStorageLoading: false,
170
- connection: "closed"
171
- }
172
- });
173
- }
174
-
175
- return newState;
176
- }
177
- }
178
- };
179
-
180
- var store = createStore(newReducer, initialState, enhancer);
181
-
182
- function enterRoom(roomId, storageInitialState, reduxState) {
183
- if (storageInitialState === void 0) {
184
- storageInitialState = {};
185
- }
186
-
187
- if (storageRoot) {
188
- return;
189
- }
190
-
191
- room = client.enter(roomId);
192
- broadcastInitialPresence(room, reduxState, presenceMapping);
193
- unsubscribeCallbacks.push(room.subscribe("connection", function () {
194
- store.dispatch({
195
- type: ACTION_TYPES.UPDATE_CONNECTION,
196
- connection: room.getConnectionState()
197
- });
198
- }));
199
- unsubscribeCallbacks.push(room.subscribe("others", function (others) {
200
- store.dispatch({
201
- type: ACTION_TYPES.UPDATE_OTHERS,
202
- others: others.toArray()
203
- });
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
- }));
213
- store.dispatch({
214
- type: ACTION_TYPES.START_LOADING_STORAGE
215
- });
216
- room.getStorage().then(function (_ref) {
217
- var root = _ref.root;
218
- var updates = {};
219
- room.batch(function () {
220
- for (var _key in mapping) {
221
- var liveblocksStatePart = root.get(_key);
222
-
223
- if (liveblocksStatePart == null) {
224
- updates[_key] = storageInitialState[_key];
225
- patchLiveObjectKey(root, _key, undefined, storageInitialState[_key]);
226
- } else {
227
- updates[_key] = lsonToJson(liveblocksStatePart);
228
- }
229
- }
230
- });
231
- store.dispatch({
232
- type: ACTION_TYPES.INIT_STORAGE,
233
- state: updates
234
- });
235
- storageRoot = root;
236
- unsubscribeCallbacks.push(room.subscribe(root, function (updates) {
237
- if (isPatching === false) {
238
- store.dispatch({
239
- type: ACTION_TYPES.PATCH_REDUX_STATE,
240
- state: patchState(store.getState(), updates, mapping)
241
- });
242
- }
243
- }, {
244
- isDeep: true
245
- }));
246
- });
79
+ var enhancer = function(options) {
80
+ if ("production" !== process.env.NODE_ENV && null == options.client) throw new Error(ERROR_PREFIX + " client is missing");
81
+ var client = options.client, mapping = validateMapping(options.storageMapping || {}, "storageMapping"), presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping");
82
+ return "production" !== process.env.NODE_ENV && function(storageMapping, presenceMapping) {
83
+ for (var key in storageMapping) if (void 0 !== presenceMapping[key]) throw mappingShouldNotHaveTheSameKeys(key);
84
+ }(mapping, presenceMapping), function(createStore) {
85
+ return function(reducer, initialState, enhancer) {
86
+ var room = null, isPatching = !1, storageRoot = null, unsubscribeCallbacks = [], store = createStore((function(state, action) {
87
+ switch (action.type) {
88
+ case ACTION_TYPES_PATCH_REDUX_STATE:
89
+ return _extends({}, state, action.state);
90
+
91
+ case ACTION_TYPES_INIT_STORAGE:
92
+ return _extends({}, state, action.state, {
93
+ liveblocks: _extends({}, state.liveblocks, {
94
+ isStorageLoading: !1
95
+ })
96
+ });
97
+
98
+ case ACTION_TYPES_START_LOADING_STORAGE:
99
+ return _extends({}, state, {
100
+ liveblocks: _extends({}, state.liveblocks, {
101
+ isStorageLoading: !0
102
+ })
103
+ });
104
+
105
+ case ACTION_TYPES_UPDATE_CONNECTION:
106
+ return _extends({}, state, {
107
+ liveblocks: _extends({}, state.liveblocks, {
108
+ connection: action.connection
109
+ })
110
+ });
111
+
112
+ case ACTION_TYPES_UPDATE_OTHERS:
113
+ return _extends({}, state, {
114
+ liveblocks: _extends({}, state.liveblocks, {
115
+ others: action.others
116
+ })
117
+ });
118
+
119
+ default:
120
+ var newState = reducer(state, action);
121
+ return room && (isPatching = !0, function(room, oldState, newState, presenceMapping) {
122
+ for (var key in presenceMapping) {
123
+ if ("function" == typeof newState[key]) throw mappingToFunctionIsNotAllowed("value");
124
+ var _room$updatePresence2;
125
+ if (oldState[key] !== newState[key]) room.updatePresence(((_room$updatePresence2 = {})[key] = newState[key],
126
+ _room$updatePresence2));
247
127
  }
248
-
249
- function leaveRoom(roomId) {
250
- for (var _iterator = _createForOfIteratorHelperLoose(unsubscribeCallbacks), _step; !(_step = _iterator()).done;) {
251
- var unsubscribe = _step.value;
252
- unsubscribe();
253
- }
254
-
255
- storageRoot = null;
256
- room = null;
257
- isPatching = false;
258
- unsubscribeCallbacks = [];
259
- client.leave(roomId);
128
+ }(room, state, newState, presenceMapping), room.batch((function() {
129
+ storageRoot && function(root, oldState, newState, mapping) {
130
+ for (var key in mapping) {
131
+ if ("production" !== process.env.NODE_ENV && "function" == typeof newState[key]) throw mappingToFunctionIsNotAllowed("value");
132
+ oldState[key] !== newState[key] && internal.patchLiveObjectKey(root, key, oldState[key], newState[key]);
133
+ }
134
+ }(storageRoot, state, newState, mapping);
135
+ })), isPatching = !1), null == newState.liveblocks ? _extends({}, newState, {
136
+ liveblocks: {
137
+ others: [],
138
+ isStorageLoading: !1,
139
+ connection: "closed"
260
140
  }
261
-
262
- function newDispatch(action, state) {
263
- if (action.type === ACTION_TYPES.ENTER) {
264
- enterRoom(action.roomId, action.initialState, store.getState());
265
- } else if (action.type === ACTION_TYPES.LEAVE) {
266
- leaveRoom(action.roomId);
267
- } else {
268
- store.dispatch(action, state);
269
- }
141
+ }) : newState;
142
+ }
143
+ }), initialState, enhancer);
144
+ return _extends({}, store, {
145
+ dispatch: function(action, state) {
146
+ var roomId, storageInitialState, reduxState;
147
+ action.type === ACTION_TYPES_ENTER ? (roomId = action.roomId, storageInitialState = action.initialState,
148
+ reduxState = store.getState(), void 0 === storageInitialState && (storageInitialState = {}),
149
+ storageRoot || (function(room, state, mapping) {
150
+ for (var key in mapping) {
151
+ var _room$updatePresence;
152
+ null == room || room.updatePresence(((_room$updatePresence = {})[key] = state[key],
153
+ _room$updatePresence));
270
154
  }
271
-
272
- return _extends({}, store, {
273
- dispatch: newDispatch
155
+ }(room = client.enter(roomId), reduxState, presenceMapping), unsubscribeCallbacks.push(room.subscribe("connection", (function() {
156
+ store.dispatch({
157
+ type: ACTION_TYPES_UPDATE_CONNECTION,
158
+ connection: room.getConnectionState()
159
+ });
160
+ }))), unsubscribeCallbacks.push(room.subscribe("others", (function(others) {
161
+ store.dispatch({
162
+ type: ACTION_TYPES_UPDATE_OTHERS,
163
+ others: others.toArray()
274
164
  });
275
- };
165
+ }))), unsubscribeCallbacks.push(room.subscribe("my-presence", (function() {
166
+ !1 === isPatching && store.dispatch({
167
+ type: ACTION_TYPES_PATCH_REDUX_STATE,
168
+ state: patchPresenceState(room.getPresence(), presenceMapping)
169
+ });
170
+ }))), store.dispatch({
171
+ type: ACTION_TYPES_START_LOADING_STORAGE
172
+ }), room.getStorage().then((function(_ref) {
173
+ var root = _ref.root, updates = {};
174
+ room.batch((function() {
175
+ for (var key in mapping) {
176
+ var liveblocksStatePart = root.get(key);
177
+ null == liveblocksStatePart ? (updates[key] = storageInitialState[key], internal.patchLiveObjectKey(root, key, void 0, storageInitialState[key])) : updates[key] = internal.lsonToJson(liveblocksStatePart);
178
+ }
179
+ })), store.dispatch({
180
+ type: ACTION_TYPES_INIT_STORAGE,
181
+ state: updates
182
+ }), storageRoot = root, unsubscribeCallbacks.push(room.subscribe(root, (function(updates) {
183
+ !1 === isPatching && store.dispatch({
184
+ type: ACTION_TYPES_PATCH_REDUX_STATE,
185
+ state: patchState(store.getState(), updates, mapping)
186
+ });
187
+ }), {
188
+ isDeep: !0
189
+ }));
190
+ })))) : action.type === ACTION_TYPES_LEAVE ? function(roomId) {
191
+ for (var _step, _iterator = _createForOfIteratorHelperLoose(unsubscribeCallbacks); !(_step = _iterator()).done; ) (0,
192
+ _step.value)();
193
+ storageRoot = null, room = null, isPatching = !1, unsubscribeCallbacks = [], client.leave(roomId);
194
+ }(action.roomId) : store.dispatch(action, state);
195
+ }
196
+ });
276
197
  };
198
+ };
277
199
  };
278
200
 
279
- var actions = {
280
- enterRoom: enterRoom,
281
- leaveRoom: leaveRoom
282
- };
283
-
284
- function enterRoom(roomId, initialState) {
285
- return {
286
- type: ACTION_TYPES.ENTER,
287
- roomId: roomId,
288
- initialState: initialState
289
- };
290
- }
291
-
292
- function leaveRoom(roomId) {
293
- return {
294
- type: ACTION_TYPES.LEAVE,
295
- roomId: roomId
296
- };
297
- }
298
-
299
- var enhancer = internalEnhancer;
300
-
301
- function patchLiveblocksStorage(root, oldState, newState, mapping) {
302
- for (var _key2 in mapping) {
303
- if (process.env.NODE_ENV !== "production" && typeof newState[_key2] === "function") {
304
- throw mappingToFunctionIsNotAllowed("value");
305
- }
306
-
307
- if (oldState[_key2] !== newState[_key2]) {
308
- patchLiveObjectKey(root, _key2, oldState[_key2], newState[_key2]);
309
- }
310
- }
311
- }
312
-
313
- function broadcastInitialPresence(room, state, mapping) {
314
- for (var _key3 in mapping) {
315
- var _room$updatePresence;
316
-
317
- room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key3] = state[_key3], _room$updatePresence));
318
- }
319
- }
320
-
321
- function updatePresence(room, oldState, newState, presenceMapping) {
322
- for (var _key4 in presenceMapping) {
323
- if (typeof newState[_key4] === "function") {
324
- throw mappingToFunctionIsNotAllowed("value");
325
- }
326
-
327
- if (oldState[_key4] !== newState[_key4]) {
328
- var _room$updatePresence2;
329
-
330
- room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key4] = newState[_key4], _room$updatePresence2));
331
- }
332
- }
333
- }
334
-
335
- function isObject(value) {
336
- return Object.prototype.toString.call(value) === "[object Object]";
337
- }
338
-
339
- function validateNoDuplicateKeys(storageMapping, presenceMapping) {
340
- for (var _key5 in storageMapping) {
341
- if (presenceMapping[_key5] !== undefined) {
342
- throw mappingShouldNotHaveTheSameKeys(_key5);
343
- }
344
- }
345
- }
346
-
347
201
  function patchPresenceState(presence, mapping) {
348
- var partialState = {};
349
-
350
- for (var _key6 in mapping) {
351
- partialState[_key6] = presence[_key6];
352
- }
353
-
354
- return partialState;
202
+ var partialState = {};
203
+ for (var key in mapping) partialState[key] = presence[key];
204
+ return partialState;
355
205
  }
356
206
 
357
207
  function patchState(state, updates, mapping) {
358
- var partialState = {};
359
-
360
- for (var _key7 in mapping) {
361
- partialState[_key7] = state[_key7];
362
- }
363
-
364
- var patched = patchImmutableObject(partialState, updates);
365
- var result = {};
366
-
367
- for (var _key8 in mapping) {
368
- result[_key8] = patched[_key8];
369
- }
370
-
371
- return result;
208
+ var partialState = {};
209
+ for (var key in mapping) partialState[key] = state[key];
210
+ var patched = internal.patchImmutableObject(partialState, updates), result = {};
211
+ for (var _key in mapping) result[_key] = patched[_key];
212
+ return result;
372
213
  }
373
214
 
374
215
  function validateMapping(mapping, mappingType) {
375
- if (process.env.NODE_ENV !== "production") {
376
- if (!isObject(mapping)) {
377
- throw mappingShouldBeAnObject(mappingType);
378
- }
379
- }
380
-
381
- var result = {};
382
-
383
- for (var _key9 in mapping) {
384
- if (process.env.NODE_ENV !== "production" && typeof mapping[_key9] !== "boolean") {
385
- throw mappingValueShouldBeABoolean(mappingType, _key9);
386
- }
387
-
388
- if (mapping[_key9] === true) {
389
- result[_key9] = true;
390
- }
391
- }
392
-
393
- return result;
216
+ if ("production" !== process.env.NODE_ENV && (value = mapping, "[object Object]" !== Object.prototype.toString.call(value))) throw function(mappingType) {
217
+ return new Error(ERROR_PREFIX + " " + mappingType + " should be an object where the values are boolean.");
218
+ }(mappingType);
219
+ var value, result = {};
220
+ for (var key in mapping) {
221
+ if ("production" !== process.env.NODE_ENV && "boolean" != typeof mapping[key]) throw mappingValueShouldBeABoolean(mappingType, key);
222
+ !0 === mapping[key] && (result[key] = !0);
223
+ }
224
+ return result;
394
225
  }
395
226
 
396
- exports.actions = actions;
397
- exports.enhancer = enhancer;
227
+ exports.actions = actions, exports.enhancer = enhancer;