An open API service indexing awesome lists of open source software.

https://github.com/kaelzhang/tapable-proxy

The pseudo tapable based on Proxy
https://github.com/kaelzhang/tapable-proxy

fake hooks proxy tapable

Last synced: 2 months ago
JSON representation

The pseudo tapable based on Proxy

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/kaelzhang/tapable-proxy.svg?branch=master)](https://travis-ci.org/kaelzhang/tapable-proxy)
[![Coverage](https://codecov.io/gh/kaelzhang/tapable-proxy/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/tapable-proxy)

# tapable-proxy

The pseudo tapable based on [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). `tapable-proxy` could create fake hooks which can be tapped even before the creation of real hooks.

## Install

```sh
$ npm i tapable-proxy
```

## Usage

```js
const {
create,
APPLY_TAPS,
SET_HOOKS
} = require('tapable-proxy')

// Create a fake hook proxy
const hooks = create()

hooks.afterEmit.tap('MyPlugin', compilation => {
// ...
})

// Apply all taps to webpack compiler hooks
hooks[APPLY_TAPS](compiler.hooks)

// Proxy the follow-up taps to compiler hooks
hooks[SET_HOOKS](compiler.hooks)
```

### hooks\[APPLY_TAPS](realHooks, clean)

- **realHooks** `{[string]: Tapable}` the real [tapable](https://www.npmjs.com/package/tapable) hooks
- **clean?** `boolean=true` If `true`, the tapped handlers will be maintained after applied. Defaults to `true`

### hooks\[SET_HOOKS](realHooks)

Set the underlying hooks of the proxy as `realHooks`, and after that follop-up taps will directly tap into `realHooks`.

## License

[MIT](LICENSE)