Comparing version 0.0.7 to 0.0.8
55
index.js
@@ -22,6 +22,6 @@ // todo 用更好的方式继承 app.response. | ||
// 让 response.render 的时候,将 response 实例作为 locals 参数携带进来。 | ||
hackResponse(app); | ||
settings.views = app.get('views'); | ||
Engine = view.engines[settings.engine || 'swig']; | ||
@@ -33,7 +33,4 @@ | ||
var bigpipe = res.bigpipe; | ||
var fis = res.fis; | ||
var prototols = api(fis, bigpipe, settings.views); | ||
var prototols = api(res.fis, bigpipe, settings.views); | ||
var engine = new Engine(settings, prototols); | ||
var bufs = []; | ||
@@ -44,38 +41,25 @@ // 这个模式表示是一次请求局部内容的请求。 | ||
var isQuickingMode = bigpipe && bigpipe.isQuickingMode(); | ||
var flush = function() { | ||
if (isQuickingMode) { | ||
return; | ||
} | ||
while((d = bufs.shift())) { | ||
d = prototols.filter(d); | ||
res.write(d); | ||
} | ||
}; | ||
var finish = function(err, data) { | ||
engine.destroy(); | ||
options.response = engine = bigpipe = fis = null; | ||
if (err) { | ||
return done(err); | ||
} | ||
bufs.push(data || ''); | ||
flush(); | ||
res = null; | ||
data && res.write(data); | ||
// prototols.destroy(); | ||
res = finish = null; | ||
done(); | ||
}; | ||
engine.on('data', function(d) { | ||
bufs.push(d); | ||
}); | ||
engine.on('flush', flush); | ||
options._yog = prototols; | ||
engine.renderFile(filepath, options, function(err, output) { | ||
if (err) { | ||
return finish(err); | ||
} | ||
engine.on('end', function(output) { | ||
output = output || bufs.pop() || ''; | ||
output = prototols.filter(output); | ||
var identify = '</body>'; | ||
var idx = output.indexOf(identify); | ||
var identify = prototols.BIGPIPE_HOOK; | ||
var idx = identify ? output.indexOf(identify) : -1; | ||
var clouser = ''; | ||
@@ -87,10 +71,7 @@ | ||
if (~idx) { | ||
idx += identify.length; | ||
clouser = output.substring(idx); | ||
clouser = output.substring(idx + identify.length); | ||
output = output.substring(0, idx); | ||
} | ||
// flush framework. | ||
bufs.push(output); | ||
flush(); | ||
res.write(output); | ||
@@ -104,6 +85,2 @@ // then chunk out pagelets | ||
}); | ||
engine.on('error', finish); | ||
options._yog = prototols; | ||
engine.renderFile(filepath, options); | ||
} | ||
@@ -110,0 +87,0 @@ } |
@@ -93,2 +93,3 @@ var path = require('path'); | ||
JS_HOOK: '<!--FIS_JS_HOOK-->', | ||
BIGPIPE_HOOK: bigpipe ? '<!--FIS_BIGPIPE_HOOK-->' : '', | ||
@@ -95,0 +96,0 @@ /** |
@@ -6,5 +6,9 @@ var proto = module.exports = { | ||
options['response'] = this; | ||
return proto.__proto__.render.apply(this, arguments); | ||
var ret = proto.__proto__.render.apply(this, arguments); | ||
delete options.response; | ||
return ret; | ||
} | ||
}; |
{ | ||
"name": "yog-view", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "An express.js middleware for optimizing the order of js\\css output, and enabling render template in bigpipe mode.", | ||
@@ -26,4 +26,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"yog-swig": "~0.0.6" | ||
"yog-swig": "~0.0.7" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
13727
298
Updatedyog-swig@~0.0.7