Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d33c42

Browse files
committed
feat(connect): implement junction
1 parent4902598 commit6d33c42

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

‎src/connect/junction.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
"use strict";
2-
functionapplyMiddleware(text,middleware,next){
3-
middleware(text,next);
2+
functionisErrorHandingMiddleware(middleware){
3+
// middleware(error, text, next)
4+
vararity=middleware.length;
5+
returnarity===3;
6+
}
7+
functionapplyMiddleware(error,text,middleware,next){
8+
leterrorOnMiddleware=null;
9+
try{
10+
if(error&&isErrorHandingMiddleware(middleware)){
11+
middleware(error,text,next);
12+
}else{
13+
middleware(text,next);
14+
}
15+
return;
16+
}catch(error){
17+
errorOnMiddleware=error;
18+
}
19+
// skip the middleware or Error on the middleware
20+
next(errorOnMiddleware,text);
421
}
522

623
exportdefaultclassJunction{
@@ -18,7 +35,7 @@ export default class Junction {
1835
if(!middleware){
1936
returncallback(error,data);
2037
}
21-
applyMiddleware(data,middleware,next);
38+
applyMiddleware(error,data,middleware,next);
2239
};
2340
next(null,text);
2441
}

‎test/connect/junction-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
importassertfrom"power-assert";
4+
importJunctionfrom"../../src/connect/junction";
5+
describe("junction",function(){
6+
describe("when",function(){
7+
it("should",function(done){
8+
varjunction=newJunction();
9+
junction.use(functionerrorHandling(error,text,next){
10+
next(error);
11+
});
12+
junction.use(functiontoUpper(text,next){
13+
next(null,text.toLocaleUpperCase());
14+
});
15+
junction.use(functionaddDesu(text,next){
16+
next(null,text+" suffix");
17+
});
18+
junction.process("text",(error,result)=>{
19+
if(error){
20+
returndone(error);
21+
}
22+
assert.equal(result,"TEXT suffix");
23+
done();
24+
});
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp