Add MultiHook and _pluginCompat to Tapable (#24527)

* Fix Tapable types

* ..

* Clean up

* Undo instance member change

* Add constructor to Hookmap
This commit is contained in:
Mohsen Azimi
2018-03-27 11:32:31 -07:00
committed by Mohamed Hegazy
parent 966fe06044
commit d5cbb8d3cb
2 changed files with 21 additions and 1 deletions

View File

@@ -9,6 +9,9 @@ export declare abstract class Tapable {
[propName: string]: Tapable.Handler[]
}
/** @deprecated Private internals. Do not use directly */
_pluginCompat: Hook;
/**
* @deprecated Tapable.plugin is deprecated. Use new API on `.hooks` instead
* Register plugin(s)
@@ -275,7 +278,9 @@ export class HookInterceptor {
context: boolean;
}
/** A HookMap is a helper class for a Map with Hooks */
export class HookMap<T1 = any, T2 = any, T3 = any> {
constructor(fn: () => Hook);
get: (key: any) => Hook<T1, T2, T3> | undefined;
for: (key: any) => Hook<T1, T2, T3>;
tap: (key: any, name: string | Tap, fn: (arg1: T1, arg2: T2, arg3: T3, ...args: any[]) => any) => void;
@@ -287,3 +292,16 @@ export class HookMap<T1 = any, T2 = any, T3 = any> {
export class HookMapInterceptor<T1 = any, T2 = any, T3 = any> {
factory: (key: any, hook: Hook<T1, T2, T3>) => Hook<T1, T2, T3>;
}
/**
* A helper Hook-like class to redirect taps to multiple other hooks
*
* ```
* const { MultiHook } = require("tapable");
*
* this.hooks.allHooks = new MultiHook([this.hooks.hookA, this.hooks.hookB]);
* ```
*/
export class MultiHook {
constructor(hooks: Hook[])
}

View File

@@ -1,4 +1,4 @@
import {Tapable} from "tapable";
import {Tapable, MultiHook, SyncHook} from "tapable";
class DllPlugin {
apply(compiler: Compiler) {
@@ -43,3 +43,5 @@ compiler.applyPluginsAsyncWaterfall('doSomething', 'a', callback);
compiler.applyPluginsParallel('doSomething', 'a', 'b');
compiler.applyPluginsParallelBailResult('doSomething', 'a', 'b');
compiler.applyPluginsParallelBailResult1('doSomething', 'a', callback);
const multi = new MultiHook([new SyncHook(['hi'])]);