3.4.0 The component reversion
mechanism has been fully upgraded. The new mechanism is based on data and template matching, replacing the original marking mechanism.
Old tag-based [component inverse] refer to reverse-flag
version
:>= 3.4.0
tips
: The component can be server-side rendered in San, and it must be reversed on the browser side with the same version of San.
Overview
When the component is initialized, it is passed a el argument which will be the root element of the component, and the view structure will be parsed backwards.
The intent of this feature is that sometimes we want the initial view to be direct HTML, rather than being rendered by components. But we want components to manage data, logic, and views for us, and subsequent user interactions and view transformations are managed through components.
1 | var myComponent = new MyComponent({ |
When el initializes the component, San will respect the current HTML form of el and will not perform any additional rendering actions that affect the visual.
- Will not render the view using the default template
- Will not create a root element
- Direct access to compiled, created, attached lifecycle
Data
The view of the component is the rendering of the data. We need to mark data at the beginning of the component to specify the correct initial data. The initial data tag is an HTML comment starting with s-data:, in which the data is declared.
warning
:The process of San’s component reversion
is based on data and component templates for view structure backstepping and matching. The reversed component must have the correct tagged data, otherwise, the reverse-parsing process will occur errors. For example, when the view is reversed for the s-if
condition in the template, there is no correct markup data, and the backstepping will result in undesired outcomes because the elements do not correspond.
1 | <a id="wrap"><!--s-data:{ |
1 | var MyComponent = san.defineComponent({ |
If a component has owner, there is no need to mark the initial data. Its initial data is populated by the owner based on the binding relationship.
1 | <!-- ui-label a component has owner, there is no need to mark the initial data --> |
1 | var Label = san.defineComponent({ |
Composite interpolation text
San supports direct output of HTML in an interpolated text. In this case, the interpolated text corresponds to not a TextNode but may be multiple different types of elements. For this composite interpolated text, you need to add a comment before and after the content to mark it.
- The comment before the text is s-text, which means the start of an interpolated text fragment.
- The comment after the text is /s-text, which means the end of an interpolated text fragment.
1 | <a id="wrap"><!--s-data:{ |
1 | var MyComponent = san.defineComponent({ |