Component

Lateralus. Component

Lateralus.Component

Constructor

new Component(lateralus, options, viewOptions, opt_parentComponentopt)

The constructor for this method should not be called directly. Instead, use the Lateralus.mixins#addComponent mixin method:

const App = Lateralus.beget(function () {
  Lateralus.apply(this, arguments);
});

const app = new App(document.getElementById('app'));
const component = app.addComponent(Lateralus.Component);

console.log(component instanceof Lateralus.Component); // true
Mixes In:
Source:
Parameters:
Name Type Attributes Description
lateralus Lateralus
options Object

Values to attach to this Lateralus.Component instance. This object also get passed to the Lateralus.Component.initialize method, if one is defined.

Name Type Attributes Description
modelAttributes Object <optional>

Any attributes to pre-populate the Lateralus.Component.Model instance with, if there is one.

modelOptions Object <optional>

Any parameters to pass to the Lateralus.Component.Model instance, if there is one.

viewOptions Object

The options Object to pass to the Lateralus.Component.View constructor.

opt_parentComponent Lateralus.Component <optional>

The parent component of this component, if any.

Classes

Collection
Model
View

Members

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:

initialize :function|undefined

A method to be called when this Lateralus.Component has been set up.

Default Value:
  • undefined
Source:
Type:
  • function | undefined

(readonly) lateralus :Lateralus

A reference to the central Lateralus instance.

Source:
Type:

lateralusEvents :Object|undefined

A map of functions or string references to functions that will handle events dispatched to the central Lateralus instance.

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

parentComponent :Lateralus.Component|undefined

If this is a subcomponent of another Lateralus.Component, this property is a reference to the parent Lateralus.Component.

Default Value:
  • undefined
Source:
Type:

provide :Object|undefined

A map of functions that will handle Lateralus.mixins#collect calls. Each of the functions attached to this Object should return a value. These functions must be completely synchronous.

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

view :Lateralus.Component.View|undefined

If Lateralus.Component.View is defined, this is an instance of that constructor.

Default Value:
  • undefined
Source:
Type:

View :Lateralus.Component.View|undefined

The Lateralus.Component.View constructor to use, if any. If this Lateralus.Component is intended to render to the DOM, View should be defined on the prototype before instantiating:

const ExtendedComponent = Lateralus.Component.extend({
  name: 'extended',
  View: Lateralus.Component.View,
  template: '<div></div>'
});
Default Value:
  • undefined
Source:
Type:

Methods

dispose()

Remove this Lateralus.Component from memory. Also remove any nested components added by Lateralus.mixins#addComponent.

Source:

extend(protoProps)

Create a Lateralus.Component subclass.

Source:
Parameters:
Name Type Description
protoProps Object
Name Type Attributes Description
name string

The name of this component. It should have no whitespace.

View Lateralus.Component.View <optional>

The Lateralus.Component.View to render this component with.

Model Lateralus.Component.Model <optional>

The optional Lateralus.Component.Model to be provided to protoProps.View when it is instantiated. This does nothing if protoProps.View is not defined.

toJSON() → {Object}

Meant to be overridden by subclasses.

Source:
Returns:
Type:
Object

toString() → {string}

Source:
Returns:
Type:
string

The name of this Component. This is used internally by Lateralus.