Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AsyncSeriesWaterfallHook.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. const HookCodeFactory = require("./HookCodeFactory");
  8. class AsyncSeriesWaterfallHookCodeFactory extends HookCodeFactory {
  9. content({ onError, onResult, onDone }) {
  10. return this.callTapsSeries({
  11. onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
  12. onResult: (i, result, next) => {
  13. let code = "";
  14. code += `if(${result} !== undefined) {\n`;
  15. code += `${this._args[0]} = ${result};\n`;
  16. code += `}\n`;
  17. code += next();
  18. return code;
  19. },
  20. onDone: () => onResult(this._args[0])
  21. });
  22. }
  23. }
  24. const factory = new AsyncSeriesWaterfallHookCodeFactory();
  25. class AsyncSeriesWaterfallHook extends Hook {
  26. constructor(args) {
  27. super(args);
  28. if (args.length < 1)
  29. throw new Error("Waterfall hooks must have at least one argument");
  30. }
  31. compile(options) {
  32. factory.setup(this, options);
  33. return factory.create(options);
  34. }
  35. }
  36. Object.defineProperties(AsyncSeriesWaterfallHook.prototype, {
  37. _call: { value: undefined, configurable: true, writable: true }
  38. });
  39. module.exports = AsyncSeriesWaterfallHook;