Class: controller

Suit. controller

new Suit.controller()

Reference to the container of Controller features.

Members

staticSuit.controller.listArray.<Controller>

List of registered controllers.

Methods

staticSuit.controller.add(p_target, p_view){Controller}

Attaches a controller to the pool.

Name Type Description
p_target Controller

Reference to the controller instance.

p_view String | Element nullable

Path or Reference to the view element to be watched.

Returns:
Type Description
Controller
  • Reference to the added controller.
Example

var homeController = {
allow: ["click","change","input"], //defaults to these events. Can be 'null'
enabled: true, //defaults to true. Can be 'null'
view: null, //starts 'null' but, after added to a view, holds its view reference (no need to declare splicitly)
on:
function(n) { //callback to handle events parsed as 'ControllerNotification'
switch(n.path) {
case "welcome":
//Entry point for all controllers.
break;

     case "path.to.view@click":
     //Captured 'click' event inside/including 'this.view'
     break;
 }

}
};

Suit.controller.add(homeController); //Will attach a Controller to 'document.body'.
Suit.controller.add(homeController,"path.to.view"); //Will remove it from 'document.body' and attach it to a view at 'path.to.view'

staticSuit.controller.clear()

Removes all controllers from the pool.

staticSuit.controller.dispatch(p_path, p_data)

Dispatches a notification for all enabled controllers in the pool.
The format of the 'path' can be either 'path.to.event' or 'path.to.event@type'

Name Type Description
p_path String

String with a path that describes the event context.

p_data Object nullable

Extra data to be passed to the event.

Example

var c = {
on: function(n){
switch(n.path) {

 case "some.event": console.log("some event"); break;
 case "some.event@hi": console.log("hi! "+n.data.msg);     break;

 }

}
};

Suit.controller.add(c);

Suit.controller.dispatch("some.event"); //Will log 'some event'.
Suit.controller.dispatch("some.event@hi",{msg: "John"}); //Will log 'hi! John'.

c.enabled = false;

Suit.controller.dispatch("some.event"); //No log.

staticSuit.controller.remove(p_target){Object}

Removes the controller from the pool.

Name Type Description
p_target Object

Reference to the controller instance.

Returns:
Type Description
Object
  • Reference to the removed controller.
Example

var c = {...};
Suit.controller.add(c); //Suit.controller.list.length == 1
Suit.controller.remove(c); //Suit.controller.list.length == 0

comments powered by Disqus