Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bigkoa

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigkoa - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.circleci/config.yml

8

examples/bpmodules/basic/index.js

@@ -11,8 +11,8 @@ const MyBigView = require('./MyBigView')

// main and layout setter
bigpipe.setMain(new Main(ctx))
bigpipe.setLayout(new Layout(ctx))
bigpipe.main = Main
bigpipe.layout = Layout
bigpipe.mode = 'pipeline'
bigpipe.add(P1, ctx)
bigpipe.add(P2, ctx)
bigpipe.add(P1)
bigpipe.add(P2)

@@ -19,0 +19,0 @@ if (ctx.query && ctx.query.bigview_mode) {

const path = require('path')
const Biglet = require('biglet')
const Biglet = require('biglet')

@@ -17,3 +17,2 @@ module.exports = class LayoutPagelet extends Biglet {

this.domid = 'layout'
this.location = 'layout'
this.tpl = path.join(__dirname, './tpl/index')

@@ -20,0 +19,0 @@ this.delay = 1000

@@ -1,3 +0,2 @@

const path = require('path')
const Biglet = require('biglet')
const Biglet = require('biglet')

@@ -16,4 +15,3 @@ module.exports = class MainPagelet extends Biglet {

this.domid = 'main'
this.location = 'main'
this.tpl = path.join(__dirname, './tpl/index')
this.tpl = './tpl/index'
this.delay = 1000

@@ -20,0 +18,0 @@ }

@@ -17,3 +17,3 @@ const path = require('path')

this.domid = 'pagelet1'
this.tpl = path.join(__dirname, './tpl/index')
this.tpl = './tpl/index'
this.location = 'pagelet1'

@@ -20,0 +20,0 @@ this.delay = 4000

@@ -17,3 +17,3 @@ const path = require('path')

this.domid = 'pagelet2'
this.tpl = path.join(__dirname, './p2')
this.tpl = './p2'
this.delay = 7000

@@ -20,0 +20,0 @@ }

{
"name": "bigkoa",
"version": "0.1.1",
"version": "0.1.2",
"description": "",

@@ -8,6 +8,8 @@ "main": "src/index.js",

"bluebird": "^3.4.7",
"debug": "^2.3.3"
"debug": "^2.3.3",
"lru_map": "^0.3.3"
},
"devDependencies": {
"ava": "^0.16.0",
"benchmark": "^2.1.4",
"biglet": "^1.3.14",

@@ -30,2 +32,3 @@ "chromedriver": "^2.34.1",

"nightwatch-helpers": "^1.2.0",
"nunjucks": "^3.0.1",
"nyc": "^10.0.0",

@@ -35,3 +38,3 @@ "open": "0.0.5",

"sinon": "^1.17.7",
"standard": "^8.4.0",
"standard": "^10.0.2",
"testchunks": "^1.0.1"

@@ -46,5 +49,8 @@ },

"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
"standard": "standard index.js",
"standard": "standard src/*.js src/mode/*.js",
"chromedriver": "npm install --save-dev chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver"
},
"engines": {
"node": ">= 8"
},
"keywords": [],

@@ -51,0 +57,0 @@ "author": "i5ting",

@@ -1,6 +0,6 @@

