MultiHook.js 873 B

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