-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
204 lines (173 loc) · 5.68 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!doctype html>
<html>
<style>
* {
font-family: 'Helvetica';
}
.container {
width: 640px;
margin: auto;
text-align: center;
}
h1 {
font-size: 60px;
margin-bottom: 15px;
}
a {
}
p {
line-height: 1.5em;
}
code {
font-family: 'Courier';
background-color: #eee;
}
pre {
font-size: 14px;
text-align: left;
font-family: 'Courier';
background-color: lightgray;
padding: 10px;
}
pre span, pre a {
font-size: 14px;
text-align: left;
font-family: 'Courier';
}
.step-note {
color: #906;
}
.examples a {
display: block;
}
.comparison {
border-collapse: collapse;
border: 1px solid black;
}
.comparison td, .comparison th {
padding: 10px;
border: 1px solid black;
}
</style>
<body>
<div class="container">
<h1>Domrender</h1>
<p>An HTML view library in under 500 lines.</p>
<p>Similar to React, but a lot smaller.</p>
<a href="https://github.com/drewlesueur/domrender">Source on GitHub</a>
<h2>How to use</h2>
<pre>
<!doctype html>
<html>
<body>
<span class="step-note"><!-- Step 1. Include domrender.js --></span>
<span class="step"><script src="<a href="domrender.js">domrender.js</a>"></script></span>
<span class="step-note"><!-- Step 2. Make a template in html --></span>
<span class="step"><div id="click-app">
<button @e onclick="handleClick()">Click Me</button>
<br>
You clicked the button <span @v=clicks></span> times.
</div></span>
<script>
<span class="step-note">// Step 3. Make a JavaScript model</span>
<span class="step">var myClickApp = {
clicks: 0,
handleClick: function () {
myClickApp.clicks += 1
myView.render() // call render after update
}
}</span>
<span class="step-note">// Step 4. Bind the model to the dom element</span>
var el = document.getElementById("click-app")
var myView = domrender.use(el, myClickApp)
</script>
</body>
</html>
</pre>
<h2>Live Demo</h2>
<div>
<script src="domrender.js"></script>
<div id="click-app" style="background-color: #eee; width: 320px; padding: 10px; margin: auto;">
<button @e onclick="handleClick()">Click Me</button>
<br>
You clicked the button <span @v=clicks></span> times.
<br><br>
<a href="demos/hello_world.html">See demo standalone</a>
</div>
<h2>More Examples</h2>
<div class="examples">
<a href="demos/text_html.html">Text and raw html with input binding</a>
<a href="demos/attributes.html">Attributes with more form element binding</a>
<a href="demos/loops.html">Loops with events</a>
<a href="demos/components.html">Expressions and components</a>
<a href="demos/img.html">Images</a>
<a href="demos/radio.html">Radio buttons</a>
<a href="demos/loop_inputs.html">Loop with bound inputs</a>
<a href="demos/input_binding.html">Loop with bound inputs (updated)</a>
<a href="demos/input.html">onreceive handler</a>
<a href="demos/nested.html">Simple Nested Tree View</a>
<a href="demos/switch.html">Switches and case - conditional rendering</a>
<h2>Examples Coming Soon</h2>
<a>Todo App</a>
</div>
<h2>Concepts</h2>
<p style="text-align: left;">
Domrender is inspired by Riot and React.
Like Riot and React, you can think updates in Domrender as "re-render-the-world".
Where React uses the virtual dom diffing approach, Riot uses a value diffing approach.*
Like Riot, Domrender also uses a value diffing approach, but does not require any compiling of <code>.tag</code> files.
Domrender just uses your existing dom. In Domrender, when <code>render()</code> is called, it will reevaluate
all the expressions that are bound to the dom, and then update the dom if needed.
</p>
<p style="text-align: left;">
Another difference is that Domrender does not do anyting special with event handling.
Old-fashoned inline (<code>onclick=</code> style) events are
obvious and easy to debug. Domrender does give you a helpful feature (via the <code>@e</code> attribute) that lets
your inline event handlers have the same scope as the javascript object they are bound to. For example, in the live demo above,
you can say <code>onclick="handleClick()"</code> instead of <code>onclick="myClickApp.handleClick()"</code>.
<br>
<span style="font-size: 0.5em">*This is my understanding of Riot.</span>
</p>
<h2>Other view libraries</h2>
<div class="examples">
<a href="https://0x8890.github.io/simulacra/">Simulacra.js</a>
<a href="http://knockoutjs.com/">Knockout.js</a>
<a href="http://gwendall.github.io/way/">way.js</a>
<a href="https://github.com/skatejs/skatejs">skatejs</a>
<a href="https://frzr.js.org/">FRZR</a>
<a href="http://vuejs.org/">Vue.js</a>
<a href="https://facebook.github.io/react/">React</a>
<a href="http://riotjs.com/">Riot</a>
<a href="https://angularjs.org/">Angular</a>
<a href="http://www.ractivejs.org/">Ractive</a>
<a href="http://rivetsjs.com/">Rivets</a>
<a href="http://emberjs.com/">Ember</a>
<a href="https://www.polymer-project.org/1.0/">Polymer</a>
<a href="https://x-tag.readme.io/">x-tag</a>
<a href="http://webcomponents.org/">web components</a>
<a href="http://regularjs.github.io/">Regular</a>
<a href="http://google.github.io/incremental-dom/#about">Incremental DOM</a>
<a href="https://github.com/Matt-Esch/virtual-dom">virtual-dom (library)</a>
<a href="https://github.com/blakeembrey/dombars">dombars</a>
</div>
</tbody>
</table>
<script>
// Step 3. Make a javascript model
var myClickApp = {
clicks: 0,
handleClick: function () {
myClickApp.clicks += 1
myView.render() // call render after update
}
}
// Step 4. bind the model to the dom element
var el = document.getElementById("click-app")
var myView = domrender.use(el, myClickApp)
</script>
</body>
</html>
</div>
</div>
</body>
</html>