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

做网站公司的排名网络营销知名企业

做网站公司的排名,网络营销知名企业,cms免费开源,武宣县住房和城乡建设局网站起源: 当看见reactivity文件中的ref.ts文件长达五百多的ts代码后,突发奇想想看下转化成js有多少行。 进行转化: let shouldTrack true; // Define shouldTrack variable let activeEffect null; // Define activeEffect variable// 定义…

起源:

当看见reactivity文件中的ref.ts文件长达五百多的ts代码后,突发奇想想看下转化成js有多少行。

进行转化:

let shouldTrack = true; // Define shouldTrack variable
let activeEffect = null; // Define activeEffect variable// 定义 ref 函数
function ref(value) {return createRef(value, false);
}// 浅的引用 ref
function shallowRef(value) {return createRef(value, true);
}// 创造 ref 函数
function createRef(rawValue, shallow) {// 判断 rawValue 是不是 ref 类型的if (isRef(rawValue)) {// 是的话直接 returreturn rawValue;}// 不是的话 使用:RefImpl 将其变成ref对象后return出去return new RefImpl(rawValue, shallow);
}
// 定义 ref的 对象 RefImpl 类
class RefImpl {constructor(value, isShallow) {this._rawValue = isShallow ? value : toRaw(value);this._value = isShallow ? value : toReactive(value);}get value() {trackRefValue(this);return this._value;}set value(newVal) {const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);newVal = useDirectValue ? newVal : toRaw(newVal);if (hasChanged(newVal, this._rawValue)) {this._rawValue = newVal;this._value = useDirectValue ? newVal : toReactive(newVal);triggerRefValue(this, DirtyLevels.Dirty, newVal);}}
}function trackRefValue(ref) {if (shouldTrack && activeEffect) {ref = toRaw(ref);trackEffect(activeEffect,(ref.dep ??= createDep(() => (ref.dep = undefined),ref instanceof ComputedRefImpl ? ref : undefined,)),__DEV__? {target: ref,type: TrackOpTypes.GET,key: 'value',}: void 0);}
}function triggerRefValue(ref, dirtyLevel = DirtyLevels.Dirty, newVal) {ref = toRaw(ref);const dep = ref.dep;if (dep) {triggerEffects(dep,dirtyLevel,__DEV__? {target: ref,type: TriggerOpTypes.SET,key: 'value',newValue: newVal,}: void 0);}
}
// 判断是不是ref
function isRef(r) {return !!(r && r.__v_isRef === true);
}function toRaw(observed) {return observed;
}function toReactive(value) {return value;
}let result = ref(0);
console.log(result);

转化完毕,相信看过源码的小伙伴一经发现,转化前的代码非常臃肿且难以阅读,转化后的代码轻便易于阅读,且能快速在浏览器的控制台调试和实现ref的功能。

最后我们通过打印result可以看到输出了一个RefImpl对象,之后我们通过打印result.value即可获得我们当初传给ref的0

经过测试,发现输出的颜色很淡的values是class类中的get values方法

当传进_value的值的时候,因为构造函数中的get values方法是return的,所以在最后的console中点开values是可以看见: "这里是_values"输出的

将get values函数中return改为console后,打印出来的values就是undefined了,因为没有向外return了

同理,这时候想要学习vue3,通过john.values就可以打印出: "这里是_value"了.

但是感觉下面的_value和value是一个东西,可以用_value统一起来方便看:

class RefImpl {
  constructor(value, isShallow) {
    this._rawValue = isShallow ? value : toRaw(value);
    this._value = isShallow ? value : toReactive(value);
  }

  get value() {
    trackRefValue(this);
    return this._value;
  }

  set value(newVal) {
    const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
    newVal = useDirectValue ? newVal : toRaw(newVal);
    if (hasChanged(newVal, this._rawValue)) {
      this._rawValue = newVal;
      this._value = useDirectValue ? newVal : toReactive(newVal);
      triggerRefValue(this, DirtyLevels.Dirty, newVal);
    }
  }
}

上述: get value方法中return的this._value就是constructor中穿进去的value,统一更方便看.

http://www.khdw.cn/news/26351.html

相关文章:

  • 部署自己做的网站吗手机优化专家下载
  • 网站弹窗在中间位置长沙弧度seo
  • 哈尔滨哪里做网站好网站seo的方法
  • 专用车网站建设多少钱百度指数官网登录
  • 泉州网站建设哪家好网络运营商
  • cpa项目怎么做必须有网站么云建站模板
  • 重庆网站排名推广站内关键词排名软件
  • 外贸b2c商城网站建设找个网站
  • 眉山做网站网站怎么找
  • 做网站服务器空间b站刺激战场视频
  • 无锡做网站的公司电话企业网站设计规范
  • 网站建设的英语怎么说网络营销方式方法
  • 推广app赚佣金平台有哪些中国十大seo公司
  • 小程序模板做视频网站郑州seo网站管理
  • 汕头市政府官网seo页面代码优化
  • 长沙岳麓区做网站百度收录
  • 保定网站建设培训班营销技巧第三季
  • 阳江做网站详细解读关键词数据分析
  • 关注网站建设福建seo外包
  • 如何判断一个网站的关键词是否难做做百度网站一年多少钱
  • 买个域名自己做网站吗百度高级搜索页面的网址
  • 网站首页结构昆明seo推广外包
  • 自媒体还是做网站代理公司注册
  • 如何做中英文网站设计百度应用市场app下载
  • 折扣网站怎么做软文写作技巧及范文
  • 带音乐网站模板在哪里打广告效果最好
  • 网站建站与优化怎么开个人网站
  • wordpress只显示标题宁波seo推广服务电话
  • 开发一块地需要多少钱seo关键词外包
  • 在线手机客服系统seo关键词优化排名公司