/lib/core/interceptorManager.js
interceptorManager.js定义了axios的拦截器,包含了拦截器的增加、删除、循环拦截器。响应拦截器和请求拦截器都是用数组存储的。
1 | var utils = require('./../utils'); |
interceptorManager.js定义了axios的拦截器,包含了拦截器的增加、删除、循环拦截器。响应拦截器和请求拦截器都是用数组存储的。
1 | var utils = require('./../utils'); |
dispatchRequest.js 文件是axios源码中实际调用请求的地方
1 |
|
defaults.js文件中配置了axios的默认请求头,不同环境下axios的默认请求方法,格式化请求正文的方法以及响应征文的方法等
1 | var utils = require('./utils'); |
1 | var utils = require('./utils'); |
util.js 中被用到的工具类:
1 | /** |
1 | /** |
bind 方法:1
2
3
4
5
6
7
8
9module.exports = function bind(fn, thisArg) {
return function wrap() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
return fn.apply(thisArg, args);
};
};
createInstance
干了什么instance有Axios.prototype.request和Axios.prototype的方法,并且这些方法的执行上下文都绑定到context中
instance 里面还有 context 上的方法。
Axios.js中定义了Axios实例上的request,get,post,delete方法。get,post,delete等方法均基于Axios.prototype.request的封装。在Axios.prototype.request会依次执行请求拦截器,dispatchRequest,响应拦截器。
1 | var defaults = require('./../defaults'); |
xhr.js 暴露的xhrAdapter方法,是axios在浏览器环境下的默认请求方法,可以在配置中使用adapter配置项对默认的方法进行替换。
1 | module.exports = function xhrAdapter(config) { |
1 | // axios用于取消请求的类 |
1 | function CancelToken(executor) { // @param {Function} executor The executor function. |
1 | // xhr.js 相关代码 |
通过cancelToken,创建了一个额外的promiseA,这个promiseA对外暴露了它的resolve方法,这个promise被挂载在config下。
在调用send方法前,添加对promiseA的监听,当promiseA的状态发生变化,就会在promiseA的callback取消请求,并且将axios返回的的promiseB的状态设置为reject,从而取消请求。
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
1 | $ hexo new "My New Post" |
More info: Writing
1 | $ hexo server |
More info: Server
1 | $ hexo generate |
More info: Generating
1 | $ hexo deploy |
More info: Deployment
1 | // 合并构造函数原本的options和构造时传入的options |
检查构造时传入的options中,components中引入的组件名是否合法1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24function checkComponents (options: Object) {
for (const key in options.components) {
// 遍历传入options中的components,并验证引入的组件的合法性
validateComponentName(key)
}
}
export function validateComponentName (name: string) {
if (!/^[a-zA-Z][\w-]*$/.test(name)) { // 命名是否符合正则中的规则
warn(
'Invalid component name: "' + name + '". Component names ' +
'can only contain alphanumeric characters and the hyphen, ' +
'and must start with a letter.'
)
}
if (isBuiltInTag(name) || config.isReservedTag(name)) {
// isBuiltInTag方法是检验该名是否与svg标签或者html标签相同
// isReservedTag方法,检验是否和保留字相同
warn(
'Do not use built-in or reserved HTML elements as component ' +
'id: ' + name
)
}
}
1 | function normalizeProps (options: Object, vm: ?Component) { |
1 | function mergeHook ( |
流畅图如下
1 | strats.props = |
流程和钩子函数合并类似,只是处理父子合并的时候不同,此处是使用继承的方式,同名属性使用childVal中的值
1 | function mergeAssets ( |
逻辑同上
1 | export function mergeDataOrFn ( |
上面代码的最后,都会调用mergeData,下面是mergeData内容:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16function mergeData (to: Object, from: ?Object): Object {
if (!from) return to
let key, toVal, fromVal
const keys = Object.keys(from)
for (let i = 0; i < keys.length; i++) {
key = keys[i]
toVal = to[key]
fromVal = from[key]
if (!hasOwn(to, key)) {
set(to, key, fromVal)
} else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
mergeData(toVal, fromVal)
}
}
return to
}
to为childVal,from为parentVal
大体思路: