FlitterApp

libflitter/app/FlitterApp~ FlitterApp

This class is the core of the Flitter initialization system. It contains the underlying Express app. The up method links Flitter units together to form the initialization stack, which starts the application server.

Constructor

new FlitterApp(unit_classes)

Source:

Instantiate the class. Create a new Express app, as well as a global context and bind the essentials to it. Creates the global "_flitter" variable which has access to the global context.

Parameters:
Name Type Description
unit_classes module:libflitter/app/FlitterApp~FlitterApp~UnitList

collection of units to be loaded by the app

Members

d :Object

Source:

The Flitter daemon. This is a collection of module:libflitter/Context~Context instances populated by each unit. The collection is a set of key-value pairs such that each key is the name of a unit, and the value is an Object obtained by calling the module:libflitter/Context~Context#serialize method on each unit's context.

Type:
  • Object

directories :Object

Source:

Collection of directories provided by the units in the application. This is populated as the application is started, and the directories are in key-value pairs such that the key is the agnostic name of the directory which can be used to access it programmatically and the value is the fully-qualified path to the directory.

Type:
  • Object

express :Express

Source:

The underlying Express application.

Type:
  • Express

global :module:libflitter/Context~Context

Source:

The global context. This can be accessed by all units and is used to expose functionality to the app-space code in the controllers/etc. It is usually mapped to the global "_flitter" variable.

Type:

services :Array.<String>

Source:

String list of services present in the application. This is populated as the application is started.

Type:
  • Array.<String>

units :module:libflitter/app/FlitterApp~FlitterApp~UnitList

Source:

The units to be loaded by the application.

Type:
  • module:libflitter/app/FlitterApp~FlitterApp~UnitList

Methods

(async) down() → {Promise.<number>}

Source:

Clean up and prepare to exit. Check each Unit in module:libflitter/app/FlitterApp~FlitterApp#units for a "cleanup" method. If it exists, call it. If no errors occur, end the process with exit code 0. If an error occurs during any cleanup process, print the error and when all units have finished, exit with code 1. In most cases, this is all that is needed to end the Flitter process. You shouldn't really need to call module:libflitter/app/FlitterApp~FlitterApp#stop.

Returns:
Type
Promise.<number>

has(service_name) → {boolean}

Source:

Helper function that checks if a unit with the specified name has been loaded. This is usually bound to the module:libflitter/app/FlitterApp~FlitterApp#global context.

Parameters:
Name Type Description
service_name string

the name of the unit ti check

Returns:
Type
boolean

(async) stop() → {Promise.<void>}

Source:

End the process. Calls this.down() and passes the status code to process.exit(). This is not the recommended way of exiting Flitter. module:libflitter/app/FlitterApp~FlitterApp#down is preferred.

Returns:
Type
Promise.<void>

(async) up() → {Promise.<void>}

Source:

Launch the application. For each unit in module:libflitter/app/FlitterApp~FlitterApp#units, call the module:libflitter/Unit~Unit#go method. The unit's context is then stored in the daemon (module:libflitter/app/FlitterApp~FlitterApp#d. Once all the units have been loaded, re-iterate over them and call the module:libflitter/Unit~Unit#cleanup method if it exists.

Returns:
Type
Promise.<void>