Comparing version 0.2.1 to 0.3.0
var Transform = require('stream').Transform; | ||
module.exports = function(layer) { | ||
module.exports = function (layer) { | ||
var stream = new Transform(); | ||
var bigpipe = layer.bigpipe; | ||
var isQuickingMode = bigpipe && bigpipe.isQuickingMode(); | ||
var isQuicklingMode = bigpipe && bigpipe.isQuicklingMode(); | ||
var identify = layer.BIGPIPE_HOOK; | ||
// chain error | ||
stream.on('pipe', function(source) { | ||
stream.on('pipe', function (source) { | ||
source.on('error', this.emit.bind(this, 'error')); | ||
}); | ||
stream._transform = function(chunk, encoding, done) { | ||
var output = isQuickingMode ? '' : layer.filter(chunk.toString()); | ||
stream._transform = function (chunk, encoding, done) { | ||
var output = isQuicklingMode ? '' : layer.filter(chunk.toString()); | ||
var idx = identify ? output.indexOf(identify) : -1; | ||
var clouser = ''; | ||
// bigpipe mode | ||
if (bigpipe && (~idx || isQuickingMode)) { | ||
if (bigpipe && (~idx || isQuicklingMode)) { | ||
if (~idx) { | ||
@@ -32,15 +32,15 @@ clouser = output.substring(idx + identify.length); | ||
// chain error. | ||
// chain error. | ||
.on('error', stream.emit.bind(stream, 'error')) | ||
.on('data', function(chunk) { | ||
stream.push(chunk); | ||
}) | ||
.on('data', function (chunk) { | ||
stream.push(chunk); | ||
}) | ||
.on('end', function() { | ||
stream.push(clouser); | ||
done(); | ||
}); | ||
.on('end', function () { | ||
stream.push(clouser); | ||
done(); | ||
}); | ||
} | ||
this.push(output); | ||
@@ -51,2 +51,2 @@ return done(); | ||
return stream; | ||
}; | ||
}; |
{ | ||
"name": "yog-view", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "An express.js middleware for optimizing the order of js\\css output, and enabling render template in bigpipe mode.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
574
22533