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

before mutation阶段文档和源码不一致 #75

Open
zjw666 opened this issue May 6, 2021 · 8 comments
Open

before mutation阶段文档和源码不一致 #75

zjw666 opened this issue May 6, 2021 · 8 comments

Comments

@zjw666
Copy link

zjw666 commented May 6, 2021

如题,commit的before mutation阶段,源码分为commitBeforeMutationEffects_begin,commitBeforeMutationEffects_complete,使用subtree的方式进行遍历。除此之外,flushPassiveEffects的遍历方式也有一定变化,大佬有时间可否更新下?

function commitBeforeMutationEffects_begin() {
  while (nextEffect !== null) {
    var fiber = nextEffect; // TODO: Should wrap this in flags check, too, as optimization

    var deletions = fiber.deletions;

    if (deletions !== null) {
      for (var i = 0; i < deletions.length; i++) {
        var deletion = deletions[i];
        commitBeforeMutationEffectsDeletion(deletion);
      }
    }

    var child = fiber.child;

    if ((fiber.subtreeFlags & BeforeMutationMask) !== NoFlags && child !== null) {
      ensureCorrectReturnPointer(child, fiber);
      nextEffect = child;
    } else {
      commitBeforeMutationEffects_complete();
    }
  }
}

function commitBeforeMutationEffects_complete() {
  while (nextEffect !== null) {
    var fiber = nextEffect;

    {
      setCurrentFiber(fiber);
      invokeGuardedCallback(null, commitBeforeMutationEffectsOnFiber, null, fiber);

      if (hasCaughtError()) {
        var error = clearCaughtError();
        captureCommitPhaseError(fiber, fiber.return, error);
      }

      resetCurrentFiber();
    }

    var sibling = fiber.sibling;

    if (sibling !== null) {
      ensureCorrectReturnPointer(sibling, fiber.return);
      nextEffect = sibling;
      return;
    }

    nextEffect = fiber.return;
  }
}
@BetaSu
Copy link
Owner

BetaSu commented May 6, 2021

使用的哪个版本呢? 书里使用的是 v17.0.0-alpha

@zjw666
Copy link
Author

zjw666 commented May 6, 2021

没看到这个版本了呢?
image

@BetaSu
Copy link
Owner

BetaSu commented May 6, 2021

可以使用 从书里的链接跳转的源码地址, 换成subtree也仅仅改变了commit阶段节点的遍历方式,后续操作还是一样的

@zjw666
Copy link
Author

zjw666 commented May 6, 2021

大佬书写的很好,赞一个。但是,17版本的都是用的subtree的方式了,虽然代码整体流程是变化不大,但有些代码和函数和书中对不上,比较影响阅读体验,尤其是对我这种菜鸟小白,大佬有空可以更新一波。

@BetaSu
Copy link
Owner

BetaSu commented May 6, 2021

subtree 其实翻来覆去好几次了, 之前Andrew Clark就合过一次,后来因为性能原因又revert了, 等他合并到稳定版为再看,令人伤心。。。

@zjw666
Copy link
Author

zjw666 commented May 6, 2021

嗯,嗯,看起来应该稳定了,17.0.x 和master都改了,大佬可以看看

@BetaSu
Copy link
Owner

BetaSu commented May 6, 2021

👌

@JunlinZhu-Tommy
Copy link
Contributor

我觉得还是可以稍微等一两周,找时间统一把代码更新到17.0.x的一个版本。因为现在书里面其实还有一些不一致的地方,这样零散的改效果不太好。

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

3 participants