Core.Controller Class
Uses
Defined in:
samsara/core/Controller.js:8
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
(
private
-
options
Parameters:
-
options
ObjectInstance 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
Item Index
Methods
Attributes
Methods
"on"
(
-
type
-
handler
Adds a handler to the
type
channel which will be executed on emit
.
extend
(
-
protoObj
-
constants
Allows a class to extend Controller. Note: this is a method defined on the Controller constructor
get
(
Object
-
key
Look up options value by key or get the full options hash.
Parameters:
-
key
StringKey
Returns:
Object:
Associated object or full options hash
getOptions
(
Object
-
key
Options getter.
Parameters:
-
key
StringKey
Returns:
Object:
object Options value for the key
key
(
OptionsManager
-
key
Return OptionsManager based on sub-object retrieved by
key
.
Parameters:
-
key
StringKey
Returns:
OptionsManager:
Value
off
(
-
type
-
handler
Removes the
handler
from the type
channel.
This undoes the work of on
.
OptionsManager.patch
(
Object
-
options
-
patch
Constructor method. Create OptionsManager from source dictionary with arguments overriden by patch dictionary.
Parameters:
-
options
ObjectOptions to be patched -
patch
...ObjectOptions to overwrite
Returns:
Object:
source
patch
(
OptionsManager
-
options
Patch options with provided patches. Triggers
change
event on the object.
Parameters:
-
options
ObjectPatch options
Returns:
OptionsManager:
this
set
(
OptionsManager
-
key
-
value
Set key to value. Outputs
change
event if a value is overwritten.
Returns:
OptionsManager:
Updated OptionsManager