SAP Spartacus cx-page-layout属性运行
2021-02-12 本文已影响0人
华山令狐冲
下图storefront.component.html的语义:
![](https://img.haomeiwen.com/i2085791/4cf6b151b5280bde.png)
将字符串header赋给cx-page-layout selector对应的Angular Component:
/**
* Creates an empty element using {@link elementStart} and {@link elementEnd}
*
* @param index Index of the element in the data array
* @param name Name of the DOM Node
* @param attrsIndex Index of the element's attributes in the `consts` array.
* @param localRefsIndex Index of the element's local references in the `consts` array.
*
* @codeGenApi
*/
function ɵɵelement(index, name, attrsIndex, localRefsIndex) {
ɵɵelementStart(index, name, attrsIndex, localRefsIndex);
ɵɵelementEnd();
}
![](https://img.haomeiwen.com/i2085791/6543b0b48fd733fb.png)
![](https://img.haomeiwen.com/i2085791/30de7222335612fc.png)
elementStart负责创建dom元素:
/**
* Create DOM element. The instruction must later be followed by `elementEnd()` call.
*
* @param index Index of the element in the LView array
* @param name Name of the DOM Node
* @param attrsIndex Index of the element's attributes in the `consts` array.
* @param localRefsIndex Index of the element's local references in the `consts` array.
*
* Attributes and localRefs are passed as an array of strings where elements with an even index
* hold an attribute name and elements with an odd index hold an attribute value, ex.:
* ['id', 'warning5', 'class', 'alert']
*
* @codeGenApi
*/
function ɵɵelementStart(index, name, attrsIndex, localRefsIndex) {
const lView = getLView();
const tView = getTView();
const adjustedIndex = HEADER_OFFSET + index;
ngDevMode &&
assertEqual(getBindingIndex(), tView.bindingStartIndex, 'elements should be created before any bindings');
ngDevMode && ngDevMode.rendererCreateElement++;
ngDevMode && assertIndexInRange(lView, adjustedIndex);
const renderer = lView[RENDERER];
const native = lView[adjustedIndex] = elementCreate(name, renderer, getNamespace());
const tNode = tView.firstCreatePass ?
elementStartFirstCreatePass(index, tView, lView, native, name, attrsIndex, localRefsIndex) :
tView.data[adjustedIndex];
setPreviousOrParentTNode(tNode, true);
const mergedAttrs = tNode.mergedAttrs;
if (mergedAttrs !== null) {
setUpAttributes(renderer, native, mergedAttrs);
}
const classes = tNode.classes;
if (classes !== null) {
writeDirectClass(renderer, native, classes);
}
const styles = tNode.styles;
if (styles !== null) {
writeDirectStyle(renderer, native, styles);
}
appendChild(tView, lView, native, tNode);
// any immediate children of a component or template container must be pre-emptively
// monkey-patched with the component view data so that the element can be inspected
// later on using any element discovery utility methods (see `element_discovery.ts`)
if (getElementDepthCount() === 0) {
attachPatchData(native, lView);
}
increaseElementDepthCount();
if (isDirectiveHost(tNode)) {
createDirectivesInstances(tView, lView, tNode);
executeContentQueries(tView, tNode, lView);
}
if (localRefsIndex !== null) {
saveResolvedLocalsInData(lView, tNode);
}
}
![](https://img.haomeiwen.com/i2085791/54665575fe47dfa7.png)
Instantiate all the directives that were previously resolved on the current node
![](https://img.haomeiwen.com/i2085791/391c4107cbd0a53f.png)
在这里进行的赋值:
![](https://img.haomeiwen.com/i2085791/ffc1b6b14c07a6a5.png)
![](https://img.haomeiwen.com/i2085791/1c3ad9cfec515c61.png)
![](https://img.haomeiwen.com/i2085791/1f66db409a2800c9.png)
最后的结果,调用Component的set方法:
![](https://img.haomeiwen.com/i2085791/18e2a1bc10755e51.png)
更多Jerry的原创文章,尽在:"汪子熙":
![](https://img.haomeiwen.com/i2085791/7cc33388ba14e967.png)