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 5c6f511 commit f73186e
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 321 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@
"@vuex-orm/core": ">=0.34.0"
},
"dependencies": {
"axios": "^0.19.0"
"axios": "^0.19.0",
"lodash.isnil": "latest",
"lodash.merge": "latest",
"lodash.omitby": "latest"
},
"devDependencies": {
"@types/jest": "^24.0.23",
"@types/lodash.isnil": "^4.0.6",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.omitby": "^4.6.6",
"@vuex-orm/core": "^0.34.1",
"axios-mock-adapter": "^1.17.0",
"codecov": "^3.5.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 @@ -124,15 +127,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
Loading

0 comments on commit f73186e

Please sign in to comment.