-
Notifications
You must be signed in to change notification settings - Fork 3
Element Controller vs Instance
In small examples of input elements each element can act on its own without much trouble. In more complex examples you need central coordination. The controller part of the MVC pattern is meant for this. The MVC pattern is for another era of programming and trying to implement it explicitly in a web browser will gain you little good and lots of pain. The HTML DOM are in some ways a level above View/Model, and in some ways below.
Enhanced element handlers can define an instance for the element. You are free to create any object you like so this can be a controller. To mark it as one set controller to true in the data-role.
<div role="application" data-role="'generator':'MultiFaceted','controller':true">
</div>
This element will instantiate the function/generator MultiFaceted and set it as the instance for the DIV element. The instance must support the controller call interface and will act as the controller.
You can also create a separate controller object.
<div role="presentation" data-role="'controller':'MultiFaceted'">
</div>
This element will not create any instance in the handler as presentation doesn't have an enhance handler. The controller will be instantiated in addition, independent of the role handlers.
When a controller is about to be used with an enhanced element such as when the element enhance handler is called the controller init method is called. It will only be called once.
If the controller has an init method it will be called with the signature init(el,config,context).
When the enhanced element that the controller is tied with is destroyed the controller is notified.
If the controller has a destroy method it will be called with the signature destroy(el,config,config).
If the controller has an enhanced method, it will be called when an element is enhanced with the
signature enhanced(el,instance,config,context).
If the controller has an destoyed method, it will be called when an element is destroyed with the
signature destroyed(el,instance).
If the controller has an discarded method, it will be called when an element is discarded with the
signature discarded(el,instance).