Show:

A utility class which can be extended by custom classes. These classes will then include event input and output streams, a optionsManager for handling optional parameters with defaults, and take an event dictionary.

Specifically, instantiations will have an options dictionary property, input, output stream properties, and on, off, emit, trigger, subscribe, unsubscribe methods.

Constructor

Core.Controller

(
  • options
)
private

Parameters:

  • options Object

    Instance options

Example:

 var MyClass = Controller.extend({
             defaults : {
                 defaultOption1 : value1,
                 defaultOption2 : value2
             },
             events : {
                 'change' : myUpdateOptionsFunction
             },
             initialize : function(options){
                 // this method called on instantiation
                 // options are passed in after being patched by the specified defaults
        
                 this.input.on('test', function(){
                     console.log('test fired');
                 });
             }
         });
        
         var myInstance = new MyClass({
             defaultOption1 : value3
         });
        
         // myInstance.options = {
         //     defaultOption1 : value3,
         //     defaultOption2 : value2
         // }
        
         myInstance.subscribe(anotherStream);
        
         anotherStream.emit('test'); // "test fired" in console

Methods

"on"

(
  • type
  • handler
)

Inherited from Core.OptionsManager:

Adds a handler to the type channel which will be executed on emit.

Parameters:

extend

(
  • protoObj
  • constants
)

Allows a class to extend Controller. Note: this is a method defined on the Controller constructor

Parameters:

  • protoObj Object

    Prototype properties of the extended class

  • constants Object

    Constants to be added to the extended class's constructor

get

(
  • key
)
Object

Inherited from Core.OptionsManager:

Look up options value by key or get the full options hash.

Parameters:

Returns:

Object: Associated object or full options hash

getOptions

(
  • key
)
Object

Inherited from Core.OptionsManager but overwritten in

Options getter.

Parameters:

Returns:

Object:

object Options value for the key

key

(
  • key
)
OptionsManager

Inherited from Core.OptionsManager:

Return OptionsManager based on sub-object retrieved by key.

Parameters:

Returns:

OptionsManager: Value

off

(
  • type
  • handler
)

Inherited from Core.OptionsManager:

Removes the handler from the type channel. This undoes the work of on.

Parameters:

OptionsManager.patch

(
  • options
  • patch
)
Object

Inherited from Core.OptionsManager but overwritten in

Constructor method. Create OptionsManager from source dictionary with arguments overriden by patch dictionary.

Parameters:

  • options Object
    Options to be patched
  • patch ...Object
    Options to overwrite

Returns:

Object: source

patch

(
  • options
)
OptionsManager

Inherited from Core.OptionsManager:

Patch options with provided patches. Triggers change event on the object.

Parameters:

  • options Object
    Patch options

Returns:

OptionsManager: this

set

(
  • key
  • value
)
OptionsManager

Inherited from Core.OptionsManager:

Set key to value. Outputs change event if a value is overwritten.

Parameters:

Returns:

OptionsManager: Updated OptionsManager

setOptions

(
  • options
)

Inherited from Core.OptionsManager but overwritten in

Options setter.

Parameters:

Attributes

DEFAULT_OPTIONS

readonly

Overwrite the DEFAULT_OPTIONS dictionary on the constructor of the class you wish to extend with the Controller to patch any options that are not prescribed on instantiation.

EVENTS

readonly

Overwrite the EVENTS dictionary on the constructor of the class you wish to extend with the Controller to include events in {key : value} pairs where the keys are event channel names and the values are functions to be executed.