# mojo-application

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

Latest version **0.2.0** (published 2014-12-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install mojo-application
pnpm add mojo-application
yarn add mojo-application
bun add mojo-application
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-12-01 |
| First published | 2014-06-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | architectd |

## Links

- npm: https://www.npmjs.com/package/mojo-application
- Repository: https://github.com/mojo-js/mojo-application
- Issues: https://github.com/mojo-js/mojo-application/issues
- npm.io page: https://npm.io/package/mojo-application

## Dependencies (4)

- [mocha](https://npm.io/package/mocha.md) 1.20.x
- [nofactor](https://npm.io/package/nofactor.md) 0.0.x
- [expect.js](https://npm.io/package/expect.js.md) 0.3.x
- [bindable-object](https://npm.io/package/bindable-object.md) 0.0.x

## Recent versions

- 0.2.0 (latest) — 2014-12-01
- 0.1.0 — 2014-10-10
- 0.0.17 — 2014-08-06
- 0.0.16 — 2014-07-21
- 0.0.15 — 2014-07-21
- 0.0.14 — 2014-07-21
- 0.0.13 — 2014-07-17
- 0.0.12 — 2014-07-17
- 0.0.11 — 2014-07-02
- 0.0.10 — 2014-07-02
- 0.0.8 — 2014-06-05
- 0.0.7 — 2014-06-05
- 0.0.6 — 2014-06-05
- 0.0.5 — 2014-06-05
- 0.0.3 — 2014-06-05
- … 2 more at https://npm.io/package/mojo-application/versions

## README

[![Build Status](https://travis-ci.org/classdojo/mojo-application.svg?branch=master)](https://travis-ci.org/classdojo/mojo-application)

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

### Installation

```
npm install mojo-application
```

### Examples

- https://github.com/mojo-js/mojo-todomvc-example

### See Also

- [bindable.js](https://github.com/classdojo/bindable.js) - base class for application
- [mojo-views](https://github.com/mojo-js/mojo-views)
- [mojo-models](https://github.com/mojo-js/mojo-models)
- [mojo-router](https://github.com/mojo-js/mojo-router)
- [mojo-bootstrap](https://github.com/mojo-js/mojo-bootstrap)

## API

#### Application(options)

Extends [bindable.Object](https://github.com/classdojo/bindable.js)

- `options`
  - `nodeFactory` - the node factory to use when creating elements. This is automatically set when undefined.

```javascript
// 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"] });
```

#### application.nodeFactory

the [node factory](https://github.com/mojo-js/nofactor.js) to use when creating elements. This allows us to run on multiple platforms.

#### application.plugins

Array of plugins to use in the application.

```javascript
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();
```

#### application.use(plugin)

registers a plugin to the application.

```javascript
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
});
```

#### application.initialize(options)

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.

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

app.initialize({ element: document.body });
```

#### application.willInitialize(options)

called immediately before initializing your application.

#### application.didInitialize(options)

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

```javascript
var MyApplication = Application.extend({
  plugins: [
    require("mojo-views"),
    require("./views")
  ],
  didInitialize: function (options) {
    options.element.appendChild(this.views.create("main").render());
  }
});

var app = new MyApplication();
app.initialize({ element: document.body });
```

#### events

- `initialize` - emitted when the application is initialized

---
_Source: https://npm.io/package/mojo-application · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
