MultiHook.js 898 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Hook = require("./Hook");
  7. class MultiHook {
  8. constructor(hooks, name = undefined) {
  9. this.hooks = hooks;
  10. this.name = name;
  11. }
  12. tap(options, fn) {
  13. for (const hook of this.hooks) {
  14. hook.tap(options, fn);
  15. }
  16. }
  17. tapAsync(options, fn) {
  18. for (const hook of this.hooks) {
  19. hook.tapAsync(options, fn);
  20. }
  21. }
  22. tapPromise(options, fn) {
  23. for (const hook of this.hooks) {
  24. hook.tapPromise(options, fn);
  25. }
  26. }
  27. isUsed() {
  28. for (const hook of this.hooks) {
  29. if (hook.isUsed()) return true;
  30. }
  31. return false;
  32. }
  33. intercept(interceptor) {
  34. for (const hook of this.hooks) {
  35. hook.intercept(interceptor);
  36. }
  37. }
  38. withOptions(options) {
  39. return new MultiHook(
  40. this.hooks.map(h => h.withOptions(options)),
  41. this.name
  42. );
  43. }
  44. }
  45. module.exports = MultiHook;