Skip to content

Commit 9e3ea00

Browse files
Merge configs using lodash merge
Fixes #97
1 parent 41bdb59 commit 9e3ea00

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@
4242
},
4343
"dependencies": {
4444
"@vuex-orm/core": "^0.32.5",
45-
"axios": "^0.19.0"
45+
"axios": "^0.19.0",
46+
"lodash.isnil": "latest",
47+
"lodash.merge": "latest",
48+
"lodash.omitby": "latest"
4649
},
4750
"devDependencies": {
4851
"@types/jest": "^24.0.19",
52+
"@types/lodash.isnil": "^4.0.6",
53+
"@types/lodash.merge": "^4.6.6",
54+
"@types/lodash.omitby": "^4.6.6",
4955
"axios-mock-adapter": "^1.17.0",
5056
"codecov": "^3.5.0",
5157
"jest": "^24.8.0",

src/api/Request.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { AxiosInstance, AxiosResponse } from 'axios'
22
import { Model } from '@vuex-orm/core'
3+
import _merge from 'lodash.merge'
4+
import _omitBy from 'lodash.omitby'
5+
import _isNil from 'lodash.isnil'
36
import Config from '../contracts/Config'
47
import Response from './Response'
58

@@ -126,15 +129,16 @@ export default class Request {
126129

127130
/**
128131
* Create a new config by merging the global config, the model config,
129-
* and the given config.
132+
* and the given config. Any value that is null after the merge will
133+
* have the entire entry removed.
130134
*/
131135
private createConfig (config: Config): Config {
132-
return {
133-
...this.config,
134-
...this.model.globalApiConfig,
135-
...this.model.apiConfig,
136-
...config
137-
}
136+
return _omitBy(_merge({},
137+
this.config,
138+
this.model.globalApiConfig,
139+
this.model.apiConfig,
140+
config
141+
), _isNil)
138142
}
139143

140144
/**

yarn.lock

+46
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,32 @@
957957
dependencies:
958958
"@types/jest-diff" "*"
959959

960+
"@types/lodash.isnil@^4.0.6":
961+
version "4.0.6"
962+
resolved "https://registry.yarnpkg.com/@types/lodash.isnil/-/lodash.isnil-4.0.6.tgz#ff6f07010a69a969c32d5981832cdb4d990ccabf"
963+
integrity sha512-K+9ZVqwWUFKxijX7rPGnrubfTtCQ5VwW0xgPCL5iLBBLg5sUFFXdPG3QxkpGNJil8mgttRqNLSWNweEsUrBXTg==
964+
dependencies:
965+
"@types/lodash" "*"
966+
967+
"@types/lodash.merge@^4.6.6":
968+
version "4.6.6"
969+
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
970+
integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ==
971+
dependencies:
972+
"@types/lodash" "*"
973+
974+
"@types/lodash.omitby@^4.6.6":
975+
version "4.6.6"
976+
resolved "https://registry.yarnpkg.com/@types/lodash.omitby/-/lodash.omitby-4.6.6.tgz#d9b392d5f236983d2597b9e977d337faa00af8aa"
977+
integrity sha512-bHkWp4YyTlqPtHgUwEhExcMQNb8V+HjTUzhxgdnw0UhuT0i61aff6RuSlXt4MbQVPJhB/24tb4WBZJQ+LYIQgw==
978+
dependencies:
979+
"@types/lodash" "*"
980+
981+
"@types/lodash@*":
982+
version "4.14.149"
983+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
984+
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
985+
960986
"@types/minimatch@*":
961987
version "3.0.3"
962988
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -5378,6 +5404,11 @@ lodash.debounce@^4.0.8:
53785404
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
53795405
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
53805406

5407+
lodash.isnil@latest:
5408+
version "4.0.0"
5409+
resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"
5410+
integrity sha1-SeKM1VkBNFjIFMVHnTxmOiG/qmw=
5411+
53815412
lodash.kebabcase@^4.1.1:
53825413
version "4.1.1"
53835414
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
@@ -5388,6 +5419,16 @@ [email protected], lodash.memoize@^4.1.2:
53885419
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
53895420
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
53905421

5422+
lodash.merge@latest:
5423+
version "4.6.2"
5424+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
5425+
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
5426+
5427+
lodash.omitby@latest:
5428+
version "4.6.0"
5429+
resolved "https://registry.yarnpkg.com/lodash.omitby/-/lodash.omitby-4.6.0.tgz#5c15ff4754ad555016b53c041311e8f079204791"
5430+
integrity sha1-XBX/R1StVVAWtTwEExHo8HkgR5E=
5431+
53915432
lodash.sortby@^4.7.0:
53925433
version "4.7.0"
53935434
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -9142,6 +9183,11 @@ yargs@^13.3.0:
91429183
y18n "^4.0.0"
91439184
yargs-parser "^13.1.1"
91449185

9186+
yarn@^1.21.1:
9187+
version "1.21.1"
9188+
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.21.1.tgz#1d5da01a9a03492dc4a5957befc1fd12da83d89c"
9189+
integrity sha512-dQgmJv676X/NQczpbiDtc2hsE/pppGDJAzwlRiADMTvFzYbdxPj2WO4PcNyriSt2c4jsCMpt8UFRKHUozt21GQ==
9190+
91459191
zepto@^1.2.0:
91469192
version "1.2.0"
91479193
resolved "https://registry.yarnpkg.com/zepto/-/zepto-1.2.0.tgz#e127bd9e66fd846be5eab48c1394882f7c0e4f98"

0 commit comments

Comments
 (0)