Skip to content

Element Controller vs Instance

Henrik Vendelbo edited this page Jan 31, 2014 · 6 revisions

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.

Clone this wiki locally