mixins

Lateralus. mixins

Members

(static) components :Object.<Lateralus.Component>

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

Source:
Type:

(static) 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 () {
    // ...
  }
});
Default Value:
  • undefined
Source:
Type:
  • Object | undefined

(static) 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) {
      // ...
    }
  }
});
Default Value:
  • undefined
Source:
Type:
  • Object | undefined

(static) 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]
Source:
Type:
  • Object | undefined

Methods

addComponent(Component, viewOptionsopt, optionsopt) → {Lateralus.Component}

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

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

const app = new App(document.getElementById('app'));
const component = app.addComponent(Lateralus.Component);
const subcomponent = component.addComponent(Lateralus.Component);
Source:
Parameters:
Name Type Attributes Description
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.

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.

Returns:
Type:
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.

Source:
Parameters:
Name Type Description
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, …argsopt) → {Array.<any>}

Execute any Lateralus.mixins.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.

Source:
Parameters:
Name Type Attributes Description
key string

The name of the Lateralus.mixins.provide methods to run.

args any <optional>
<repeatable>

Any parameters to pass along to Lateralus.mixins.provide methods.

Returns:
Type:
Array.<any>

collectOne(key, …argsopt) → {any}

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

Source:
Parameters:
Name Type Attributes Description
key string

The name of the Lateralus.mixins.provide methods to run.

args any <optional>
<repeatable>

Any parameters to pass along to Lateralus.mixins.provide methods.

Returns:
Type:
any

delegateLateralusEvents()

Bind Lateralus.mixins.lateralusEvents, if it is defined.

Source:

emit(eventName, …argsopt)

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.

Source:
Parameters:
Name Type Attributes Description
eventName string

The name of the event.

args any <optional>
<repeatable>

Any arguments to pass along to the listeners.

initCollection(Collection, modelsopt, optionsopt) → {Lateralus.Component.Collection}

Source:
Parameters:
Name Type Attributes Description
Collection Lateralus.Component.Collection

A constructor, not an instance.

models Array.<Lateralus.Model> <optional>
options Object <optional>
Returns:
Type:
Lateralus.Component.Collection

Am instance of the provided Collection constructor.

initModel(Model, attributesopt, optionsopt) → {Lateralus.Component.Model}

Source:
Parameters:
Name Type Attributes Description
Model Lateralus.Component.Model

A constructor, not an instance.

attributes Object <optional>
options Object <optional>
Returns:
Type:
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.

Source:
Parameters:
Name Type Description
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.

Source:
Parameters:
Name Type Description
mixin Object

The object to mix in to this one.