UNPKG

4.18 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory(require("lodash/lang"));
4 else if(typeof define === 'function' && define.amd)
5 define(["lodash/lang"], factory);
6 else if(typeof exports === 'object')
7 exports["merge.js"] = factory(require("lodash/lang"));
8 else
9 root["merge.js"] = factory(root["lodash/lang"]);
10})(this, function(__WEBPACK_EXTERNAL_MODULE_12__) {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId])
20/******/ return installedModules[moduleId].exports;
21
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ exports: {},
25/******/ id: moduleId,
26/******/ loaded: false
27/******/ };
28
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
32/******/ // Flag the module as loaded
33/******/ module.loaded = true;
34
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38
39
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45
46/******/ // __webpack_public_path__
47/******/ __webpack_require__.p = "";
48
49/******/ // Load entry module and return exports
50/******/ return __webpack_require__(0);
51/******/ })
52/************************************************************************/
53/******/ ({
54
55/***/ 0:
56/***/ function(module, exports, __webpack_require__) {
57
58 'use strict';
59
60 Object.defineProperty(exports, "__esModule", {
61 value: true
62 });
63
64 var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
65
66 exports.default = merge;
67
68 var _lang = __webpack_require__(12);
69
70 function merge(state, stateDiff) {
71 var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
72 var _options$emptyDict = options.emptyDict;
73 var emptyDict = _options$emptyDict === undefined ? 'strict' : _options$emptyDict;
74 var _options$array = options.array;
75 var array = _options$array === undefined ? 'replace' : _options$array;
76
77 // Empty state diffs get special handling. In 'replace' mode they should be
78 // overwriting the current state. In 'skip' mode, we should be 'skipping'
79 // the merge of any objects, and return the current state. In 'strict' mode (default)
80 // we should still be creating a new object.
81
82 if (!Object.keys(stateDiff).length) {
83 if (emptyDict === 'replace') {
84 return stateDiff;
85 } else if (emptyDict === 'skip') {
86 return state;
87 }
88 }
89
90 var newState = _extends({}, state);
91
92 Object.keys(stateDiff).forEach(function (key) {
93 var oldVal = newState[key];
94 var newVal = stateDiff[key];
95 var newValIsEmpty = (0, _lang.isEmpty)(newVal);
96
97 if ((0, _lang.isPlainObject)(oldVal) && (0, _lang.isPlainObject)(newVal)) {
98 if (newValIsEmpty && emptyDict === 'skip') {
99 newState[key] = oldVal;
100 } else if (newValIsEmpty && emptyDict === 'replace') {
101 newState[key] = newVal;
102 } else {
103 newState[key] = merge(oldVal, newVal, options);
104 }
105 } else if (Array.isArray(oldVal) && Array.isArray(newVal)) {
106 if (array === 'concat') {
107 if (!newVal.length) {
108 newState[key] = oldVal;
109 } else {
110 newState[key] = oldVal.concat(newVal);
111 }
112 } else {
113 newState[key] = newVal;
114 }
115 } else {
116 newState[key] = newVal;
117 }
118 });
119
120 return newState;
121 }
122
123/***/ },
124
125/***/ 12:
126/***/ function(module, exports) {
127
128 module.exports = require("lodash/lang");
129
130/***/ }
131
132/******/ })
133});
134;
\No newline at end of file