Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hable

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hable

A simpler tapable alternative, which can be used to create hooks for plugins

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
108K
decreased by-13.72%
Maintainers
1
Weekly downloads
 
Created
Source

Hable

npm

A simpler tapable alternative, which can be used to create hooks for plugins.

Install

>_ yarn add hable
>_ npm install hable

Usage

Extend your base class from Hable:

import Hookable from 'hable'

export default class MyLib extends Hookable {
  constructor() {
    // Call to parent to initialize
    super()
  }

  async someFunction() {
    // Call and wait for `foo` hooks (if any) sequential
    await this.callHook('foo')

    // Call and wait for `bar` hooks (if any) in paraller
    await this.callHookAsync('bar')
  }
}

Inside plugins, register for any hook:

const lib = new MyLib()

// Register a handler for `foo`
lib.hook('foo', async () => { /* ... */ })

// Register multiply handlers at once
lib.hookObj({
  foo: async () => { /* ... */ },
  bar: [ /* can be also an array */ ]
})

API

Class functions

  • async callHook(name, ...args): Used by class itself to sequentially call handlers of a specific hook.
  • async callHookAsync(name, ...args): Same as callHook but calls handlers in parallel.
  • hook(name, fn): Used by plugins to register a handler for an specific hook. fn can be a single function or an array.
  • hookObj(hooksObj): Register many hook using an object.

Class attributes

  • $hooks: An object which maps from each hook name to it's handlers.

Credits

Extracted from Nuxt.js hooks system. Original author: Sébastien Chopin.

License

MIT

Keywords

FAQs

Package last updated on 26 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc