Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1018 Bytes

3.plugins.md

File metadata and controls

44 lines (33 loc) · 1018 Bytes

Plugins registration

A plugin groups multiple hooks in a same place. As such, it must exports at least one hook inside the hooks property.

Structure

A plugin is an object literal with the properties:

  • hooks ({name: hook})
    List of hooks identified by hook names.
  • name (string)
    Name of the plugin.
  • require ([string])
    Names of the required plugins.

Alternatively, a plugin can be defined as a function which returns the same plugin object and receive the args property from the Plug-And-Play function.

Registration

Plug and Play can be initialized with a list of plugins through the plugins options:

import { plugandplay } from 'plug-and-play'
plugandplay({
  plugins: [{
    hooks: {
      'my:hook': () => { console.log('"my:hook" is called') }
    }
  }]
})

Or later on with the register function:

import { plugandplay } from 'plug-and-play'
plugandplay()
.register({
  hooks: {
    'my:hook': () => { console.log('"my:hook" is called') }
  }
})