Application


Extends bindable.Object
See Also views.Base, models.Base, templates

Your Mojo application entry point. This module ties everything together, and allows other parts of your application to communicate with each other. This should be your only singleton.

Installation

npm install mojo-application --save-exact

Playground Example

Here's an example of how to use just about every property / method in the Application class.

Application(properties)

Your main application entry point.

  • properties - properties to set on the application
    • nodeFactory - (optional) the node factory to use for creating views. Automatically set depending on the platform.

Application.main

The pre-defined application instance. This is the default application when the application parameter is omitted from the View(properties[, application]), and Model(properties[, application]) classes. Useful if you want a global reference to an application.

plugins

The plugins to register when initializing the application. See playground example for usage.

nodeFactory

The node factory to use for rendering the DOM

use(plugins...)

initialize()

method to initialize the application. This method calls willInitialize, and didInitialize. it also emits an initialize event.

override willInitialize()

called immediately before initializing the application

override didInitialize()

called immediately after initializing the application

Events

  • initialize - emitted when the application initializes

Extended API

Below are a list of extensions to mojo applications.

views

Property added by views extension when registering to the application.

views.register(classesOrClassName[, class])

Registers a view class that's accessible anywhere in the application. This is especially useful when registering reusable components you might want to use in something like paperclip components.

  • classesOrClassName - classes, or class name
  • class - the class if className is provided

var Application = require("mojo-application@0.1.x"),
views = require("mojo-views@0.2.x");

var app = new Application();
app.use(views);
app.views.register("someViewName", views.Base);
app.views.register({
  someViewName: views.Base,
  someOtherView: views.Base.extend({
    paper: require("./someTemplate.pc")
  })
});

views.create(className, properties)

Creates a new registered view.

  • className - the className of the view you want to create
  • properties - the properties to assign to the created class

views.decorator(decorator)

Registers a view plugin. This is useful if you want to extend the functionality for each view. Super useful for interpolation between different libraries. Here's an example of paperclip using the handlebars template engine:

models

Property added by models extension when registering to the application.

models.register(classesOrClassName[, class])

Registers a globally accessible model class. Similar to how views.register(...) works.

  • classesOrClassName - classes, or class name
  • class - the class if className is provided

models.create(className, properties)

Creates a new registered model. Similar to how models.register(...) works.

models.decorate(decorator)

Registers a model extension. Works exactly like view extensions.

animate(animatable)

Added property by the animator. The animator plugin leverages the browsers native requestAnimationFrame function to update the DOM. It's used in views, and templates.

router

Added property from mojo-router. See HTTP Router docs for usage.

paperclip

Added property. See paperclip template extension for more details.