yog-bigpipe
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -42,3 +42,3 @@ var Pagelet = require('./pagelet.js'); | ||
var arr = this.quicklings; | ||
arr.splice.apply(arr, [arr.length, 0].concat(pagelets)); | ||
arr.push.apply(arr, pagelets); | ||
}; | ||
@@ -138,2 +138,3 @@ | ||
cb(null, ''); | ||
cb = this.cb = null; | ||
} | ||
@@ -140,0 +141,0 @@ }; |
@@ -49,3 +49,3 @@ var util = require("util"); | ||
self._render(val); | ||
self.destroyed || self._render(val); | ||
}); | ||
@@ -55,3 +55,3 @@ } else if (typeof source ==='string' && source) { | ||
} else { | ||
this._render(); | ||
process.nextTick(this._render.bind(this)); | ||
} | ||
@@ -61,8 +61,4 @@ }; | ||
Pagelet.prototype._render = function(model) { | ||
if (this.destroyed) { | ||
return; | ||
} | ||
var locals = this.locals; | ||
var fn = this.compiled; | ||
var _yog = locals._yog; | ||
var self = this; | ||
@@ -73,13 +69,20 @@ var output; | ||
this.fis = _yog.fis.fork(); | ||
locals._yog = _yog.fork(this.fis, locals._yog.bigpipe); | ||
this._yog = locals._yog = locals._yog.fork(); | ||
// hook sub pagelet render. | ||
// make that render after this pagelet render. | ||
var origin = locals._yog.addPagelet; | ||
locals._yog.addPagelet = function() { | ||
var args = arguments; | ||
var me = this; | ||
self.once('ready', function() { | ||
origin.apply(me, args); | ||
var subpagelets = []; | ||
self.onReady = function() { | ||
subpagelets.forEach(function(args) { | ||
origin.apply(locals._yog, args); | ||
}); | ||
locals = self = origin = null; | ||
}; | ||
locals._yog.addPagelet = function() { | ||
subpagelets.push(arguments); | ||
}; | ||
output = fn(locals); | ||
@@ -90,3 +93,3 @@ this.analyse(output); | ||
Pagelet.prototype.analyse = function(output) { | ||
var fis = this.fis; | ||
var yog = this._yog; | ||
var scripts = this.scripts; | ||
@@ -96,10 +99,13 @@ var js = this.js; | ||
var styles = this.styles; | ||
var yogScripts = yog.getScripts(); | ||
var yogStyles = yog.getStyles(); | ||
var p; | ||
// 收集js, css, html | ||
if(fis.getResourceMap()) { | ||
if(yog.getResourceMap()) { | ||
scripts.push('require.resourceMap(' + JSON.stringify(this.getResourceMap()) + ');'); | ||
} | ||
styles.splice.apply(styles, [styles.length, 0].concat(fis.styles)); | ||
styles.push.apply(styles, yogStyles.embed); | ||
output = output.replace(/<script[^>]*?>([\s\S]+?)<\/script>/ig, function(_, content) { | ||
@@ -112,8 +118,10 @@ scripts.push(content); | ||
}); | ||
scripts.splice.apply(scripts, [scripts.length, 0].concat(fis.scripts)); | ||
fis.sync['js'] && (js = this.js = fis.sync['js'].concat()); | ||
fis.sync['css'] && (css = this.css = fis.sync['css'].concat()); | ||
scripts.push.apply(scripts, yogScripts.embed); | ||
yogScripts.urls && (js = this.js = yogScripts.urls.concat()); | ||
yogStyles.urls && (css = this.css = yogStyles.urls.concat()); | ||
this.html = output; | ||
this.state = status.fulfilled; | ||
this.onReady && this.onReady(); | ||
this.emit('ready', this); | ||
@@ -120,0 +128,0 @@ }; |
{ | ||
"name": "yog-bigpipe", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "An express.js middleware for fis widget pipline output.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
21395
542