Core.View Class
samsara/core/View.js:16
A View provides encapsulation for a subtree of the render tree. You can build
complicated visual components and add them to a render tree as you would a Surface
.
Custom Views
are created by calling extend
on the View
constructor.
In addition to what a Controller
provides, a View provides:
Render Tree method: .add
Size methods: setSize
, setProportions
Layout methods: setOpacity
, setOrigin
Constructor
Core.View
()
Example:
var MyView = View.extend({
defaults : {
defaultOption1 : '',
defaultOption2 : 42
},
initialize : function(options){
// this method called on instantiation
// options are passed in after being patched by the specified defaults
var surface = new Surface({
content : options.defaultOption1,
size : [options.defaultOption2,100],
properties : {background : 'red'}
});
this.add(surface);
}
});
var myView = new myView({defaultOption1 : 'hello'});
var context = Context();
context.add(myView);
context.mount(document.body);
Item Index
Methods
Attributes
Methods
"on"
-
type
-
handler
Adds a handler to the type
channel which will be executed on emit
.
add
-
object
Extends the render tree subtree with a new node.
Parameters:
-
object
SizeNode | LayoutNode | SurfaceNode
Returns:
extend
-
protoObj
-
constants
Allows a class to extend Controller. Note: this is a method defined on the Controller constructor
get
-
key
Look up options value by key or get the full options hash.
Parameters:
-
key
StringKey
Returns:
Associated object or full options hash
getOptions
-
key
Options getter.
Parameters:
-
key
StringKey
Returns:
object Options value for the key
key
-
key
Return OptionsManager based on sub-object retrieved by key
.
Parameters:
-
key
StringKey
Returns:
Value
off
-
type
-
handler
Removes the handler
from the type
channel.
This undoes the work of on
.
OptionsManager.patch
-
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:
source
patch
-
options
Patch options with provided patches. Triggers change
event on the object.
Parameters:
-
options
ObjectPatch options
Returns:
this
set
-
sources
Introduce new data streams to the layout node in {key : value} pairs.
Here the key
is one of "transform", "origin", "align" or "opacity".
The value
is either a stream, or a simple type like a Number
or Array
.
Simple types will be wrapped in an Observerable
to emit appropriate events.
Parameters:
-
sources
ObjectObject of data sources
setOrigin
-
origin
Setter for origin.
Parameters:
-
origin
Number[] | StreamOrigin as [x,y], or a stream.
setProportions
-
proportions
Setter for proportions.
Parameters:
-
proportions
Number[] | StreamProportions as [x,y], or a stream.
setProportions
-
proportions
Setter for proportions.
Parameters:
-
proportions
Number[] | StreamProportions as [x,y], or a stream.
setSize
-
size
Setter for size.
Parameters:
-
size
Number[] | StreamSize as [width, height] in pixels, or a stream.