Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 24a422e

Browse files
committedJan 10, 2020
Merge configs using lodash merge
Fixes #97
1 parent 5c6f511 commit 24a422e

File tree

3 files changed

+18
-9078
lines changed

3 files changed

+18
-9078
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

-9,070
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.