yog-bigpipe
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -117,3 +117,3 @@ var Pagelet = require('./pagelet.js'); | ||
parent = this.map[parent.parentId]; | ||
if (parent.mode === mode.quickling && !!~this.quicklings.indexOf(parent.id)) { | ||
if (this.isQuicklingWidget(parent) && !!~this.quicklings.indexOf(parent.id)) { | ||
founded = true; | ||
@@ -156,2 +156,6 @@ // 插入为需要输出的Pagelet | ||
BigPipe.prototype.isQuicklingWidget = function (item) { | ||
return (item.mode === mode.quickling || item.mode === mode.async || item.mode === mode.pipeline); | ||
} | ||
BigPipe.prototype.render = function () { | ||
@@ -158,0 +162,0 @@ var pagelets = this.pagelets.concat(); |
{ | ||
"name": "yog-bigpipe", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "An express.js middleware for fis widget pipline output.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -288,2 +288,3 @@ (function (root) { | ||
var BigPipe = function () { | ||
var insertQueue = []; | ||
@@ -309,4 +310,11 @@ // The order of render pagelet. | ||
var remaining = 0; | ||
var item = { | ||
cssLoaded: false, | ||
finish: function () { | ||
insertDom(); | ||
} | ||
}; | ||
var loadCss = function () { | ||
insertQueue.push(item); | ||
// load css | ||
@@ -317,3 +325,7 @@ if (data.css && data.css.length) { | ||
Util.loadCss(data.css[i], BigPipe.ignoreDuplicate, function () { | ||
--remaining || insertDom(); | ||
--remaining; | ||
if (remaining === 0) { | ||
item.cssLoaded = true; | ||
finishInsertQueue(); | ||
} | ||
}); | ||
@@ -323,6 +335,16 @@ } | ||
else { | ||
insertDom(); | ||
item.cssLoaded = true; | ||
finishInsertQueue(); | ||
} | ||
}; | ||
var finishInsertQueue = function () { | ||
var item = insertQueue[0]; | ||
while (item && item.cssLoaded) { | ||
insertQueue.shift(); | ||
item.finish(); | ||
item = insertQueue[0]; | ||
} | ||
}; | ||
var insertDom = function () { | ||
@@ -359,4 +381,4 @@ var i, len, dom, node, text, scriptText, temp; | ||
var len = data.js && data.js.length; | ||
var remaining = len, | ||
i; | ||
var remaining = len; | ||
var i; | ||
@@ -399,3 +421,2 @@ // exec data.scripts | ||
/* registered pagelets */ | ||
currentPagelet = null, | ||
currReqID = null, | ||
@@ -415,4 +436,3 @@ cache = {}, | ||
this.trigger('pageletarrive', obj); | ||
var pagelet = PageLet(obj, function () { | ||
var pagelet = new PageLet(obj, function () { | ||
// console.log('dom ready', obj.id); | ||
@@ -426,6 +446,6 @@ var item; | ||
// console.log('pagelet exec js', item.pageletData.id); | ||
item.loadJs(function () { | ||
item.loadJs((function (item) { | ||
// console.log('pagelet exec done', item.pageletData.id); | ||
BigPipe.trigger('pageletdone', pagelet, item.pageletData); | ||
}); | ||
})(item)); | ||
} | ||
@@ -432,0 +452,0 @@ } |
38393
996