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 - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

.babelrc

15

CHANGELOG.md

@@ -5,2 +5,17 @@ # Change Log

<a name="0.0.7"></a>
## [0.0.7](https://github.com/pi0/hable/compare/v0.0.6...v0.0.7) (2018-01-28)
### Bug Fixes
* hook with array or falsy key ([7e90de1](https://github.com/pi0/hable/commit/7e90de1))
### Performance Improvements
* use for in for hookObj ([3c8e2e7](https://github.com/pi0/hable/commit/3c8e2e7))
<a name="0.0.6"></a>

@@ -7,0 +22,0 @@ ## [0.0.6](https://github.com/pi0/hable/compare/v0.0.5...v0.0.6) (2018-01-26)

6

dist/hable.cjs.js

@@ -47,6 +47,2 @@ 'use strict';

Hookable.prototype.hook = function hook (name, fn) {
if (!name || typeof fn !== 'function') {
return;
}
if (!this.$hooks[name]) {

@@ -66,3 +62,3 @@ this.$hooks[name] = [];

for (var name of Object.keys(hooksObj)) {
for (var name in hooksObj) {
this$1.hook(name, hooksObj[name]);

@@ -69,0 +65,0 @@ }

@@ -45,6 +45,2 @@ function serial(tasks, fn) {

Hookable.prototype.hook = function hook (name, fn) {
if (!name || typeof fn !== 'function') {
return;
}
if (!this.$hooks[name]) {

@@ -64,3 +60,3 @@ this.$hooks[name] = [];

for (var name of Object.keys(hooksObj)) {
for (var name in hooksObj) {
this$1.hook(name, hooksObj[name]);

@@ -67,0 +63,0 @@ }

{
"name": "hable",
"version": "0.0.6",
"version": "0.0.7",
"description": "A simpler tapable alternative, which can be used to create hooks for plugins",
"main": "dist/hable.cjs.js",
"module": "dist/hable.es.js",
"jsnext:main": "dist/hable.es.js",
"scripts": {
"build": "bili --format es,cjs --inline",
"dev": "npm run build --watch",
"release": "npm run build && standard-version",
"release2": "git push --follow-tags && npm publish"
},
"author": "Pooya Parsa <pooya@pi0.ir>",
"license": "MIT",
"homepage": "https://github.com/pi0/hable#readme",
"repository": {

@@ -18,2 +12,5 @@ "type": "git",

},
"bugs": {
"url": "https://github.com/pi0/hable/issues"
},
"keywords": [

@@ -26,8 +23,13 @@ "tapable",

],
"author": "Pooya Parsa <pooya@pi0.ir>",
"license": "MIT",
"bugs": {
"url": "https://github.com/pi0/hable/issues"
"main": "dist/hable.cjs.js",
"module": "dist/hable.es.js",
"jsnext:main": "dist/hable.es.js",
"scripts": {
"build": "bili --format es,cjs,cjs-min --inline",
"test": "jest",
"test-ci": "NODE_ENV=test jest --coverage && codecov",
"dev": "npm run build --watch",
"release": "npm run build && standard-version",
"release2": "git push --follow-tags && npm publish"
},
"homepage": "https://github.com/pi0/hable#readme",
"dependencies": {

@@ -37,5 +39,10 @@ "items-promise": "^1.0.0"

"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^22.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"bili": "^2.2.3",
"codecov": "^3.0.0",
"jest": "^22.1.4",
"standard-version": "^4.3.0"
}
}
# Hable
[![CircleCI](https://img.shields.io/circleci/project/github/pi0/hable.svg?style=flat-square)](https://circleci.com/gh/pi0/hable)
[![Codecov](https://img.shields.io/codecov/c/github/pi0/hable.svg?style=flat-square)](https://codecov.io/gh/pi0/hable)
[![npm](https://img.shields.io/npm/v/hable.svg?style=flat-square)](https://www.npmjs.com/package/hable)
[![npm](https://img.shields.io/npm/dt/hable.svg?style=flat-square)](https://www.npmjs.com/package/hable)
[![size](http://img.badgesize.io/https://unpkg.com/hable?compression=gzip&style=flat-square)](https://unpkg.com/hable)

@@ -9,7 +13,14 @@ > A simpler tapable alternative, which can be used to create hooks for plugins.

Using yarn:
```bash
>_ yarn add hable
>_ npm install hable
yarn add hable
```
Using npm:
```bash
npm install hable
```
## Usage

@@ -22,3 +33,3 @@

export default class MyLib extends Hookable {
export default class Foo extends Hookable {
constructor() {

@@ -30,7 +41,7 @@ // Call to parent to initialize

async someFunction() {
// Call and wait for `foo` hooks (if any) sequential
await this.callHook('foo')
// Call and wait for `hook1` hooks (if any) sequential
await this.callHook('hook1')
// Call and wait for `bar` hooks (if any) in paraller
await this.callHookAsync('bar')
// Call and wait for `hook2` hooks (if any) in paraller
await this.callHookAsync('hook2')
}

@@ -43,24 +54,27 @@ }

```js
const lib = new MyLib()
const lib = newFooLib()
// Register a handler for `foo`
lib.hook('foo', async () => { /* ... */ })
// Register a handler for `hook2`
lib.hook('hook2', async () => { /* ... */ })
// Register multiply handlers at once
lib.hookObj({
foo: async () => { /* ... */ },
bar: [ /* can be also an array */ ]
hook1: async () => { /* ... */ },
hook2: [ /* can be also an array */ ]
})
```
## API
## Hookable class
### Class functions
**private 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**.
**public functions**
* `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.
* `hookObj(hooksObj)`: Register many hooks using an object.
### Class attributes
**private attributes**

@@ -67,0 +81,0 @@ * `$hooks`: An object which maps from each hook name to it's handlers.

@@ -26,6 +26,2 @@ import { serial, parallel } from 'items-promise'

hook(name, fn) {
if (!name || typeof fn !== 'function') {
return
}
if (!this.$hooks[name]) {

@@ -43,3 +39,3 @@ this.$hooks[name] = []

hookObj(hooksObj) {
for (let name of Object.keys(hooksObj)) {
for (let name in hooksObj) {
this.hook(name, hooksObj[name])

@@ -46,0 +42,0 @@ }

Sorry, the diff of this file is not supported yet

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