anu icon indicating copy to clipboard operation
anu copied to clipboard

提供一种机制,更好地对不需要的功能进行tree shaking

Open RubyLouvre opened this issue 6 years ago • 1 comments

上一次升级中已经可以对不同的React Hooks进行tree shaking。tree shaking需要对框架内部模块的依赖进行梳理,由表至内。

RubyLouvre avatar May 23 '19 15:05 RubyLouvre

function Node(val) {
      this.value = val
    }
    var a = new Node(1)
    var b = a.child = new Node(2)
    var c = b.child = new Node(3)
    var d = c.sibling = new Node(4)
    var e = d.sibling = new Node(5)

    var f = b.sibling = new Node(6)
    f.sibling = new Node(7)


  
  function travelFiber(fiber, cb){
    var topWork = fiber
    outerLoop:
    while (fiber) {
      var a = cb(fiber)
      if(a === false){
        continue outerLoop;
      }
      if (fiber.child) {
        fiber.child.return = fiber
        fiber = fiber.child;
      
        continue outerLoop;
      }
     
      var f = fiber;
      while (f) {
        if (f === topWork) {
          console.log("结束所有")
          break outerLoop;
        }
     
        if (f.sibling) {
          f.sibling.return = f.return;
          fiber = f.sibling;
          continue outerLoop;
        }
        f = f.return;
      }
    }
  }
    var top1 = {
      child: a
    }
  travelFiber(top1, function(a){
console.log(a.value)
  })

RubyLouvre avatar Jul 11 '19 01:07 RubyLouvre