Skip to content

Commit 4902598

Browse files
committed
feat(connect): add junction
1 parent d679c5d commit 4902598

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/connect/junction.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
function applyMiddleware(text, middleware, next) {
3+
middleware(text, next);
4+
}
5+
6+
export default class Junction {
7+
constructor() {
8+
this.stack = [];
9+
}
10+
11+
use(middleware) {
12+
this.stack.push(middleware);
13+
}
14+
15+
process(text, callback) {
16+
let next = (error, data) => {
17+
let middleware = this.stack.shift();
18+
if (!middleware) {
19+
return callback(error, data);
20+
}
21+
applyMiddleware(data, middleware, next);
22+
};
23+
next(null, text);
24+
}
25+
}

0 commit comments

Comments
 (0)