# Yahoo! UI Library

### base 3.0.0b1

Yahoo! UI Library > base > Plugin.Host
Search:
Filters Show Private Show Protected Show Deprecated

## Class Plugin.Host

An augmentable class, which provides the augmented class with the ability to host plugins. It adds plug and unplug methods to the augmented class, which can be used to add or remove plugins from instances of the class.

Plugins can also be added through the constructor configuration object passed to the host class' constructor using the "plugins" property. Supported values for the "plugins" property are those defined by the plug method. For example the following code would add the AnimPlugin and IOPlugin to Overlay (the plugin host):

    var o = new Overlay({plugins: [ AnimPlugin, {fn:IOPlugin, cfg:{section:"header"}}]});

Plug.Host's protected _initPlugins and _destroyPlugins methods should be invoked by the host class at the appropriate point in the host's lifecyle. This is done by default for the Base class, so developers extending Base or Widget don't need to do anything to enable plugin support.

### Methods

#### _destroyPlugins

`private void _destroyPlugins ( )`
Unplugs and destroys all plugins on the host

Returns: `void`

#### _initPlugins

`private void _initPlugins ( config )`
Initializes static plugins registered on the host (using the Base.plug static method) and any plugins passed to the instance through the "plugins" configuration property.

Parameters:
  `config <Config>` The configuration object with property name/value pairs.

Returns: `void`

#### _plug

`private void _plug ( PluginClass , config )`
Private method used to instantiate and attach plugins to the host

Parameters:
  `PluginClass <Function>` The plugin class to instantiate
  `config <Object>` The configuration object for the plugin

Returns: `void`

#### _unplug

`private void _unplug ( plugin )`
Unplugs and destroys a plugin already instantiated with the host.

Parameters:
  `plugin <String | Function>` The namespace for the plugin, or a plugin class with the static NS property defined.

Returns: `void`

#### hasPlugin

`boolean hasPlugin ( ns )`
Determines if a plugin has plugged into this host.

Parameters:
  `ns <String>` The plugin's namespace

Returns: `boolean`
  returns true, if the plugin has been plugged into this host, false otherwise.

#### plug

`Base plug ( p , config )`
Adds a plugin to the host object. This will instantiate the plugin and attach it to the configured namespace on the host object.

Parameters:
  `p <Function | Object |Array>` Accepts the plugin class, or an object with a "fn" property specifying the plugin class and a "cfg" property specifying the configuration for the Plugin.

  Additionally an Array can also be passed in, with the above function or object values, allowing the user to add multiple plugins in a single call.

  `config <object>` (Optional) If the first argument is the plugin class, the second argument can be the configuration for the plugin.

Returns: `Base`
  A reference to the host object

Chainable: This method is chainable.

#### Plugin.Host.plug

`static void Plugin.Host.plug ( hostClass , plugin , config )`
Registers plugins to be instantiated at the class level (plugins which should be plugged into every instance of the class by default).

Parameters:
  `hostClass <Function>` The host class on which to register the plugins
  `plugin <Function | Array>` Either the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
  `config <Object>` (Optional) If plugin is the plugin class, the configuration for the plugin

Returns: `void`

#### Plugin.Host.unplug

`static void Plugin.Host.unplug ( hostClass , plugin )`
Unregisters any class level plugins which have been registered by the host class, or any other class in the hierarchy.

Parameters:
  `hostClass <Function>` The host class from which to unregister the plugins
  `plugin <Function | Array>` The plugin class, or an array of plugin classes

Returns: `void`

#### unplug

`Base unplug ( plugin )`
Removes a plugin from the host object. This will destroy the plugin instance and delete the namepsace from the host object.

Parameters:
  `plugin <String | Function>` The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided, all registered plugins are unplugged.

Returns: `Base`
  A reference to the host object

Chainable: This method is chainable.

Copyright © 2009 Yahoo! Inc. All rights reserved.