vue源码阅读(一)
版本:2.5.17-beta.0
核心模块(src/core):包括组件、全局API、vue实例、对象属性监测系统、公共方法、虚拟dom、配置等模块
src/core/index.js
import Vue from './instance/index'
import { initGlobalAPI } from './global-api/index'
import { isServerRendering } from 'core/util/env'
import { FunctionalRenderContext } from 'core/vdom/create-functional-component'
//添加全局api
initGlobalAPI(Vue)
//服务端 运行判断
Object.defineProperty(Vue.prototype, '$isServer', {
get: isServerRendering
})
//处理内存泄漏 处理
Object.defineProperty(Vue.prototype, '$ssrContext', {
get () {
/* istanbul ignore next */
return this.$vnode && this.$vnode.ssrContext
}
})
// 不知道干啥的todo
Object.defineProperty(Vue, 'FunctionalRenderContext', {
value: FunctionalRenderContext
})
//__VERSION__是配置的变量
Vue.version = '__VERSION__'
export default Vue
突然发现源码 读起来还好 写出来怎么那么麻烦啊!
initGlobalApi
/* @flow */ import config from '../config'
import { initUse } from './use'
import { initMixin } from './mixin'
import { initExtend } from './extend'
import { initAssetRegisters } from './assets'
import { set, del } from '../observer/index'
import { ASSET_TYPES } from 'shared/constants'
import builtInComponents from '../components/index' import {
warn,
extend,
nextTick,
mergeOptions,
defineReactive
} from '../util/index' export function initGlobalAPI (Vue: GlobalAPI) {
// config
const configDef = {}
configDef.get = () => config
if (process.env.NODE_ENV !== 'production') {
configDef.set = () => {
warn(
'Do not replace the Vue.config object, set individual fields instead.'
)
}
}
Object.defineProperty(Vue, 'config', configDef) // exposed util methods.
// NOTE: these are not considered part of the public API - avoid relying on
// them unless you are aware of the risk. //在这个地方挂载 util方法
Vue.util = {
warn,
extend,
mergeOptions, //合并options.js
defineReactive //
}
Vue.set = set
Vue.delete = del //方法来自 "../util/index"
Vue.nextTick = nextTick Vue.options = Object.create(null)
ASSET_TYPES.forEach(type => {
Vue.options[type + 's'] = Object.create(null)
}) // this is used to identify the "base" constructor to extend all plain-object
// components with in Weex's multi-instance scenarios.
Vue.options._base = Vue //keep-alive 组件,点进去就可以看到
extend(Vue.options.components, builtInComponents) //Vue.use()方法
initUse(Vue) //Vue.mixin()方法
initMixin(Vue) //Vue.extend() 方法
initExtend(Vue) //Vue.component, Vue.directive, Vue.filter
initAssetRegisters(Vue)
}
util 方法 extend,mergeOptions,defineReactive,nextTick
extend
/**
* 简单的对象的浅拷贝,有点失望
*/
export function extend (to: Object, _from: ?Object): Object {
for (const key in _from) {
to[key] = _from[key]
}
return to
}
写出来真麻烦
vue源码阅读(一)的更多相关文章
- vue源码阅读(二)
一 一个实例 如果简单了解过些Vue的API的话,肯定会对一下这个特别熟悉,在上一篇里,分析了Vue的核心文件core的index.js构造vue函数执行的流程. 那么下边这个则是实例化构造函数,也就 ...
- Vue源码阅读一:说说vue.nextTick实现
用法: 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 疑惑: 怎么实现的延迟回调 原理: JavaScript语言的一大特点就是单线程,同一个时 ...
- vue源码阅读笔记
1.yarn test [文件名] -t [name-of-spec(describe or test )] 直接运行yarn test,会测试所有测试文件:yarn test 后面只跟文件名的话会 ...
- vue 源码阅读记录
0.webpack默认引入的是vue.runtime.common.js,并不是vue.js,功能有略微差别,不影响使用 1.阅读由ts编译后的js: 入口>构造函数 >定义各类方法 &g ...
- 【一套代码小程序&Native&Web阶段总结篇】可以这样阅读Vue源码
前言 前面我们对微信小程序进行了研究:[微信小程序项目实践总结]30分钟从陌生到熟悉 在实际代码过程中我们发现,我们可能又要做H5站又要做小程序同时还要做个APP,这里会造成很大的资源浪费,如果设定一 ...
- 阅读vue源码-----内置组件篇(keep-alive)
1.前言: <keep-alive>是vue实现的一个内置组件,也就是说vue源码不仅实现了一套组件化的机制,也实现了一些内置组件. <keep-alive>官网介绍如下:&l ...
- 大白话Vue源码系列(01):万事开头难
阅读目录 Vue 的源码目录结构 预备知识 先捡软的捏 Angular 是 Google 亲儿子,React 是 Facebook 小正太,那咱为啥偏偏选择了 Vue 下手,一句话,Vue 是咱见过的 ...
- 大白话Vue源码系列(02):编译器初探
阅读目录 编译器代码藏在哪 Vue.prototype.$mount 构建 AST 的一般过程 Vue 构建的 AST 题接上文,上回书说到,Vue 的编译器模块相对独立且简单,那咱们就从这块入手,先 ...
- 大白话Vue源码系列(03):生成AST
阅读目录 AST 节点定义 标签的正则匹配 解析用到的工具方法 解析开始标签 解析结束标签 解析文本 解析整块 HTML 模板 未提及的细节 本篇探讨 Vue 根据 html 模板片段构建出 AST ...
随机推荐
- Java 多线程总结
昨天熬了个通宵,看了一晚上的视频,把java 的多线程相关技术重新复习了一遍,下面对学习过程中遇到的知识点进行下总结. 首先我们先来了解一下进程.线程.并发执行的概念: 进程是指:一个内存中运行的应用 ...
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
- django的一些常用指令
生成Django项目 django-admin startproject mysite 启动服务 python manage.py runserver 本地化中间件 'django.mididdlew ...
- php in_array() 循环大量数组时效率特别慢问题
in_array() 会循环数组内部元素逐个匹配,特别耗时,换成以下方式,效率大大提升
- Arduino语言介绍
Arduino语言介绍 Arduino语言是建立在C/C++基础上的,其基础是C语言,Arduino语言只不过把AVR单片机(微控制器)相关的一些参数设置都函数化,不用我们去了解他的底层,让不了解AV ...
- ROS-十步完成ROS-indigo安装
Ubuntu 版本是14.04.5.(这个版本的ubuntu的内核是V4.4的内核,长期维护到2019年,是14代比较稳定的,反正用这个安装就没有什么依赖的头疼的问题,安装ROS很方便,可以去清华的网 ...
- 【原创】算法基础之Anaconda(1)简介、安装、使用
Anaconda 2 官方:https://www.anaconda.com/ 一 简介 The Most Popular Python Data Science Platform Anaconda® ...
- Sharding-JDBC
1.官网文档:https://shardingsphere.apache.org/document/legacy/3.x/document/cn/manual/sharding-jdbc/usage/ ...
- Python学习笔记五
一. 递归 递归函数: def a (): print ("from b") b() def b(): print("from a ") a() a() 递推和 ...
- CodeSmith Generator 7.0.2的激活流程
学过三层的人应该认识CodeSmith Generator吧,今天我就跟大家一起探讨下CodeSmith Generator 7.0.2的激活,这最新版本破解的难度也是超越以往......具体看这篇日 ...