API Docs for: 0.9.3
Show:

Lateralus.mixins Class

These method are mixed into Lateralus, Lateralus.Component, and Lateralus.Component.View.

Methods

addComponent

(
  • Component
  • [viewOptions]
  • [options]
)
Lateralus.Component

Add a subcomponent to a Lateralus or Lateralus.Component instance.

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

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

Parameters:

  • Component Lateralus.Component

    A constructor, not an instance.

  • [viewOptions] Object optional

    The options object to be passed along to the Component parameter's Lateralus.Component.View instance.

  • [options] Object optional

    Gets passed to the new Lateralus.Component instance.

    • [modelAttributes] Object optional

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

    • [modelOptions] Object optional

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

Returns:

Lateralus.Component:

The component that was added.

amplify

(
  • emitter
  • eventName
)

Listen to an event-emitting Object and amplify one of its events across the Lateralus application. Useful for making plain Backbone Objects (i.e., non-Lateralus Objects) communicate important information in a broader way.

Parameters:

  • emitter Backbone.Events

    The object that triggers events that should be amplified globally across the app.

  • eventName String

    The event to amplify globally across the app.

collect

(
  • key
  • [args]
)
Array(any)

Execute any provide handlers that have been set up in the app and return an array of the returned values.

Values that are undefined are excluded from the returned Array.

Parameters:

  • key String

    The name of the provide methods to run.

  • [args] ...any optional

    Any parameters to pass along to provide methods.

Returns:

Array(any):

collectOne

(
  • key
  • [args]
)
Any

Execute any provide handlers that have been set up in the app and return the first value.

Parameters:

  • key String

    The name of the provide methods to run.

  • [args] ...any optional

    Any parameters to pass along to provide methods.

Returns:

Any:

delegateLateralusEvents

() chainable

Bind lateralusEvents, if it is defined.

emit

(
  • eventName
  • [args]
)

Components should never communicate directly with one another in order to maintain a loosely-coupled architecture. Instead, they should just broadcast general messages with the Backbone.Events API. emit facilitates this loose coupling by firing an event that bubbles throughout the app, depending on what calls it:

This method has the same method signature as Backbone.Events.trigger.

Parameters:

  • eventName String

    The name of the event.

  • [args] ...any optional

    Any arguments to pass along to the listeners.

initCollection

(
  • Collection
  • [models]
  • [options]
)
Lateralus.Component.Collection

Parameters:

  • Collection Lateralus.Component.Collection

    A constructor, not an instance.

  • [models] Array.(Lateralus.Model) optional
  • [options] Object optional

Returns:

Lateralus.Component.Collection:

Am instance of the provided Collection constructor.

initModel

(
  • Model
  • [attributes]
  • [options]
)
Lateralus.Component.Model

Parameters:

Returns:

Lateralus.Component.Model:

An instance of the provided Model constructor.

listenFor

(
  • event
  • callback
)

Listen for an event that is triggered on the central Lateralus instance and bind a function handler.

Parameters:

  • event String

    The name of the event to listen for.

  • callback Function

    The function handler to bind.

mixin

(
  • mixin
)

Merge the properties of another object into this object. If the mixin configuration object has a method called initialize, it is called in the context of the object calling this function.

Parameters:

  • mixin Object

    The object to mix in to this one.

Properties

componentCounters

Object(number) private

An internal counter registry of the subcomponents belonging to this object.

components

Object(Lateralus.Component)

The subcomponents belonging to this object. Do not modify this property directly, it is managed by Lateralus.

lateralusEvents

Object | Undefined

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

var ExtendedComponent = Lateralus.Component.extend({
  name: 'extended'

  ,lateralusEvents: {
    anotherComponentChanged: 'onAnotherComponentChanged'

    ,anotherComponentDestroyed: function () {
      // ...
    }
  }

  ,onAnotherComponentChanged: function () {
    // ...
  }
});

Default: undefined

modelEvents

Object | Undefined

A map of functions or string references to functions that will handle events emitted by this.model.

var ExtendedComponent = Lateralus.View.extend({
  modelEvents: {
    changed:someProperty: function (model, someProperty) {
      // ...
    }
  }
});

Default: undefined

provide

Object | Undefined

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

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

_.extend(App.prototype, {
  provide: {
    demoData: function () {
      return 1;
    }
  }
});

var app = new App();
var ComponentSubclass = Lateralus.Component.extend({
  name: 'provider'
  ,provide: {
    demoData: function () {
      return 2;
    }
  }
});

app.addComponent(ComponentSubclass);
console.log(app.collect('demoData')); // [1, 2]

PROVIDE_PREFIX

String private final

Event namespace for provide handlers.