Skip to content

Commit 20359d8

Browse files
Merge configs using lodash merge
Fixes #97
1 parent 5c6f511 commit 20359d8

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
@@ -44,10 +44,16 @@
4444
"@vuex-orm/core": ">=0.34.0"
4545
},
4646
"dependencies": {
47-
"axios": "^0.19.0"
47+
"axios": "^0.19.0",
48+
"lodash.isnil": "latest",
49+
"lodash.merge": "latest",
50+
"lodash.omitby": "latest"
4851
},
4952
"devDependencies": {
5053
"@types/jest": "^24.0.23",
54+
"@types/lodash.isnil": "^4.0.6",
55+
"@types/lodash.merge": "^4.6.6",
56+
"@types/lodash.omitby": "^4.6.6",
5157
"@vuex-orm/core": "^0.34.1",
5258
"axios-mock-adapter": "^1.17.0",
5359
"codecov": "^3.5.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

@@ -124,15 +127,16 @@ export default class Request {
124127

125128
/**
126129
* Create a new config by merging the global config, the model config,
127-
* and the given config.
130+
* and the given config. Any value that is null after the merge will
131+
* have the entire entry removed.
128132
*/
129133
private createConfig (config: Config): Config {
130-
return {
131-
...this.config,
132-
...this.model.globalApiConfig,
133-
...this.model.apiConfig,
134-
...config
135-
}
134+
return _omitBy(_merge({},
135+
this.config,
136+
this.model.globalApiConfig,
137+
this.model.apiConfig,
138+
config
139+
), _isNil)
136140
}
137141

138142
/**

yarn.lock

+46
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,32 @@
922922
dependencies:
923923
jest-diff "^24.3.0"
924924

925+
"@types/lodash.isnil@^4.0.6":
926+
version "4.0.6"
927+
resolved "https://registry.yarnpkg.com/@types/lodash.isnil/-/lodash.isnil-4.0.6.tgz#ff6f07010a69a969c32d5981832cdb4d990ccabf"
928+
integrity sha512-K+9ZVqwWUFKxijX7rPGnrubfTtCQ5VwW0xgPCL5iLBBLg5sUFFXdPG3QxkpGNJil8mgttRqNLSWNweEsUrBXTg==
929+
dependencies:
930+
"@types/lodash" "*"
931+
932+
"@types/lodash.merge@^4.6.6":
933+
version "4.6.6"
934+
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
935+
integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ==
936+
dependencies:
937+
"@types/lodash" "*"
938+
939+
"@types/lodash.omitby@^4.6.6":
940+
version "4.6.6"
941+
resolved "https://registry.yarnpkg.com/@types/lodash.omitby/-/lodash.omitby-4.6.6.tgz#d9b392d5f236983d2597b9e977d337faa00af8aa"
942+
integrity sha512-bHkWp4YyTlqPtHgUwEhExcMQNb8V+HjTUzhxgdnw0UhuT0i61aff6RuSlXt4MbQVPJhB/24tb4WBZJQ+LYIQgw==
943+
dependencies:
944+
"@types/lodash" "*"
945+
946+
"@types/lodash@*":
947+
version "4.14.149"
948+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
949+
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
950+
925951
"@types/minimatch@*":
926952
version "3.0.3"
927953
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -5305,6 +5331,11 @@ lodash.debounce@^4.0.8:
53055331
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
53065332
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
53075333

5334+
lodash.isnil@latest:
5335+
version "4.0.0"
5336+
resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"
5337+
integrity sha1-SeKM1VkBNFjIFMVHnTxmOiG/qmw=
5338+
53085339
lodash.kebabcase@^4.1.1:
53095340
version "4.1.1"
53105341
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
@@ -5315,6 +5346,16 @@ [email protected], lodash.memoize@^4.1.2:
53155346
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
53165347
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
53175348

5349+
lodash.merge@latest:
5350+
version "4.6.2"
5351+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
5352+
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
5353+
5354+
lodash.omitby@latest:
5355+
version "4.6.0"
5356+
resolved "https://registry.yarnpkg.com/lodash.omitby/-/lodash.omitby-4.6.0.tgz#5c15ff4754ad555016b53c041311e8f079204791"
5357+
integrity sha1-XBX/R1StVVAWtTwEExHo8HkgR5E=
5358+
53185359
lodash.sortby@^4.7.0:
53195360
version "4.7.0"
53205361
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -9064,6 +9105,11 @@ yargs@^13.3.0:
90649105
y18n "^4.0.0"
90659106
yargs-parser "^13.1.1"
90669107

9108+
yarn@^1.21.1:
9109+
version "1.21.1"
9110+
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.21.1.tgz#1d5da01a9a03492dc4a5957befc1fd12da83d89c"
9111+
integrity sha512-dQgmJv676X/NQczpbiDtc2hsE/pppGDJAzwlRiADMTvFzYbdxPj2WO4PcNyriSt2c4jsCMpt8UFRKHUozt21GQ==
9112+
90679113
zepto@^1.2.0:
90689114
version "1.2.0"
90699115
resolved "https://registry.yarnpkg.com/zepto/-/zepto-1.2.0.tgz#e127bd9e66fd846be5eab48c1394882f7c0e4f98"

0 commit comments

Comments
 (0)