Fundamentals - Creating Components III

The Component Life cycle:

- constructor ( ) The view-model's constructor is called first.

- created (owningView: View, myView: View) If the view-model implements the created callback it is invoked next. At this point in time, the view has also been created & both the view-model & the view are connected to their controller. The created callback will receive the instance of the "owningView". This is the view that the component is declared inside of. If the component itself has a view, this will be passed second

- bind (bindingContext: Object, overrideContext: Object) Databinding is then activated on the view & view-model. If the view-model has a bind callback, it will be invoked at this time. The "binding context" to which the component is being bound will be passed first. An "override context" will be passed second. The override context contains information used to traverse the parent hierarchy & can also be used to add any contextual properties that the component wants to add.

- attached ( ) Next, the component is attached to the DOM(in document). If the view-model has an attached callback, it will be invoked at this time
- detached ( ) At some point in the future, the component may be removed from the DOM. If/When this happens & if the view-model has a detached callback, this is when it will be invoked.

- unbind ( ) After a component is detached, it's usually unbound. If view-model has the unbind callback, it will be invoked during this process.

each of these callbacks is optional. If you implement bind you will need to implement unbind. The same goes for attached & detached

Comments

Popular posts from this blog

Fundamentals - App Config & Startup - VIII

Fundamentals - Dependency Injection V

Style vs Css attribute