Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RubyLouvre opened this issue May 23, 2019 · 1 comment
Open

Comments

@RubyLouvre
Copy link
Owner

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

@RubyLouvre
Copy link
Owner Author

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)
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant