Projekt

Obecné

Profil

Stáhnout (1.22 KB) Statistiky
| Větev: | Revize:
1
/*
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 SyncWaterfallHookCodeFactory extends HookCodeFactory {
11
	content({ onError, onResult, resultReturns, rethrowIfPossible }) {
12
		return this.callTapsSeries({
13
			onError: (i, err) => onError(err),
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
			doneReturns: resultReturns,
24
			rethrowIfPossible
25
		});
26
	}
27
}
28

    
29
const factory = new SyncWaterfallHookCodeFactory();
30

    
31
class SyncWaterfallHook extends Hook {
32
	constructor(args) {
33
		super(args);
34
		if (args.length < 1)
35
			throw new Error("Waterfall hooks must have at least one argument");
36
	}
37

    
38
	tapAsync() {
39
		throw new Error("tapAsync is not supported on a SyncWaterfallHook");
40
	}
41

    
42
	tapPromise() {
43
		throw new Error("tapPromise is not supported on a SyncWaterfallHook");
44
	}
45

    
46
	compile(options) {
47
		factory.setup(this, options);
48
		return factory.create(options);
49
	}
50
}
51

    
52
module.exports = SyncWaterfallHook;
(14-14/16)