mojo-application

Main entry point to mojo-based applications. Not very complex - just some glue to help bootstrap your application.

Main entry point to mojo-based applications. Not very complex - just some glue to help bootstrap your application.

npm install mojo-application
  • https://github.com/mojo-js/mojo-todomvc-example

Extends bindable.Object

  • options
    • nodeFactory - the node factory to use when creating elements. This is automatically set when undefined.
// node factory 
var nofactor = require("nofactor"),
Application  = require("mojo-application");
 
// use the DOM node factory - meant for the browser 
var app = new Application({ nodeFactory: nofactor.dom });
 
// use the string node factory - meant for node.js 
var app = new Application({ nodeFactory: nofactor.string });
 
// use the default node factory - automatically identified based on platform. 
var app = new Application({ nodeFactory: nofactor["default"] });

the node factory to use when creating elements. This allows us to run on multiple platforms.

Array of plugins to use in the application.

var Application = require("mojo-application");
 
var MyApplication = Application.extend({
  plugins: [
    require("mojo-router"),
    require("mojo-models")
    require("mojo-views"),
    require("mojo-paperclip"),
    require("./routes"),
    require("./models"),
    require("./views")
  ]
});
 
var app = new MyApplication();

registers a plugin to the application.

var Application = require("mojo-application");
var app = new Application();
 
// load in a third-party plugin 
app.use(require("mojo-views"));
 
// or pass in a function 
app.use(function (app) {
  // do stuff with the application 
});

Initializes the application. This is where you should pass-in your app config, including what element to attach to.

Note that an exception will be thrown if initialize is called more than once.

var app = new MyApplication();
app.once("initialize", function (options) {
  console.log(options.element);
});
 
app.initialize({ element: document.body });

called immediately before initializing your application.

called immediately after initializing your application. Good place to start your application.

var MyApplication = Application.extend({
  plugins: [
    require("mojo-views"),
    require("./views")
  ],
  didInitializefunction (options) {
    options.element.appendChild(this.views.create("main").render());
  }
});
 
var app = new MyApplication();
app.initialize({ element: document.body });
  • initialize - emitted when the application is initialized