-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (46 loc) · 1.11 KB
/
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
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
"use strict";
var jsx = require('jsx-runtime');
var idom = typeof _mockdom !== 'undefined' ? _mockdom : require('incremental-dom');
var hasOwn = Object.prototype.hasOwnProperty;
var openStart = idom.elementOpenStart;
var openEnd = idom.elementOpenEnd;
var close = idom.elementClose;
var text = idom.text;
var attr = idom.attr;
var element = {};
var renderer = jsx.register('DOM', {
tags: {
'*': {
enter: function(tag, props) {
openStart(tag);
if (props) {
handleProps(props);
}
openEnd();
return element;
},
leave: function(parent, tag) {
close(tag);
return parent;
},
child: function(child, parent) {
if (child === element) {
// do nothing
} else {
text(child + '');
}
return parent;
}
}
}
});
module.exports = renderer;
function handleProps(props) {
for (var key in props) {
if (!hasOwn.call(props, key)) continue;
var val = props[key];
if (key === 'className') key = 'class';
if (key === 'cssFor') key = 'for';
attr(key, val);
}
}