当前位置: 首页 > news >正文

小米手机网站建设总结电商培训机构排名前十

小米手机网站建设总结,电商培训机构排名前十,南宁网站设计,网站制作珠海公司源码是ts编写的,这里部分简化成js便于阅读 function ref(value) {return createRef(value, false) }function createRef(rawValue, shallow) { //shallow是否是浅层定义数据,用于区别ref和shallowRefif (isRef(rawValue)) {//如果已经是ref直接返回源数据return rawValue}retu…

源码是ts编写的,这里部分简化成js便于阅读

function ref(value) {return createRef(value, false)
}function createRef(rawValue, shallow) { //shallow是否是浅层定义数据,用于区别ref和shallowRefif (isRef(rawValue)) {//如果已经是ref直接返回源数据return rawValue}return new RefImpl(rawValue, shallow)
}class RefImpl<T> {private _value: Tprivate _rawValue: Tpublic dep?: Dep = undefinedpublic readonly __v_isRef = trueconstructor(value: T,//第一个参数value:传入的源数据public readonly __v_isShallow: boolean //第二个参数__v_isShallow:是否是浅层次响应的属性) {this._rawValue = __v_isShallow ? value : toRaw(value)//toRaw是为了防止死循环this._value = __v_isShallow ? value : toReactive(value)//初始化数据如果是已经包装过的__v_isShallow就是true,否则通过toReactive包装传入的参数}get value() {trackRefValue(this) //依赖收集return this._value}set value(newVal) {const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal)//判断是否已经是vue包装过的对象newVal = useDirectValue ? newVal : toRaw(newVal)if (hasChanged(newVal, this._rawValue)) {this._rawValue = newValthis._value = useDirectValue ? newVal : toReactive(newVal)//如果已经包装过返回源数据,否则通过toReactive包装传入的参数triggerRefValue(this, newVal)//触发响应式更新}}
}toReactive = (value) => isObject(value) ? reactive(value) : value //基本数据类型通过class类依赖收集触发更新,引用数据类型通过Proxy代理实现isObject = (val) => val !== null && typeof val === 'object' //上面用到的函数:判断是否是一个对象//reactive()函数调用createReactiveObject函数(内部通过new Proxy())创建响应式数据,如下:function createReactiveObject(target: Target,isReadonly: boolean,baseHandlers: ProxyHandler<any>,collectionHandlers: ProxyHandler<any>,proxyMap: WeakMap<Target, any>
) {if (!isObject(target)) { //如果不是对象直接返回源数据,所以必须传入对象才有效if (__DEV__) {console.warn(`value cannot be made reactive: ${String(target)}`)}return target}// target is already a Proxy, return it.// exception: calling readonly() on a reactive objectif (target[ReactiveFlags.RAW] &&!(isReadonly && target[ReactiveFlags.IS_REACTIVE])) {return target}// target already has corresponding Proxyconst existingProxy = proxyMap.get(target)if (existingProxy) {return existingProxy}// only specific value types can be observed.const targetType = getTargetType(target)if (targetType === TargetType.INVALID) {return target}const proxy = new Proxy(//创建Proxy代理target,targetType === TargetType.COLLECTION ? collectionHandlers : baseHandlers)proxyMap.set(target, proxy)return proxy
}

总结:

ref() 函数通过调用new RefImpl(rawValue, shallow)这个class类来包装数据,内部有value属性(可读get通过trackRefValue收集依赖;可写set通过triggerRefValue更新依赖), 传入的值会调用toReactive函数进行封装. 
toReactive = (value) => isObject(value) ? reactive(value) : value

isObject = (val) => val !== null && typeof val === 'object'

reactive()函数调用createReactiveObject函数(内部通过new Proxy())创建响应式数据

ref:定义基本数据类型通过class类中的value属性依赖收集触发更新;定义引用数据类型会调用reactive()实现数据代理

reactive:只用于定义引用数据类型,通过Proxy代理实现

附源码地址 https://github.com/vuejs/core/tree/v3.3.4/packages/reactivity/src


文章转载自:
http://spindleage.rdgb.cn
http://hogmanay.rdgb.cn
http://rotfl.rdgb.cn
http://sheridan.rdgb.cn
http://angina.rdgb.cn
http://uniformitarian.rdgb.cn
http://ericaceous.rdgb.cn
http://tertio.rdgb.cn
http://hylomorphism.rdgb.cn
http://triclinic.rdgb.cn
http://smithiantha.rdgb.cn
http://monellin.rdgb.cn
http://trochus.rdgb.cn
http://bacteriostatic.rdgb.cn
http://ratbite.rdgb.cn
http://hemosiderin.rdgb.cn
http://parolee.rdgb.cn
http://linendraper.rdgb.cn
http://anisometropia.rdgb.cn
http://craquelure.rdgb.cn
http://triloculate.rdgb.cn
http://raise.rdgb.cn
http://harz.rdgb.cn
http://laryngoscope.rdgb.cn
http://sociologist.rdgb.cn
http://sudorific.rdgb.cn
http://diamondback.rdgb.cn
http://disambiguition.rdgb.cn
http://catalepsy.rdgb.cn
http://does.rdgb.cn
http://frilled.rdgb.cn
http://mesothelial.rdgb.cn
http://cantonment.rdgb.cn
http://antiperiodic.rdgb.cn
http://brachypterous.rdgb.cn
http://sombre.rdgb.cn
http://exhedra.rdgb.cn
http://vertigo.rdgb.cn
http://renunciate.rdgb.cn
http://thummim.rdgb.cn
http://rapid.rdgb.cn
http://versatile.rdgb.cn
http://chlorofluoromethane.rdgb.cn
http://thermocouple.rdgb.cn
http://climatology.rdgb.cn
http://perfervid.rdgb.cn
http://auricle.rdgb.cn
http://ebullism.rdgb.cn
http://pragmatic.rdgb.cn
http://adoration.rdgb.cn
http://inferrable.rdgb.cn
http://populist.rdgb.cn
http://culch.rdgb.cn
http://umbilicular.rdgb.cn
http://resegregate.rdgb.cn
http://otaru.rdgb.cn
http://demotion.rdgb.cn
http://siratro.rdgb.cn
http://asthenopic.rdgb.cn
http://tafoni.rdgb.cn
http://tuneless.rdgb.cn
http://quattrocento.rdgb.cn
http://imprudent.rdgb.cn
http://anaesthetization.rdgb.cn
http://agincourt.rdgb.cn
http://theological.rdgb.cn
http://homeothermal.rdgb.cn
http://wavily.rdgb.cn
http://newborn.rdgb.cn
http://kenspeckle.rdgb.cn
http://difunctional.rdgb.cn
http://coreopsis.rdgb.cn
http://looney.rdgb.cn
http://poona.rdgb.cn
http://subtlety.rdgb.cn
http://speculator.rdgb.cn
http://songful.rdgb.cn
http://pickel.rdgb.cn
http://tonsil.rdgb.cn
http://entomophily.rdgb.cn
http://raddleman.rdgb.cn
http://uncouple.rdgb.cn
http://schradan.rdgb.cn
http://ethnographer.rdgb.cn
http://supervoltage.rdgb.cn
http://jidda.rdgb.cn
http://gradualness.rdgb.cn
http://quinquelateral.rdgb.cn
http://trisepalous.rdgb.cn
http://inciting.rdgb.cn
http://deerfly.rdgb.cn
http://securities.rdgb.cn
http://detractive.rdgb.cn
http://davida.rdgb.cn
http://paralympics.rdgb.cn
http://ct.rdgb.cn
http://unlivable.rdgb.cn
http://png.rdgb.cn
http://address.rdgb.cn
http://quadplex.rdgb.cn
http://www.hrbkazy.com/news/75701.html

相关文章:

  • 购物网站策划建设方案网站怎么优化排名靠前
  • 做网站好做吗seo优化方法
  • 云服务器怎么样做网站专注网络营销推广公司
  • 怎么做网站浮动模块seo短期培训班
  • 阜宁做网站的公司软件开发培训机构去哪个学校
  • 网站建设教学视频汕头网站推广
  • 开发网站服务fifa世界排名最新
  • 做网站用php如何学习连云港网站seo
  • 成都flash互动网站开发百度关键词排名点击器
  • 大型自助建站平台关键词优化公司哪家好
  • 生鲜网站建设规划书范文淘宝定向推广
  • 中国自适应网站建设百度指数关键词搜索趋势
  • 无锡网站推广seo的定义
  • 找客户在公司做网站seo快速排名外包
  • 用css做商务网站的代码办公软件速成培训班
  • 安宁网站建设熊掌号网站推广优化外包公司哪家好
  • 做门面商铺比较好的网站深圳市社会组织总会
  • 网站推广做的比较好的公司seo工作职位
  • 地产网站建设百度百度地图
  • 企业网站建设 优化友情链接平台哪个好
  • 如何使用腾讯云建网站查网站
  • 做招聘网站的怎么引流求职者如何在网上推广自己
  • 做国际贸易的一般用什么平台seo外链工具软件
  • 智慧团建网站登录操作网络营销策划书包括哪些内容
  • 独立设计师怎么找西安seo网站优化
  • wordpress建好站了打不开首页海外广告投放渠道
  • 重庆沙坪坝最新疫情seo优化服务是什么意思
  • 扬州市城市建设投资公司网站如何快速推广自己的品牌
  • 自建网站步骤在线工具网站
  • 南通网络公司网站搜索推广广告