Home Reference Source Test Repository
import PluginManager from 'plugged-in/src/PluginManager.js'
public class | source

PluginManager

This class is usually the main part of the application.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Create a new instance.

Member Summary

Public Members
public get

Get the current application context.

public get

Determine if running in debug mode.

public get

log: Object: *

Get logger.

Method Summary

Public Methods
public

addHandler(eventName: String, handler: Function): Object

Adds a new handler to the event list.

public

Add local plugins.

public

dispatch(eventName: String, context: Object): Object

Helper method to dispatch events.

public

getMaxHandlers(): Integer

Get max event handlers.

public

handlers(eventName: String): Function[]

Get list of handlers for an event.

public

hasHandler(event: String, handler: Function | String): Boolean

Determines if a handler exists for an event.

public

Determines if an event has any handlers.

public

init(plugin: Object, npm: Object): PluginManager

Initialize the application.

public

Deletes all handlers for an event.

public

removeHandler(eventName: String, handler: Function | String): PluginManager

Removes a handler for an event that matches the handler function name.

public

setMaxHandlers(count: Integer): Object

Set max number of event handlers.

Public Constructors

public constructor(options: Object) source

Create a new instance.

Params:

NameTypeAttributeDescription
options Object
  • optional

options object

options.debug Boolean
  • optional

debug flag

options.context String
  • optional

context name

options.configFile String
  • optional

set the config file path

options.override Boolean
  • optional
  • default: true

whether to override matching functions

Public Members

public get context: String: * source

Get the current application context.

Return:

String

the context name

public get debug: Boolean: * source

Determine if running in debug mode.

Return:

Boolean

true or false

public get log: Object: * source

Get logger.

Return:

Object

the logger instance

Public Methods

public addHandler(eventName: String, handler: Function): Object source

Adds a new handler to the event list.

Params:

NameTypeAttributeDescription
eventName String

the event name

handler Function

the callback function

Return:

Object

this instance

public addPlugins(plugins: Object[]): PluginManager source

Add local plugins.

Params:

NameTypeAttributeDescription
plugins Object[]

list of plugins

plugins.provides Object

the provides object

Return:

PluginManager

this instance

public dispatch(eventName: String, context: Object): Object source

Helper method to dispatch events.

Params:

NameTypeAttributeDescription
eventName String

the event name

context Object
  • optional

optional event context object

Return:

Object

the modified data object

public getMaxHandlers(): Integer source

Get max event handlers.

Return:

Integer

max number of handlers

public handlers(eventName: String): Function[] source

Get list of handlers for an event.

Params:

NameTypeAttributeDescription
eventName String

the event name

Return:

Function[]

list of handlers

public hasHandler(event: String, handler: Function | String): Boolean source

Determines if a handler exists for an event.

Params:

NameTypeAttributeDescription
event String

the event name

handler Function | String

the function or its name

Return:

Boolean

true if exists, otherwise false

public hasHandlers(event: String): Boolean source

Determines if an event has any handlers.

Params:

NameTypeAttributeDescription
event String

the event name

Return:

Boolean

true or false

public init(plugin: Object, npm: Object): PluginManager source

Initialize the application.

Generates config file if it does not exist and loads plugins.

Params:

NameTypeAttributeDescription
plugin Object

local event handlers

npm Object
  • optional

optional Npm instance

Return:

PluginManager

this plugin

public removeAllHandlers(eventName: String): Object source

Deletes all handlers for an event.

Params:

NameTypeAttributeDescription
eventName String

the event name to removes

Return:

Object

this instance

public removeHandler(eventName: String, handler: Function | String): PluginManager source

Removes a handler for an event that matches the handler function name.

Params:

NameTypeAttributeDescription
eventName String

the event name

handler Function | String

the function or its name

Return:

PluginManager

this instance

public setMaxHandlers(count: Integer): Object source

Set max number of event handlers.

Params:

NameTypeAttributeDescription
count Integer

max number

Return:

Object

this instance