Class: ClassWithPlugins

ClassWithPlugins

A basic class that has can be extended using plugins

Constructor

new ClassWithPlugins(options)

Parameters:
Name Type Description
options Object the object the instance will be extended with
Properties:
Name Type Description
plugins Array.<String> Array of plugin names to use in this class
Source:

Members

plugins :Object

Object containing all plugins for all types, in plugins[type][name] hierarchy
Type:
  • Object
Source:

Methods

(static) hook(event, cb, context, instance)

This methods registers a hook callback on an instance of a ClassWithPlugins, it is called by the framework. This should never be called manually, if you want to register a hook, create a plugin and add it to the plugins of the class. If you want to fire a hook, use that instance (non static) hook method.
Parameters:
Name Type Description
event String The hook event to hook into
cb function Callback function, gets ran when this hook executes
context Object Context the callbacks should be called with
instance ClassWithPlugins The instance to hook plugins for
Source:

(static) registerPlugin(type, name, plugin) → {*}

Registers a plugin
Parameters:
Name Type Description
type String The type this is a plugin for, mapped onto a Class using the static get _type property on the class
name String Name of the plugin, this is how the plugin is identified in the system, the name is local to its type
plugin Object The plugin itself
Source:
Returns:
Type
*

(static) retrievePlugin(type, name) → {Object|undefined}

Retrieves a plugin
Parameters:
Name Type Description
type String The type this is a plugin for
name String Name of the plugin
Source:
Returns:
Type
Object | undefined

hasPlugin(plugin) → {Boolean}

Checks whether this instance has a certain plugin provided using the plugin parameter as a string.
Parameters:
Name Type Description
plugin String Plugin to look for
Source:
Returns:
Type
Boolean

hook(event, data) → {Promise}

Runs all hook listeners from all plugins active on the class, returns a promise so plugins can do async stuff and you can wait for the plugins to finish.
Parameters:
Name Type Description
event String Hook event to trigger
data Object Data to supply the hook callback with, in addition to the instance it's called from
Source:
Returns:
Type
Promise

on(event, cb)

Listens for an event trigger by the ClassWithPlugins#trigger method
Parameters:
Name Type Description
event String Event to listen to.
cb function Function that should be called when this event is triggered.
Source:

trigger(event, data)

Triggers an event with data that can be listed to using the ClassWithPlugins#on method
Parameters:
Name Type Description
event String Event to trigger.
data * Data the event should trigger with.
Source: