Controller.Stateful provides state for controller instances. Controller.Stateful is useful for
creating self-contained widgets or when there are many instances of an object that has complex state.
Read the
fixedbox demo
for good an example of using Controller.Stateful.
Example
The following is a a small piece of the SliderController.
SliderController = MVC.Controller.Stateful('slider',{
init : function(element, options){
this.options = options ||{}
this._super(MVC.$E(element))
},
'.slider dragstart' : function(params){
params.horizontal()
},
'.slider dragging' : function(params){
//check pos
this.options.sliding(pos, params) //callback with position
}
})
You would create a new Slider like:
new SliderController('element_id',{sliding: function(pos){console.log(pos)});
Naming
Naming works just similar to regular controllers. If the Controller's className is plural, it will insert an implicit
.singular_name before this controller's
event actions. If the controller is a singular name
nothing is added to the delegation class name.
How Stateful works
New stateful instances create a new delegation listening point on the element passed into the base
init function. As events happen on the element or child elements
of the instance, they call back to the controller instance.