-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 843 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
Transformer.prototype.with = transformWith;
Transformer.prototype.using = using;
Transformer.prototype.complete = complete;
Transformer.prototype.transform = transform;
module.exports = Transformer;
function Transformer(key, state) {
this.state = state;
this.key = key;
}
function transformWith(transformer) {
this.transformer = transformer;
if (this.complete()) {
this.transform();
}
return this;
}
function using() {
this.varargs = [].slice.call(arguments);
this.varargs.unshift(this.state.get(this.key));
if (this.complete()) {
this.transform();
}
return this;
}
function transform() {
var result = this.transformer.apply(null, this.varargs);
this.state.set(this.key, result);
}
function complete() {
return !!this.transformer && !!this.varargs;
}