Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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;