vue.js 源代码学习笔记 ----- instance proxy
- /* not type checking this file because flow doesn't play well with Proxy */
- import config from 'core/config'
- import { warn, makeMap } from '../util/index'
- let initProxy
- if (process.env.NODE_ENV !== 'production') {
- //一些能使用的全局变量
- const allowedGlobals = makeMap(
- 'Infinity,undefined,NaN,isFinite,isNaN,' +
- 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
- 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
- 'require' // for Webpack/Browserify
- )
//未定义缺使用了- const warnNonPresent = (target, key) => {
- warn(
- `Property or method "${key}" is not defined on the instance but ` +
- `referenced during render. Make sure to declare reactive data ` +
- `properties in the data option.`,
- target
- )
- }
//es6 proxy详解- const hasProxy =
- typeof Proxy !== 'undefined' &&
- Proxy.toString().match(/native code/)
- if (hasProxy) {
- const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta')
//避免设置 系统鼠标 属性
config.keyCodes = new Proxy(config.keyCodes, {- set (target, key, value) {
- if (isBuiltInModifier(key)) {
- warn(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`)
- return false
- } else {
- target[key] = value
- return true
- }
- }
- })
- }
- const hasHandler = {
- has (target, key) {
- const has = key in target
- const isAllowed = allowedGlobals(key) || key.charAt(0) === '_'
- if (!has && !isAllowed) {
- warnNonPresent(target, key)
- }
//如果有这个key 或者 不是全局函数, 返回true- return has || !isAllowed
- }
- }
- const getHandler = {
- get (target, key) {
- if (typeof key === 'string' && !(key in target)) {
- warnNonPresent(target, key)
- }
- return target[key]
- }
- }
- initProxy = function initProxy (vm) {
- if (hasProxy) {
- // determine which proxy handler to use
- const options = vm.$options
- const handlers = options.render && options.render._withStripped
- ? getHandler
- : hasHandler
- vm._renderProxy = new Proxy(vm, handlers)
- } else {
- vm._renderProxy = vm
- }
- }
- }
- export { initProxy }
此方法做了一些对象操作的拦截 和 警告
vue.js 源代码学习笔记 ----- instance proxy的更多相关文章
- vue.js 源代码学习笔记 ----- instance state
/* @flow */ import Dep from '../observer/dep' import Watcher from '../observer/watcher' import { set ...
- vue.js 源代码学习笔记 ----- instance render
/* @flow */ import { warn, nextTick, toNumber, _toString, looseEqual, emptyObject, handleError, loos ...
- vue.js 源代码学习笔记 ----- instance init
/* @flow */ import config from '../config' import { initProxy } from './proxy' import { initState } ...
- vue.js 源代码学习笔记 ----- instance event
/* @flow */ import { updateListeners } from '../vdom/helpers/index' import { toArray, tip, hyphenate ...
- vue.js 源代码学习笔记 ----- instance index
import { initMixin } from './init' import { stateMixin } from './state' import { renderMixin } from ...
- vue.js 源代码学习笔记 ----- instance inject
/* @flow */ import { hasSymbol } from 'core/util/env' import { warn } from '../util/index' import { ...
- vue.js 源代码学习笔记 ----- html-parse.js
/** * Not type-checking this file because it's mostly vendor code. */ /*! * HTML Parser By John Resi ...
- vue.js 源代码学习笔记 ----- core lifecycle
/* @flow */ import config from '../config' import Watcher from '../observer/watcher' import { mark, ...
- vue.js 源代码学习笔记 ----- 工具方法 option
/* @flow */ import Vue from '../instance/index' import config from '../config' import { warn } from ...
随机推荐
- 20145231熊梓宏 《网络对抗》 实验5 MSF基础应用
20145231熊梓宏 <网络对抗> 实验5 MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit就相当于是就是渗透攻击,其 ...
- Leetcode(93): Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- linux c开发环境构成
1.编辑器:VI.VIM 2.编译器:GNU C/C++编译器gcc 3.调试器:gdb 4.函数库:glibc 5.系统头文件:glibc_header
- 源码安装GCC-4.9.2
本文参考:http://cuchadanfan.blog.51cto.com/9940284/1689556 感谢原作者的分享! 首先安装基础包,安装网络依赖的时候要用 [root@localhos ...
- Ad Exchange基本接口和功能
这里描述下一个exchange通常应该提供的接口和应该满足的功能. 接口 实时竞价接口 实时竞价接口也是最核心的接口,对接的dsp需要向exchange提供竞价地址.每次有广告请求时,exchange ...
- LaTeX模板 - FORMCM
LaTex 模板 - FORMCM \documentclass{mcmthesis} \mcmsetup{CTeX = true, % 使用 CTeX 套装时,设置为 true tcn = 8989 ...
- Mysql事物的4种隔离级别
SQL标准定义了4种隔离级别,包括了一些具体规则,用来限定事务内外的哪些改变是可见的,哪些是不可见的. 低级别的隔离级一般支持更高的并发处理,并拥有更低的系统开销. 首先,我们使用 test 数据库, ...
- asp.net core + log4net+exceptionles+DI
参考了ABP的代码,我也用依赖注入的原则,设计了日志模块. 与abp不同之处在于:1)DI容器使用的是.net core自带的注入容器,2)集成了excetpionless日志模块,3)不依赖于abp ...
- 关于http请求ContentType:application/x-www-form-urlencoded
在又一次http请求过程中,模拟post请求提交form表单数据一直提示部分参数为空,后面检查发现是缺少ContentType:application/x-www-form-urlencoded的原因 ...
- HTML5 history API,创造更好的浏览体验
HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...