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
(
private
static
-
properties
-
[constructorProperties]
Extend the Controller class with user-defined instance properties, as well as constructor properties.
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 overridden by patch dictionary.
Parameters:
-
options
ObjectOptions to be patched -
patch
...ObjectOptions to override
Returns:
Object:
source
OptionsManager.setOptions
(
Object
-
instance
-
options
-
defaults
Constructor method. Convenience method to set options with defaults on an object instance.
Parameters:
Returns:
Object:
Patched options
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