目标

  • [] 11:00-12:00 typescript
  • [] 15:00-16:00 vue3
  • [] 16:30-17:30 英语

琐碎

简易的响应式系统

  const bucket = new WeakMap();
  const data = { txt: 'hello world' };
  const obj = new Proxy(data, {
    get(target, key) {
      //没有activeEffect直接return
      if (!activeEffect) return target[key];
      //根据target取出桶中的depsMap,depsMap是Map类型,表示为key->effects Set
      let depsMap = bucket.get(target);
      //在桶中新建map与target关联
      if (!depsMap) {
        depsMap = new Map();
        bucket.set(target, depsMap);
      }

      let deps = depsMap.get(key);
      if (!deps) {
        deps = new Set();
        depsMap.set(key, deps);
      }
      //这里是读取操作,最后需将激活的副作用函数收集在桶中
      deps.add(activeEffect);

      console.log('bucket', bucket);
      return target[key];
    },

    set(target, key, newVal) {
      target[key] = newVal;

      const depsMap = bucket.get(target);
      if (!depsMap) return true;
      const deps = depsMap.get(key);
      if (!deps) return true;
      deps.forEach((fn) => fn());
      return true;
    },
  });
  //注册副作用函数
  let activeEffect;
  function effect(fn) {
    console.log('effect run');
    activeEffect = fn;
    fn();
  }
  effect(() => {
    console.log('1');
    //读取操作
    document.body.innerText = obj.txt;
  });
  obj.txt = '666';

关于weakMap

圾回收机制。这意味着在没有其他引用存在时垃圾回收能正确进行。原生 WeakMap 的结构是特殊且有效的,其用于映射的 key 只有在其没有被回收时才是有效的。正由于这样的弱引用,WeakMap 的 key 是不可枚举的(没有方法能给出所有的 key)

ref

ref 在模板中作为顶层属性被访问时,它们会被自动“解包”,所以不需要使用 .value

每日英语

这里有一些考研英语的单词,希望对您有所帮助:

  1. Process [prəˈses] n. 过程、工序、程序 vt. 加工、处理 例句:The process of making wine involves many steps.

  2. Growth [ɡroʊθ] n.增加、增长(量);生长,发展 例句:The growth of the economy is a positive sign for the country.

  3. Technology [tekˈnɑːlədʒi] n.工艺、技术 例句:Advances in technology have made our lives easier.

  4. Theory [ˈθɪri] n.理论、原理;学说;看法、见解 例句:Einstein's theory of relativity revolutionized our understanding of space and time.

  5. Economy [ɪˈkɑːnəmi] n.经济(制度)、经济情况;节约、省俭 例句:The government is taking measures to boost the economy.

  6. Behavior [bɪˈheɪvjər] n.行为、举止;运转情况 例句:His behavior at the party was unacceptable.

  7. Account [əˈkaʊnt] n.账(目)、账户;叙述、说明 vi.说明(原因等)、(数量、比例方面)占 例句:She gave a detailed account of the events that occurred.

  8. Economic [ˌikəˈnɑːmɪk] adj.经济(学)的,经济上的 例句:The economic situation in the country is improving.

  9. Individual [ˌɪndɪˈvɪdʒuəl] adj.单独的,个人的 例句:Each individual has their own unique talents and abilities.

  10. Create [kriˈeɪt] vt.创造、创建、创作;引起、产生 例句:The artist was able to create a beautiful painting using only a few colors.

总结

今日除了上午的ts没怎么学,其他的都圆满完成,甚至中午还看了一会机器学习(吴恩达),好耶。。。。

在《聪明人的个人成长》一书中,看到了“一体”的概念,当把眼前所见的一切都视作“我”,便会感到世界的明亮,世界便是“我”,我便无需为任何事情烦恼。

明日目标

  • [] 11:00-12:00 typescript
  • [] 15:00-16:00 vue3响应式原理看完
  • [] 16:30-17:30 英语