内容简介:TheInputWhen each node is assigned to a slot, this slot is also added to the node's
The slotting algorithm assigns nodes of a shadow tree host into slots of that tree.
Input HOST -- a shadow tree host Output All child nodes of HOST are slotted
- Let TREE be HOST 's shadow tree
- Let DEFAULT be an empty list of nodes
- For each child node NODE of HOST , in tree order:
- Let NAME be NODE 's slot name
- If NAME is missing, add NODE to DEFAULT
- Let SLOT be the slot with slot name NAME for TREE
- If SLOT does not exist, discard node
- Otherwise, assign NODE to SLOT
- Let DEFAULT-SLOT be the the default slot for TREE
- If DEFAULT-SLOT does not exist, stop
- Otherwise, assign all nodes in DEFAULT to DEFAULT-SLOT .
When each node is assigned to a slot, this slot is also added to the node's destination insertion points list.
这是w3c web components规范的一个提案,地址位于https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Slots-Proposal.md
在这个提案中,我们发现 shadow DOM和shadow Tree 这两个概念,关于它们的规范,在这里: w3c.github.io/webcomponen…
mdn上关于shadow DOM的一篇特别好的文章: developer.mozilla.org/en-US/docs/…
Shadow DOM : attach a hidden separated DOM to an element.
几个shadow DOM的专业术语:
- Shadow host: shadow DOM要连接的普通DOM节点。
- Shadow tree: shadow DOM里的DOM树。
- Shadow boundary: Shadow DOM结束的地方,也是普通DOM开始的地方。
- Shadow root:shadow tree的根节点。
Shadow DOM知识点:
- shadow DOM和普通DOM一样可以添加子节点设置属性,但是shadow DOM内部的代码不能影响到外部的任何东西。
- shadow DOM其实一直都在用,例如
- 两种模式mode:open,closed。
shadow DOM的作用是什么: 增强组件内聚性 。
An important aspect of web components is encapsulation — being able to keep the markup structure, style, and behavior hidden and separate from other code on the page so that different parts do not clash, and the code can be kept nice and clean.
vue demo: component.vue -> shadow host
<slot></slot> <slot name="foo"></slot> <slot name="bar"></slot> 复制代码
page.vue -> shadow Tree
<span>+</span> <span slot="foo">-</span> <span slot="bar">2</span> <span slot="bar">3</span> 复制代码
渲染结果:
渲染结果与slot算法十分契合,但是较为奇怪的是,vue的slot机制,不会生成像w3c web component 的shadow DOM。
web component shadow DOM是下面这样:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
算法设计与分析基础
Anany levitin / 潘彦 / 清华大学出版社 / 2007-1-1 / 49.00元
作者基于丰富的教学经验,开发了一套对算法进行分类的新方法。这套方法站在通用问题求解策略的高度,能对现有的大多数算法都能进行准确分类,从而使本书的读者能够沿着一条清晰的、一致的、连贯的思路来探索算法设计与分析这一迷人领域。本书作为第2版,相对第1版增加了新的习题,还增加了“迭代改进”一章,使得原来的分类方法更加完善。 本书十分适合作为算法设计和分析的基础教材,也适合任何有兴趣探究算法奥秘的读者......一起来看看 《算法设计与分析基础》 这本书的介绍吧!