forked from yoshuawuyts/choo-component-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (22 loc) · 728 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var Cache = require('./lib/cache')
var assert = require('assert')
module.exports = store
function store (lru) {
return function (state, emitter, app) {
var cache = new Cache(state, emitter.emit.bind(emitter), lru)
state.cache = Render
function Render (Component, id) {
assert.equal(typeof Component, 'function', 'choo-component-preview: Component should be type function')
var args = []
for (var i = 0, len = arguments.length; i < len; i++) {
args.push(arguments[i])
}
return cache.render.apply(cache, args)
}
// When the state gets stringified, make sure `state.cache` isn't
// stringified too.
Render.toJson = function () {
return null
}
}
}