San components use HTML-based template syntax in order too keep their lifecycles consistent with WebComponents.
compiled
- Compiled the template of a componentinited
- Initialized a component instance with template and datacreated
- Created a component elementattached
- Attached a component to DOMdetached
- Detached a component from DOMdisposed
- Destoryed a component instance
The lifecycle of a component has some of these features.
- The lifecycle represents the state of the component. The essence of the lifecycle is state management.
- At the different stages of the life cycle, the component will trigger the corresponding hook functions.
- States coexist such as
attached
andcreated
. - States are mutually exclusive such as
attached
anddetached
,disposed
and others. - Some time points do not represent the state of the component, only a certain behavior. The hook function is also triggered when the behavior is completed. For example, updated represents the completion of the view change caused by each data change.
Through the hook function of the life cycle, we can customize to do something in different lifecycles. For example, in the attached lifecycle initiate a request to get data, and then update the data to refresh the view.
1 | var ListComponent = san.defineComponent({ |
The following diagram details the lifecycle of the component