MultiHook.js 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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) {
  9. this.hooks = hooks;
  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())
  29. 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(this.hooks.map(h => h.withOptions(options)));
  40. }
  41. }
  42. module.exports = MultiHook;