API Docs for: 0.9.3
Show:

Lateralus Class

You should not need to call the Lateralus constructor directly, use beget instead. To create a new Lateralus app:

var App = Lateralus.beget(function () {
  // Don't forget to call the Lateralus constructor!
  Lateralus.apply(this, arguments);
});

var app = new App(document.getElementById('app'));

Constructor

Lateralus

(
  • el
)

Parameters:

  • el Element

    The DOM element that contains the entire Lateralus app.

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.

beget

(
  • child
  • [config]
)
Function static

Create a Lateralus application instance.

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

Parameters:

Returns:

Function:

The created Lateralus subclass.

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.

dispose

()

Remove this Lateralus app from memory.

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.

error

(
  • Any
)

Cross-browser friendly wrapper for console.error.

Parameters:

  • Any ...any

    parameters to pass along to console.error.

inherit

(
  • child
  • parent
)
Function static

Set up the prototype chain between two objects.

Parameters:

  • child Function
  • parent Function

Returns:

Function:

A reference to the passed-in child parameter.

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.

initRouter

(
  • Router
  • [options]
)
Lateralus.Router

Parameters:

Returns:

Lateralus.Router:

An instance of the provided Router 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.

log

(
  • Any
)

Cross-browser friendly wrapper for console.log.

Parameters:

  • Any ...any

    parameters to pass along to console.log.

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.

shareWith

(
  • receiver
  • providerName
)

Relay provided handlers to another Lateralus instance. This is the provide analog to amplify.

Parameters:

toString

() String final

Do not override this method, it is used internally.

Returns:

String:

This is "lateralus".

warn

(
  • Any
)

Cross-browser friendly wrapper for console.warn.

Parameters:

  • Any ...any

    parameters to pass along to console.warn.

Properties

$el

JQuery

The jQuery Object that contains el.

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.

el

HTMLElement

The DOM node that contains this Lateralus instance.

globalPartials

Object(String)

An optional map of template partials to be passed to the Mustache.render call for all Views belonging to this Lateralus app.

globalRenderData

Object(String)

An optional map of template render data to be passed to the Mustache.render call for all Views belonging to this Lateralus app.

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

model

Lateralus.Model

Maintains the state of the central Lateralus instance.

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.