颤音再投入模式
下面段落中谈到了什么是重新投入模式/成员变量?这是什么例子?来自Flutter官方文档: “因为小部件是不变的,如果元素没有将自己标记为脏,则该元素可以立即从构建中返回,切断步行,如果父母用相同的小部件重建元素。在两个小部件参考中,以确定新小部件与旧的小部件相同。 成员变量在其构建中。”
What is a reprojection pattern/member variable talked about in the paragraph below? What is an example of that? From Flutter official docs:
"Because widgets are immutable, if an element has not marked itself as dirty, the element can return immediately from build, cutting off the walk, if the parent rebuilds the element with an identical widget. Moreover, the element need only compare the object identity of the two widget references in order to establish that the new widget is the same as the old widget. Developers exploit this optimization to implement the reprojection pattern, in which a widget includes a prebuilt child widget stored as a member variable in its build."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够在 this github问题。
如果我们看一下 docs>是标题为“绩效优化”的标题,描述了以下内容的再投影:
从中,我们可以看到“重新投入”是当我们预先建造小部件树的一部分并将其作为参数传递给经常重建的小部件时。这样,每次重建小部件时,它都可以捷径建造其小部件树的预先建造部分。
I was able to find an answer to this thanks to @Hixie on this Github issue.
If we take a look at the docs for AnimatedBuilder as recommended, there is a heading titled 'Performance optimizations' that describes reprojection as follows:
From this, we can see that 'reprojection' is when we pre-build a portion of the widget tree and pass it as a parameter to a widget that is frequently rebuilt. That way, each time the widget is rebuilt, it can shortcut building the pre-built portion of its widget tree.