Application(opts)

Extends Dispatcher

src/Application.js

The Core Application class.

Parameters

  • Object opts :

    the configuration options

Examples

import {Application} from '@nxus/core'
let app = new Application(options)
app.start()
export default app

Instance members

#boot

Boots the application, cycling through the internal boot stages.

Note: Should rarely be called directly. Instead use #start

boot

src/Application.js

Boots the application, cycling through the internal boot stages.

Note: Should rarely be called directly. Instead use #start

Returns

Promise
#get(name)

Returns an internal Module object for the given name.

get(name)

src/Application.js

Returns an internal Module object for the given name.

Parameters

  • string name :

    The name of the module to return

Returns

Module
#init

Initializes the application by loading plugins, then booting the application.

Note: this should rarely be called directly. Instead use #start

init

src/Application.js

Initializes the application by loading plugins, then booting the application.

Note: this should rarely be called directly. Instead use #start

Returns

Promise
#restart

Restarts the Nxus application.

restart

src/Application.js

Restarts the Nxus application.

Returns

Promise
#start

Starts the Nxus application.

start

src/Application.js

Starts the Nxus application.

Returns

Promise
#stop

Stops the currently running application, removing all event listeners.

stop

src/Application.js

Stops the currently running application, removing all event listeners.

Returns

Promise

PluginManager

src/PluginManager.js

The PluginManager handles all of the module loading. Load order is as follows:

  1. Packages in node_modules that match the passed namespace config option, and packages in the @nxus namespace.
  2. Folders in the /modules directory.
  3. Filepaths passed in the modules config option

Instance members

#accumulatePackage(packages, directory)

Creates the internal representation of a package

accumulatePackage(packages, directory)

src/PluginManager.js

Creates the internal representation of a package

Parameters

  • array packages :

    the list of active packages being loaded by Nxus

  • string directory :

    the directory of the new package to load

Returns

object :

the package, as returned by require

#arrayify(el)

Helper method to ensure a passed variable is an array. Wraps the value in an array if it isn't already.

arrayify(el)

src/PluginManager.js

Helper method to ensure a passed variable is an array. Wraps the value in an array if it isn't already.

Parameters

  • anything el :

    the item to ensure is an array

Returns

Array :

either a new empty array, or el as is if its an array, or el wrapped in an array.

#getDeps(pkg)

Loads the dependencies for a particular package, as defined by the 'dependencies' object in the package.json file.

getDeps(pkg)

src/PluginManager.js

Loads the dependencies for a particular package, as defined by the 'dependencies' object in the package.json file.

Parameters

  • object pkg :

    the package object generated by accumulatePackage()

Returns

array :

an array of the package's dependencies, as filepaths or node_module names

#getPluginPackageJson(path)

Loads the package.json file for the specified packages.

getPluginPackageJson(path)

src/PluginManager.js

Loads the package.json file for the specified packages.

Parameters

  • string path :

    the root package folder path

Returns

object :

the parsed json object in package.json

#loadCustomPlugins(options, packages)

Loads custom plugins in the /modules directory

loadCustomPlugins(options, packages)

src/PluginManager.js

Loads custom plugins in the /modules directory

Parameters

  • object options :

    configuration options

  • packages packages :

    the array of packages currently loaded by Nxus

#loadPackage(name, directory, packages)

Loads a package

loadPackage(name, directory, packages)

src/PluginManager.js

Loads a package

Parameters

  • string name :

    The name of the package

  • string directory :

    A path to the package

  • array packages :

    An array of the currently loaded packages

#loadPackages(options, packages)

Loads all Nxus pacakges for an application

loadPackages(options, packages)

src/PluginManager.js

Loads all Nxus pacakges for an application

Parameters

  • object options :

    options to use to load the packages

  • packages packages :

    the array of packages currently loaded by Nxus

#loadPassedPlugins(options, packages)

Loads manually passed in packages by path

loadPassedPlugins(options, packages)

src/PluginManager.js

Loads manually passed in packages by path

Parameters

  • object options :

    configuration options

  • packages packages :

    the array of packages currently loaded by Nxus

Dispatcher

Extends EventEmitter

src/Dispatcher.js

The core Dispatcher class, which implements promisified

Examples

import { Dispatcher } from '@nxus/core'
class MyClass extends Dispatcher {
  ...
}

Instance members

#after(event, listener)

Bind to after an event. Receives the event handlers results, should return modified results or nothing.

after(event, listener)

src/Dispatcher.js

Bind to after an event. Receives the event handlers results, should return modified results or nothing.

Parameters

  • string event :

    The name of the event to bind to

  • callable listener :

    The after handler for the event

#before(event, listener)

Bind to before an event. Receives the event arguments, should return modified arguments or nothing.

before(event, listener)

src/Dispatcher.js

Bind to before an event. Receives the event arguments, should return modified arguments or nothing.

Parameters

  • string event :

    The name of the event to bind to

  • callable listener :

    The before handler for the event

