Unit

libflitter/Unit

exports:  class Unit

class Unit

The base class for the Flitter Unit. The Unit is the building block of the Flitter framework. Functionality in Flitter is broken into Units which are specified in order when Flitter is loaded. They contain a function which is used to initialize the unit. This function is passed the function of the next unit in the stack. Linked together as such, the collection of units forms the initialization stack of Flitter. Each unit establishes what's known as a context. A unit's context is just a point in its code when it has loaded all the functionality it provides to other units. From this point, it should call the next unit in the stack, giving it access to the functionality provided.

go(express app, function next)

returns:  undefined

This function initializes the unit. It should do everything required to establish the unit's context. Unlike the rest of the unit, when it is called it has access to all of the contexts above it. When it finishes starting up the unit, it should call the next function in the stack from within a scope that has access to all the resources this unit provides (its "context"). It is passed an instance of the underlying Express app so it can add or modify any functionality.

provides()

returns:  Object

Describes the resources provided by the unit. While optional, if the unit provides resources that other units may rely on, they should be specified here. This includes the service name of the unit, any directories it uses, and any templates it creates. These should be returned as an Object with particular formatting. Here's an example:

    provides() {
        return {
          	// The name of the service provided by the unit. Should be a String.
            name: "database",
          	
          	// List of fully-qualified directories provided by the unit.
          	// These directories are available by their assigned names.
            directories: {
                models: this.directory
            },
          	
          	// Templates provided by the unit.
            templates: {
              
              	// The key is the name of the template.
                model: {
                  	// This should be a function that takes (String name) and returns the text of the template.
                    template: require('libflitter/templates/model'),
                  	
                  	// Destination directory for the newly generated file.
                    directory: this.directory,
                  
                  	// Extension of the newly generated file.
                    extension: '.model.js'
                }
            }
        }
    }
No Comments
Back to top