Skip to content

Commit

Permalink
Merge configs using lodash merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolan Woods committed Jan 10, 2020
1 parent 41bdb59 commit 9e3ea00
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@
},
"dependencies": {
"@vuex-orm/core": "^0.32.5",
"axios": "^0.19.0"
"axios": "^0.19.0",
"lodash.isnil": "latest",
"lodash.merge": "latest",
"lodash.omitby": "latest"
},
"devDependencies": {
"@types/jest": "^24.0.19",
"@types/lodash.isnil": "^4.0.6",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.omitby": "^4.6.6",
"axios-mock-adapter": "^1.17.0",
"codecov": "^3.5.0",
"jest": "^24.8.0",
Expand Down
18 changes: 11 additions & 7 deletions src/api/Request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { AxiosInstance, AxiosResponse } from 'axios'
import { Model } from '@vuex-orm/core'
import _merge from 'lodash.merge'
import _omitBy from 'lodash.omitby'
import _isNil from 'lodash.isnil'
import Config from '../contracts/Config'
import Response from './Response'

Expand Down Expand Up @@ -126,15 +129,16 @@ export default class Request {

/**
* Create a new config by merging the global config, the model config,
* and the given config.
* and the given config. Any value that is null after the merge will
* have the entire entry removed.
*/
private createConfig (config: Config): Config {
return {
...this.config,
...this.model.globalApiConfig,
...this.model.apiConfig,
...config
}
return _omitBy(_merge({},
this.config,
this.model.globalApiConfig,
this.model.apiConfig,
config
), _isNil)
}

/**
Expand Down
46 changes: 46 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,32 @@
dependencies:
"@types/jest-diff" "*"

"@types/lodash.isnil@^4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@types/lodash.isnil/-/lodash.isnil-4.0.6.tgz#ff6f07010a69a969c32d5981832cdb4d990ccabf"
integrity sha512-K+9ZVqwWUFKxijX7rPGnrubfTtCQ5VwW0xgPCL5iLBBLg5sUFFXdPG3QxkpGNJil8mgttRqNLSWNweEsUrBXTg==
dependencies:
"@types/lodash" "*"

"@types/lodash.merge@^4.6.6":
version "4.6.6"
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ==
dependencies:
"@types/lodash" "*"

"@types/lodash.omitby@^4.6.6":
version "4.6.6"
resolved "https://registry.yarnpkg.com/@types/lodash.omitby/-/lodash.omitby-4.6.6.tgz#d9b392d5f236983d2597b9e977d337faa00af8aa"
integrity sha512-bHkWp4YyTlqPtHgUwEhExcMQNb8V+HjTUzhxgdnw0UhuT0i61aff6RuSlXt4MbQVPJhB/24tb4WBZJQ+LYIQgw==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.149"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==

"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down Expand Up @@ -5378,6 +5404,11 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash.isnil@latest:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"
integrity sha1-SeKM1VkBNFjIFMVHnTxmOiG/qmw=

lodash.kebabcase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
Expand All @@ -5388,6 +5419,16 @@ lodash.memoize@4.x, lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.merge@latest:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.omitby@latest:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.omitby/-/lodash.omitby-4.6.0.tgz#5c15ff4754ad555016b53c041311e8f079204791"
integrity sha1-XBX/R1StVVAWtTwEExHo8HkgR5E=

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
Expand Down Expand Up @@ -9142,6 +9183,11 @@ yargs@^13.3.0:
y18n "^4.0.0"
yargs-parser "^13.1.1"

yarn@^1.21.1:
version "1.21.1"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.21.1.tgz#1d5da01a9a03492dc4a5957befc1fd12da83d89c"
integrity sha512-dQgmJv676X/NQczpbiDtc2hsE/pppGDJAzwlRiADMTvFzYbdxPj2WO4PcNyriSt2c4jsCMpt8UFRKHUozt21GQ==

zepto@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/zepto/-/zepto-1.2.0.tgz#e127bd9e66fd846be5eab48c1394882f7c0e4f98"
Expand Down

0 comments on commit 9e3ea00

Please sign in to comment.