Projekt

Obecné

Profil

Stáhnout (1.16 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
/*
2
	MIT License http://www.opensource.org/licenses/mit-license.php
3
	Author Tobias Koppers @sokra
4
*/
5
"use strict";
6
7
const Hook = require("./Hook");
8
const HookCodeFactory = require("./HookCodeFactory");
9
10
class AsyncSeriesWaterfallHookCodeFactory extends HookCodeFactory {
11
	content({ onError, onResult, onDone }) {
12
		return this.callTapsSeries({
13
			onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
14
			onResult: (i, result, next) => {
15
				let code = "";
16
				code += `if(${result} !== undefined) {\n`;
17
				code += `${this._args[0]} = ${result};\n`;
18
				code += `}\n`;
19
				code += next();
20
				return code;
21
			},
22
			onDone: () => onResult(this._args[0])
23
		});
24
	}
25
}
26
27
const factory = new AsyncSeriesWaterfallHookCodeFactory();
28
29
class AsyncSeriesWaterfallHook extends Hook {
30
	constructor(args) {
31
		super(args);
32
		if (args.length < 1)
33
			throw new Error("Waterfall hooks must have at least one argument");
34
	}
35
36
	compile(options) {
37
		factory.setup(this, options);
38
		return factory.create(options);
39
	}
40
}
41
42
Object.defineProperties(AsyncSeriesWaterfallHook.prototype, {
43
	_call: { value: undefined, configurable: true, writable: true }
44
});
45
46
module.exports = AsyncSeriesWaterfallHook;