# BigKoa (Node.js 4.x +)
# BigKoa (Node.js 8.x +)
> BigKoa = BigView + Koa
[![Build](https://travis-ci.org/bigviewjs/bigkoa.svg?branch=master)](https://travis-ci.org/bigviewjs/bigkoa)
<a href="https://circleci.com/gh/bigviewjs/bigkoa/tree/master"><img src="https://img.shields.io/circleci/project/bigviewjs/bigkoa/master.svg" alt="Build Status"></a>
[![codecov.io](https://codecov.io/github/bigviewjs/bigkoa/coverage.svg?branch=master)](https://codecov.io/github/bigviewjs/bigkoa?branch=master)

@@ -7,0 +7,0 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

@@ -22,4 +22,2 @@ 'use strict'

this.res = ctx.res
this.render = ctx.render
// 用于缓存res.write的内容

@@ -86,2 +84,10 @@ this.cache = []

/**
* render the template
* @api public
*/
render (...args) {
return this.ctx.render(...args)
}
/**
* Write bigview data to Browser.

@@ -96,4 +102,2 @@ *

debug('Write data to Browser ' + text)
// 是否立即写入,如果不立即写入,放到this.cache里

@@ -108,5 +112,2 @@ if (!isWriteImmediately || this.modeInstance.isLayoutWriteImmediately === false) {

debug('BigView final data = ' + text)
debug(text)
if (text && text.length > 0) {

@@ -113,0 +114,0 @@ // write to Browser;

'use strict'
const debug = require('debug')('bigview')
const Promise = require('bluebird')

@@ -9,2 +7,4 @@

const Utils = require('./utils')
const { lurMapCache } = Utils
const PROMISE_RESOLVE = Promise.resolve(true)

@@ -33,12 +33,26 @@

// 页面render的梳理里会有this.data.pagelets
// 限制缓存的个数
this.cacheLevel = options.cacheLevel
if (this.cacheLevel) {
lurMapCache.init(options.cacheLimits || 30, this.cacheLevel)
}
}
setMain (main) {
this.main = main
set layout (layout) {
this._layout = layout
}
setLayout (layout) {
this.layout = layout
set main (main) {
this._main = main
}
get main () {
return this._main
}
get layout () {
return this._layout
}
_getPageletObj (Pagelet) {

@@ -52,2 +66,3 @@ let pagelet

}
pagelet.owner = this
pagelet.dataStore = this.dataStore

@@ -127,18 +142,25 @@

data.errorPagelet = self.errorPagelet
return self.render(tpl, data)
}
return new Promise(function (resolve, reject) {
debug('renderLayout')
self.ctx.render(tpl, data, function (err, str) {
if (err) {
debug('renderLayout ' + str)
Utils.log(err)
return reject(err)
}
debug(str)
let html = str + Utils.ready(self.debug)
// 在pipeline模式下会直接写layout到浏览器
self.write(html, self.modeInstance.isLayoutWriteImmediately)
// html没用到
resolve(html)
})
render (tpl, data, cb) {
const cacheLevel2 = lurMapCache.get(tpl, 2)
if (cacheLevel2) {
return cb && cb(null, cacheLevel2)
}
const cacheLevel1 = lurMapCache.get(tpl)
if (cacheLevel1) {
tpl = cacheLevel1
}
this.ctx.render(tpl, data, function (err, html) {
if (err) {
return Utils.log(err)
}
// let html = str + Utils.ready(this.debug)
// 在pipeline模式下会直接写layout到浏览器
cb && cb(err, html)
if (cacheLevel1 || cacheLevel2) {
return
}
lurMapCache.set(tpl, html)
})

@@ -148,12 +170,8 @@ }

renderMain () {
let syncArray = []
let self = this
debug('BigView renderLayoutAndMain')
let mainPagelet = null
if (this.main) {
mainPagelet = this._getPageletObj(this.main)
syncArray.push(self.compile(mainPagelet.tpl, mainPagelet.data))
return Promise.all([mainPagelet._exec()])
mainPagelet.data.pagelets = this.pagelets
return mainPagelet._exec()
} else {

@@ -166,9 +184,27 @@ return Promise.resolve(true)

const self = this
const layoutPagelet = this._getPageletObj(this.layout)
return new Promise(function (resolve, reject) {
self.ctx.render(self.layout.tpl, self.layout.data, function (err, html) {
self.write(html, self.modeInstance.isLayoutWriteImmediately)
let tpl = layoutPagelet.tpl
const cacheLevel2 = lurMapCache.get(tpl, 2)
if (cacheLevel2) {
debug('Use cache level 2')
self.write(cacheLevel2, self.modeInstance.isLayoutWriteImmediately)
return resolve(cacheLevel2)
}
const cacheLevel1 = lurMapCache.get(tpl, 1)
if (cacheLevel1) {
debug('Use cache level 1')
tpl = cacheLevel1
}
self.ctx.render(tpl, layoutPagelet.data, function (err, html) {
if (err) {
return reject(err)
reject(err)
} else {
self.write(html, self.modeInstance.isLayoutWriteImmediately)
resolve(html)
if (cacheLevel1 || cacheLevel2) {
return
}
lurMapCache.set(tpl, html)
}
return resolve(true)
})

@@ -215,2 +251,9 @@ })

debug('default after')
// set level 1 cache
// this.pagelets.forEach((pagelet) => {
// const tpl = pagelet.tpl
// if (!lurMapCache.get(tpl)) {
// lurMapCache.set(tpl)
// }
// })
return PROMISE_RESOLVE

@@ -217,0 +260,0 @@ }

@@ -15,3 +15,3 @@ 'use strict'

constructor () {
this.mode = 'render';
this.mode = 'render'
this.isLayoutWriteImmediately = false

@@ -18,0 +18,0 @@ this.isPageletWriteImmediately = false

'use strict'
const fs = require('fs')
const { LRUMap } = require('lru_map')
const MODULE_ID = 'BIGVIEW'

@@ -32,1 +33,30 @@

}
exports.lurMapCache = {
init (limits, level) {
if (limits && !this._lruMap) {
this._lruMap = new LRUMap(limits)
}
this._level = level
},
set (key, val) {
if (this._level === 1) {
val = fs.readFileSync(key, 'utf8')
}
this._lruMap && this._lruMap.set(key + '_' + this._level, val)
},
get (key, level) {
return this._lruMap && this._lruMap.get(key + '_' + level)
},
delete (key) {
return this._lruMap.delete(key + '_' + this._level)
},
clear () {
this._lruMap.clear()
this._lruMap = null
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc