-
Notifications
You must be signed in to change notification settings - Fork 14
/
render.js
71 lines (57 loc) · 1.46 KB
/
render.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var simplePromise = require('./simplePromise')
function runRender (mount, fn) {
if (runRender._currentRender) {
return
}
var render = new Render(mount)
try {
runRender._currentRender = render
var vdom = fn()
render.finished.fulfill()
return vdom
} finally {
runRender._currentRender = undefined
}
}
runRender._currentRender = undefined
function Render (mount) {
this.finished = simplePromise()
this.mount = mount
this.attachment = mount
}
Render.prototype.transformFunctionAttribute = function () {
return this.mount.transformFunctionAttribute.apply(this.mount, arguments)
}
module.exports = runRender
module.exports.currentRender = currentRender
module.exports.refreshify = refreshify
module.exports.RefreshHook = RefreshHook
function currentRender () {
return runRender._currentRender || defaultRender
}
var defaultRender = {
mount: {
setupModelComponent: function () { },
refreshify: function (fn) { return fn }
},
transformFunctionAttribute: function (key, value) {
return new RefreshHook(value)
},
finished: {
then: function (fn) {
fn()
}
}
}
function refreshify (fn, options) {
return runRender.currentRender().mount.refreshify(fn, options)
}
function RefreshHook (handler) {
this.handler = handler
}
RefreshHook.prototype.hook = function (node, property) {
node[property] = refreshify(this.handler)
}
RefreshHook.prototype.unhook = function (node, property) {
node[property] = null
}