ControllerUnit

libflitter/controller/ControllerUnit~ ControllerUnit

This unit loads controllers from the specified directory and makes instances of them available in a global function. This is used when defining route handlers.

Constructor

new ControllerUnit(controller_directoryopt)

Source:

Instantiates the unit. Resolves the path to the directory with the controller definition files.

Parameters:
Name Type Attributes Default Description
controller_directory string <optional>
'./app/controllers'

The path to the directory with the controller definition files

Extends

Methods

(async) cleanup(app) → {Promise.<void>}

Source:
Inherited From:

Cleans up the unit's resources before Flitter closes.

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

the Flitter app

Returns:
Type
Promise.<void>

directories() → {Object}

Source:
Overrides:

Get the directories provided by the unit. Currently "controllers" bound to module:libflitter/controller/ControllerUnit~ControllerUnit#directory

Returns:
Type
Object

getcontroller(name) → {Object}

Source:

Helper function that returns an object with the self-bound methods from the controller with the specified name.

Parameters:
Name Type Description
name string

the Flitter canonical name of the controller to retrieve

Returns:
  • collection of self-bound methods from the controller
Type
Object

(async) go(app, context) → {Promise.<void>}

Source:
Overrides:

Loads the unit. Loads the controller definition files from module:libflitter/controller/ControllerUnit~ControllerUnit#directory and binds the controllers and helper functions to the appropriate contexts.

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

the Flitter app

context module:libflitter/Context~Context

the Unit's context

Returns:
Type
Promise.<void>

name() → {string}

Source:
Overrides:

Get the name of the unit.

Returns:

"controllers"

Type
string

templates() → {Object}

Source:

Get the templates provided by the unit. "controller" provided by module:libflitter/templates/controller.

Returns:
Type
Object