yog-bigpipe
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -10,2 +10,3 @@ var Pagelet = require('./pagelet.js'); | ||
this.options = _.mixin(_.mixin({}, BigPipe.options), options); | ||
this.map = {}; | ||
this.pagelets = []; | ||
@@ -79,4 +80,10 @@ this.pipelines = []; | ||
return false; | ||
} else if (!obj.id) { | ||
this.emit('error', new Error('Id is required when add pagelet')); | ||
return; | ||
} | ||
// todo 如果某个 quickling widget 里面再包含一个非 quickling 的 pagelet, 则不会渲染。 | ||
// 应该需要渲染才对。 | ||
// 注意: 如果 quickling 的 widget 藏在某些异步 widget 里面,岂不是找不到? | ||
@@ -87,7 +94,16 @@ if (!this.isQuickingMode() && obj.mode !== mode.pipeline && obj.mode !== mode.async) { | ||
return false; | ||
} else if (this.isQuickingMode() && | ||
(obj.mode !== mode.quickling || !~this.quicklings.indexOf(obj.id))) { | ||
} else if (this.isQuickingMode()) { | ||
var parent = obj; | ||
// quickling 请求,只接收 quickling 模式的 pagelet. | ||
return false; | ||
// 找到最近的一个 quickling 父亲节点。 | ||
while (parent && parent.parentId) { | ||
if (parent.mode === mode.quickling) { | ||
break; | ||
} | ||
parent = this.map[parent.parentId]; | ||
} | ||
if (parent.mode !== mode.quickling || !~this.quicklings.indexOf(parent.id)) { | ||
return false; | ||
} | ||
} | ||
@@ -99,2 +115,3 @@ | ||
this.pagelets.push(pagelet); | ||
this.map[pagelet.id] = pagelet; | ||
pagelet.mode === mode.pipeline && this.pipelines.push(pagelet); | ||
@@ -151,3 +168,3 @@ | ||
this.rendered = this.pipelines = this.pagelets = this.quicklings = null; | ||
this.rendered = this.pipelines = this.pagelets = this.map = this.quicklings = null; | ||
}; | ||
@@ -196,3 +213,3 @@ | ||
var tpl = this.options.tpl; | ||
var type = pagelet.mode; | ||
var type = this.isQuickingMode() ? 'quickling' : '_default'; | ||
var json = pagelet.toJson(); | ||
@@ -199,0 +216,0 @@ var obj = {}; |
{ | ||
"name": "yog-bigpipe", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "An express.js middleware for fis widget pipline output.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
28606
714