Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "bigkoa", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -67,3 +67,3 @@ # BigKoa (Node.js 8.x +) | ||
Install | ||
Install | ||
@@ -156,8 +156,8 @@ ``` | ||
<li><%= p.name %> | <%= p.selector %> | ||
<% if (p.children.length) { %> | ||
<ul> | ||
<% p.children.forEach(function(sub){ %> | ||
<% if (p.children.length) { %> | ||
<ul> | ||
<% p.children.forEach(function(sub){ %> | ||
<li> subPagelet = <%= sub.name %> | <%= sub.selector %> | ||
<% }) %> | ||
</ul> | ||
<% }) %> | ||
</ul> | ||
<% } %> | ||
@@ -177,3 +177,3 @@ <% }) %> | ||
<% pagelets.forEach(function(p){ %> | ||
bigpipe.ready('<%= p.name %>',function(data){ | ||
@@ -187,3 +187,3 @@ $("#<%= p.location %>").html(data); | ||
}) | ||
</script> | ||
@@ -211,8 +211,8 @@ </body> | ||
<li><%= p.name %> | <%= p.selector %> | ||
<% if (p.children.length) { %> | ||
<ul> | ||
<% p.children.forEach(function(sub){ %> | ||
<% if (p.children.length) { %> | ||
<ul> | ||
<% p.children.forEach(function(sub){ %> | ||
<li> subPagelet = <%= sub.name %> | <%= sub.selector %> | ||
<% }) %> | ||
</ul> | ||
<% }) %> | ||
</ul> | ||
<% } %> | ||
@@ -232,3 +232,3 @@ <% }) %> | ||
<% pagelets.forEach(function(p){ %> | ||
bigpipe.ready('<%= p.name %>',function(data){ | ||
@@ -317,3 +317,3 @@ $("#<%= p.location %>").html(data); | ||
return Promise.resolve(true) | ||
} | ||
} | ||
} | ||
@@ -403,3 +403,3 @@ ``` | ||
<% pagelets.forEach(function(p){ %> | ||
bigpipe.ready('<%= p.name %>',function(data){ | ||
@@ -409,3 +409,3 @@ $("#<%= p.location %>").html(data); | ||
<% }) %> | ||
bigpipe.ready('<%= errorPagelet.name %>',function(data){ | ||
@@ -415,3 +415,3 @@ $("#<%= errorPagelet.location %>").html(data); | ||
</script> | ||
<script src="/bigconsole.min.js"></script> | ||
<script src="/bigconsole.min.js"></script> | ||
</body> | ||
@@ -531,3 +531,3 @@ </html> | ||
fetch () { | ||
fetch () { | ||
return new Promise(function(resolve, reject){ | ||
@@ -614,3 +614,3 @@ setTimeout(function() { | ||
console.log(pagelet.owner.query) | ||
pagelet.delay = 1000 | ||
@@ -622,3 +622,3 @@ return new Promise(function(resolve, reject){ | ||
}, pagelet.delay) | ||
}) | ||
}) | ||
} | ||
@@ -648,3 +648,3 @@ ``` | ||
fetch () { | ||
fetch () { | ||
return new Promise(function(resolve, reject){ | ||
@@ -669,3 +669,3 @@ setTimeout(function() { | ||
} | ||
resolve(str) | ||
@@ -743,3 +743,3 @@ }) | ||
xxx: yyy | ||
} | ||
} | ||
@@ -749,3 +749,3 @@ pagelet1.test() | ||
or | ||
or | ||
@@ -759,3 +759,11 @@ ``` | ||
## 支持 gzip 压缩 | ||
enable gzip: | ||
```javascript | ||
const bigkoa = new BigKoa({ gzip: true }) | ||
``` | ||
## More | ||
@@ -790,3 +798,3 @@ | ||
``` | ||
var FM=function(a,b,c){function bN(b,c){a.clear&&(bN=a.clear)(b,c)}function bM(b,c,d){a.start&&(bM=a.start)(b,c,d)}function bL(a){return a===null?"":Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function bK(){bv(function(){bH();for(var a in J){if(I[a]){bB(P,I[a]);delete | ||
var FM=function(a,b,c){function bN(b,c){a.clear&&(bN=a.clear)(b,c)}function bM(b,c,d){a.start&&(bM=a.start)(b,c,d)}function bL(a){return a===null?"":Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function bK(){bv(function(){bH();for(var a in J){if(I[a]){bB(P,I[a]);delete | ||
@@ -829,3 +837,3 @@ | ||
## 参考 | ||
## 参考 | ||
@@ -832,0 +840,0 @@ http://velocity.oreilly.com.cn/2011/ppts/WK_velocity.pdf |
@@ -6,2 +6,3 @@ 'use strict' | ||
const EventEmitter = require('events') | ||
const zlib = require('zlib') | ||
@@ -14,3 +15,3 @@ const ModeInstanceMappings = require('./mode') | ||
module.exports = class BigViewBase extends EventEmitter { | ||
constructor (ctx, layout, data) { | ||
constructor (ctx, options) { | ||
super() | ||
@@ -24,5 +25,9 @@ | ||
this.res = ctx.res | ||
// 用于缓存res.write的内容 | ||
this.cache = [] | ||
// 设置 gzip 压缩 | ||
this.gzip = !!options.gzip | ||
this.on('bigviewWrite', this.writeDataToBrowser.bind(this)) | ||
@@ -32,2 +37,16 @@ this.on('pageletWrite', this.writeDataToBrowser.bind(this)) | ||
set gzip (gzip) { | ||
if (gzip) { | ||
// set header | ||
this.ctx.set('Content-Encoding', 'gzip') | ||
this.output = zlib.createGzip() | ||
this.output.pipe(this.res) | ||
this._gzip = gzip | ||
} | ||
} | ||
get gzip () { | ||
return this._gzip | ||
} | ||
set dataStore (obj) { | ||
@@ -115,3 +134,10 @@ this._dataStore = obj | ||
// write to Browser; | ||
this.res.write(text) | ||
if (this.gzip) { | ||
this.output.write(text, () => { | ||
debug(`bigview gzip, text size is: ${text.length}`) | ||
this.output.flush() | ||
}) | ||
} else { | ||
this.res.write(text) | ||
} | ||
} | ||
@@ -118,0 +144,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251489
2933
879