Extends
- Backbone.View
Members
(readonly) component :Lateralus.Component
A reference to the
to which this Lateralus.Component
belongs.Lateralus.Component.View
- Source:
Type:
components :Object.<Lateralus.Component>
The subcomponents belonging to this object. Do not modify this property directly, it is managed by Lateralus.
- Mixes In:
- Source:
Type:
-
Object.<Lateralus.Component>
lateralusEvents :Object|undefined
A map of functions or string references to functions that will
handle events dispatched to the
central
instance.Lateralus
const ExtendedComponent = Lateralus.Component.extend({
name: 'extended',
lateralusEvents: {
anotherComponentChanged: 'onAnotherComponentChanged',
anotherComponentDestroyed: function () {
// ...
}
},
onAnotherComponentChanged: function () {
// ...
}
});
- Mixes In:
- Default Value:
- undefined
- Source:
Type:
-
Object
|undefined
modelEvents :Object|undefined
A map of functions or string references to functions that will
handle events emitted by
this.model
.
const ExtendedComponent = Lateralus.View.extend({
modelEvents: {
changed:someProperty: function (model, someProperty) {
// ...
}
}
});
- Mixes In:
- Default Value:
- undefined
- Source:
Type:
-
Object
|undefined
parentView :Lateralus.Component.View|null
If this is a subview of another
, this
property is a reference to the parent Lateralus.Component.View
.Lateralus.Component.View
Properties:
Name | Type | Description |
---|---|---|
parentView |
- Default Value:
- null
- Source:
Type:
-
Lateralus.Component.View
|null
provide :Object|undefined
A map of functions that will handle
calls. Each of the functions attached to this Object should return a
value. These functions must be completely synchronous.Lateralus.mixins#collect
const App = Lateralus.beget(function () {
Lateralus.apply(this, arguments);
});
_.extend(App.prototype, {
provide: {
demoData: function () {
return 1;
}
}
});
const app = new App();
const ComponentSubclass = Lateralus.Component.extend({
name: 'provider',
provide: {
demoData: function () {
return 2;
}
}
});
app.addComponent(ComponentSubclass);
console.log(app.collect('demoData')); // [1, 2]
- Mixes In:
- Source:
Type:
-
Object
|undefined
template :string|null
The DOM template to be used with this View.
- Default Value:
- {null}
- Source:
Type:
-
string
|null
Methods
addSubview(Subview, subviewOptionsopt) → {Lateralus.Component.View}
Adds a subview. Subviews are lighter than subcomponents. It is preferable to use a subview rather than a subcomponent when there is clear interdependency between two Views. This pattern is useful when you want to keep display logic well-organized into several Views, but have it compartmentalized within a single component.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
Subview |
Lateralus.Component.View
|
A constructor, not an instance. |
|
subviewOptions |
Object
|
<optional> |
Backbone.View constructor options to pass along to the subview when it is instantiated. |
deferredInitialize()
A function to be called in the next JavaScript thread. This can be necessary for situations where setup logic needs to happen after a View has been rendered.
In other words,
runs before
the View has been rendered to the DOM, and Lateralus.Component.View#initialize
deferredInitialize
runs
immediately after it has been rendered.
- Source:
dispose()
Remove this
from
the DOM and cleanly dispose of any references.Lateralus.Component.View
- Source:
getTemplateRenderData() → {Object}
This method returns the object whose properties are used as render
variables in
. The method
can be overridden.Lateralus.Component.View#renderTemplate
- Source:
Returns:
- Type:
-
Object
The raw Backbone.Model
data, if this View has a Model.
Otherwise, an empty object is returned.
initialize(optsopt)
This is called when a
is initialized, it
is not called directly.Lateralus.Component.View
subclasses that
override Lateralus.Component.View
initialize
must call this base method:
const Base = Lateralus.Component.View;
const baseProto = Base.prototype;
const ExtendedComponentView = Base.extend({
initialize: function () {
baseProto.initialize.apply(this, arguments);
// Other logic...
}
});
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opts |
Object
|
<optional> |
Any properties or methods to attach to this
|
renderTemplate()
Meant to be called by
and
infrequently thereafter, this method empties out
Lateralus.Component.View#initialize
$el
and does a full re-render.
render
should only be used for
partial renders.
- Source:
toString() → {string}
- Source:
Returns:
- Type:
-
string
The name of this View. This is used internally by Lateralus.