#emit(event, args)

Emits an event, calling all registered handlers.

emit(event, args)

src/Dispatcher.js

Emits an event, calling all registered handlers.

Parameters

  • string event :

    The name of the event to emit.

  • ... Any args :

    Arguments to the event handlers

Returns

Promise :

Returns a promise that resolves when all handlers have completed, with any returned results as an array.

#once(event, [listener])

Bind to an event once

once(event, [listener])

src/Dispatcher.js

Bind to an event once

Parameters

  • string event :

    The name of the event to bind to

  • callable = listener :

    The handler for the event

Returns

Promise :

Returns a promise that resolves when the event fires

#onceAfter(event, listener)

Bind once to after an event. Receives the event handlers results, should return modified results or nothing.

onceAfter(event, listener)

src/Dispatcher.js

Bind once to after an event. Receives the event handlers results, should return modified results or nothing.

Parameters

  • string event :

    The name of the event to bind to

  • callable listener :

    The after handler for the event

Returns

Promise :

Returns a promise that resolves when the event fires

#onceBefore(event, listener)

Bind once to before an event. Receives the event arguments, should return modified arguments or nothing.

onceBefore(event, listener)

src/Dispatcher.js

Bind once to before an event. Receives the event arguments, should return modified arguments or nothing.

Parameters

  • string event :

    The name of the event to bind to

  • callable listener :

    The before handler for the event

Returns

Promise :

Returns a promise that resolves when the event fires

ConfigurationManager

src/ConfigurationManager.js

ConfigurationManager loads the internal app.config hash using the following order (each overwrites any values of the previous):

  1. Opts loaded into the application object.
  2. Opts in the config hash of the project package.json file
  3. Any environment variables

Instance members

#getConfig

Returns the final config option using the loading order described above.

getConfig

src/ConfigurationManager.js

Returns the final config option using the loading order described above.

Returns

object :

the final composed configuration object.

#getEnvironmentVariables

Extracts the currently avaiable environment variables

getEnvironmentVariables

src/ConfigurationManager.js

Extracts the currently avaiable environment variables

Returns

object :

A hash of the current environment variables

#getNodeEnv

Returns the current NODE_ENV

getNodeEnv

src/ConfigurationManager.js

Returns the current NODE_ENV

Returns

string :

the current NODE_ENV

#getPackageJSONConfig

Gets the local package.json file and tries to find an internal config key

getPackageJSONConfig

src/ConfigurationManager.js

Gets the local package.json file and tries to find an internal config key

Returns

object :

the intenral config object or an empty object if it isn't defined.

Module

Extends Dispatcher

src/Module.js

The core Module class. This provides a messaging proxy layer between modules and calling code. The main advantage of this proxy class is that missing modules won't cause exceptions in the code.

Modules are accessed through the Application.get() method

Examples

let router = app.get('router')

Instance members

#gather(name, handler)

Receive arguments provided to a delayed gather() call.

gather(name, handler)

src/Module.js

Receive arguments provided to a delayed gather() call.

Parameters

  • string name :

    The name of the gather event

  • callable handler :

    The handler for each provided value

#provide(name, args)

Provide arguments to a delayed gather() call.

provide(name, args)

src/Module.js

Provide arguments to a delayed gather() call.

Parameters

  • string name :

    The name of the gather event

  • ... Any args :

    Arguments to provide to the gather event

Returns

Promise :

Resolves when the event is eventually handled

#provideAfter(name, args)

Provide arguments to a delayed gather() call, after the main provide() calls.

provideAfter(name, args)

src/Module.js

Provide arguments to a delayed gather() call, after the main provide() calls.

Parameters

  • string name :

    The name of the gather event

  • ... Any args :

    Arguments to provide to the gather event

Returns

Promise :

Resolves when the event is eventually handled

#provideBefore(name, args)

Provide arguments to a delayed gather() call, but do it before the other provide() calls.

provideBefore(name, args)

src/Module.js

Provide arguments to a delayed gather() call, but do it before the other provide() calls.

Parameters

  • string name :

    The name of the gather event

  • ... Any args :

    Arguments to provide to the gather event

Returns

Promise :

Resolves when the event is eventually handled

#request(name, args)

Request the result of processing a named event

request(name, args)

src/Module.js

Request the result of processing a named event

Parameters

  • string name :

    The name of the request event

  • ... Any args :

    Arguments to provide to the responder

Returns

Promise :

Resolves to the result of the event's handler

#respond(name, handler)

Respond to a named event

respond(name, handler)

src/Module.js

Respond to a named event

Parameters

  • string name :

    The name of the request event

  • callable handler :

    The handler for the request

#use(instance)

Let another instance use this module's events to reduce boilerplate calls

use(instance)

src/Module.js

Let another instance use this module's events to reduce boilerplate calls

Parameters

  • instance :

Watcher

src/Watcher.js

The Watcher class monitors the project directory and restarts the application whenever there is a change in files detected. Useful for development.