Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
143bbbe1
A
axios
项目概览
xjbieke
/
axios
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
axios
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
143bbbe1
编写于
4月 07, 2018
作者:
M
Martti Laine
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Spec for mergeConfig, finalize logic
上级
ff61caac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
11 deletion
+85
-11
lib/core/mergeConfig.js
lib/core/mergeConfig.js
+16
-10
lib/defaults.js
lib/defaults.js
+0
-1
test/specs/core/mergeConfig.spec.js
test/specs/core/mergeConfig.spec.js
+69
-0
未找到文件。
lib/core/mergeConfig.js
浏览文件 @
143bbbe1
...
...
@@ -16,18 +16,20 @@ module.exports = function mergeConfig(config1, config2) {
var
config
=
{};
utils
.
forEach
([
'
url
'
,
'
method
'
,
'
params
'
,
'
data
'
],
function
valueFromConfig2
(
prop
)
{
config
[
prop
]
=
config2
[
prop
];
if
(
typeof
config2
[
prop
]
!==
'
undefined
'
)
{
config
[
prop
]
=
config2
[
prop
];
}
});
utils
.
forEach
([
'
headers
'
,
'
auth
'
,
'
proxy
'
],
function
mergeValues
(
prop
)
{
if
(
typeof
config2
[
prop
]
!==
'
undefined
'
)
{
if
(
typeof
config2
[
prop
]
===
'
object
'
)
{
config
[
prop
]
=
utils
.
deepMerge
(
config1
[
prop
],
config2
[
prop
]);
}
else
{
config
[
prop
]
=
config2
[
prop
];
}
}
else
if
(
typeof
config1
[
prop
]
!==
'
undefined
'
)
{
utils
.
forEach
([
'
headers
'
,
'
auth
'
,
'
proxy
'
],
function
mergeDeepProperties
(
prop
)
{
if
(
utils
.
isObject
(
config2
[
prop
]))
{
config
[
prop
]
=
utils
.
deepMerge
(
config1
[
prop
],
config2
[
prop
]);
}
else
if
(
typeof
config2
[
prop
]
!==
'
undefined
'
)
{
config
[
prop
]
=
config2
[
prop
];
}
else
if
(
utils
.
isObject
(
config1
[
prop
]))
{
config
[
prop
]
=
utils
.
deepMerge
(
config1
[
prop
]);
}
else
if
(
typeof
config1
[
prop
]
!==
'
undefined
'
)
{
config
[
prop
]
=
config1
[
prop
];
}
});
...
...
@@ -37,7 +39,11 @@ module.exports = function mergeConfig(config1, config2) {
'
xsrfHeaderName
'
,
'
onUploadProgress
'
,
'
onDownloadProgress
'
,
'
maxContentLength
'
,
'
validateStatus
'
,
'
maxRedirects
'
,
'
httpAgent
'
,
'
httpsAgent
'
,
'
cancelToken
'
],
function
defaultToConfig2
(
prop
)
{
config
[
prop
]
=
typeof
config2
[
prop
]
===
'
undefined
'
?
config1
[
prop
]
:
config2
[
prop
];
if
(
typeof
config2
[
prop
]
!==
'
undefined
'
)
{
config
[
prop
]
=
config2
[
prop
];
}
else
if
(
typeof
config1
[
prop
]
!==
'
undefined
'
)
{
config
[
prop
]
=
config1
[
prop
];
}
});
return
config
;
...
...
lib/defaults.js
浏览文件 @
143bbbe1
...
...
@@ -26,7 +26,6 @@ function getDefaultAdapter() {
}
var
defaults
=
{
method
:
'
get
'
,
adapter
:
getDefaultAdapter
(),
transformRequest
:
[
function
transformRequest
(
data
,
headers
)
{
...
...
test/specs/core/mergeConfig.spec.js
0 → 100644
浏览文件 @
143bbbe1
var
defaults
=
require
(
'
../../../lib/defaults
'
);
var
mergeConfig
=
require
(
'
../../../lib/core/mergeConfig
'
);
describe
(
'
core::mergeConfig
'
,
function
()
{
it
(
'
should accept undefined for second argument
'
,
function
()
{
expect
(
mergeConfig
(
defaults
,
undefined
)).
toEqual
(
defaults
);
});
it
(
'
should accept an object for second argument
'
,
function
()
{
expect
(
mergeConfig
(
defaults
,
{})).
toEqual
(
defaults
);
});
it
(
'
should not leave references
'
,
function
()
{
var
merged
=
mergeConfig
(
defaults
,
{});
expect
(
merged
).
not
.
toBe
(
defaults
);
expect
(
merged
.
headers
).
not
.
toBe
(
defaults
.
headers
);
});
it
(
'
should allow setting request options
'
,
function
()
{
var
config
=
{
url
:
'
__sample url__
'
,
method
:
'
__sample method__
'
,
params
:
'
__sample params__
'
,
data
:
{
foo
:
true
}
};
var
merged
=
mergeConfig
(
defaults
,
config
);
expect
(
merged
.
url
).
toEqual
(
config
.
url
);
expect
(
merged
.
method
).
toEqual
(
config
.
method
);
expect
(
merged
.
params
).
toEqual
(
config
.
params
);
expect
(
merged
.
data
).
toEqual
(
config
.
data
);
});
it
(
'
should not inherit request options
'
,
function
()
{
var
localDefaults
=
{
url
:
'
__sample url__
'
,
method
:
'
__sample method__
'
,
params
:
'
__sample params__
'
,
data
:
{
foo
:
true
}
};
var
merged
=
mergeConfig
(
localDefaults
,
{});
expect
(
merged
.
url
).
toEqual
(
undefined
);
expect
(
merged
.
method
).
toEqual
(
undefined
);
expect
(
merged
.
params
).
toEqual
(
undefined
);
expect
(
merged
.
data
).
toEqual
(
undefined
);
});
it
(
'
should merge auth, headers, proxy with defaults
'
,
function
()
{
expect
(
mergeConfig
({
auth
:
undefined
},
{
auth
:
{
user
:
'
foo
'
,
pass
:
'
test
'
}
})).
toEqual
({
auth
:
{
user
:
'
foo
'
,
pass
:
'
test
'
}
});
expect
(
mergeConfig
({
auth
:
{
user
:
'
foo
'
,
pass
:
'
test
'
}
},
{
auth
:
{
pass
:
'
foobar
'
}
})).
toEqual
({
auth
:
{
user
:
'
foo
'
,
pass
:
'
foobar
'
}
});
});
it
(
'
should overwrite auth, headers, proxy with a non-object value
'
,
function
()
{
expect
(
mergeConfig
({
auth
:
{
user
:
'
foo
'
,
pass
:
'
test
'
}
},
{
auth
:
false
})).
toEqual
({
auth
:
false
});
expect
(
mergeConfig
({
auth
:
{
user
:
'
foo
'
,
pass
:
'
test
'
}
},
{
auth
:
null
})).
toEqual
({
auth
:
null
});
});
it
(
'
should allow setting other options
'
,
function
()
{
var
merged
=
mergeConfig
(
defaults
,
{
timeout
:
123
});
expect
(
merged
.
timeout
).
toEqual
(
123
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录