Skip to content

Commit

Permalink
added fab.filter and fab.parse binary apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Apr 25, 2010
1 parent 42b1570 commit a7e8a96
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions apps/fab.filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.summary = "Turns a function into a binary app that only sends responses that satisfy the function.";

exports.app = function( fn ) {
return function( app ) {
return function() {
var out = this;
return app.call( function listener( obj ) {
if ( !obj || fn.call( obj, obj ) ) {
out = out.apply( this, arguments );
}

return listener;
})
}
}
}
4 changes: 2 additions & 2 deletions apps/fab.nodejs.http.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ exports.app = function( app ) {
obj.headers || { host: loc.hostname }
)
.addListener( "response", function( response ) {
out({
out = out({
status: response.statusCode,
headers: response.headers
});

response
.addListener( "data", function( chunk ) {
out({ body: chunk });
if ( out ) out = out({ body: chunk });
})
.addListener( "end", out )
.setBodyEncoding( "utf8" );
Expand Down
9 changes: 9 additions & 0 deletions apps/fab.parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var fab = { map: require( "./fab.map" ).app };

exports.summary = "A binary app that converts JSON responses into objects.";

exports.app = fab.map( function( obj ) {
var body = obj.body;
if ( typeof body == "string" ) obj.body = JSON.parse( body );
return obj;
})

0 comments on commit a7e8a96

Please sign in to comment.