@@ -126,6 +126,9 @@ tornado.ioloop.IOLoop.instance().start()
126
126
Client Side
127
127
-----------
128
128
129
+ note: the syntax ` HTMLElement->(args) ` is a shortcut for common HTML DOM calls,
130
+ it quickly lets you create text-nodes, append multiple elements, or set attributes.
131
+
129
132
130
133
@myapp
131
134
``` rusthon
@@ -152,14 +155,13 @@ def on_message_ws(event):
152
155
else :
153
156
msg = JSON .parse(event.data)
154
157
155
-
156
158
pre = document.getElementById(' RESULTS' )
157
159
if isinstance (msg, list ):
158
160
for res in msg:
159
161
s = JSON .stringify(res)
160
- pre.appendChild( document.createTextNode( s+ ' \n ' ) )
162
+ pre-> ( s+ ' \n ' )
161
163
else :
162
- pre.appendChild( document.createTextNode( msg+ ' \n ' ) )
164
+ pre-> ( msg+ ' \n ' )
163
165
164
166
print msg
165
167
@@ -183,70 +185,68 @@ def main():
183
185
try : connect_ws()
184
186
except : print ' could not connect to websocket'
185
187
186
- with 𝔼 as " document.createElement(%s )" :
187
- with 𝕋 as " document.createTextNode(%s )" :
188
-
189
- con = document.getElementById(' FORM' )
190
- h = 𝔼(' h3' )
191
- h.appendChild(𝕋(' update database:' ))
192
- con.appendChild(h)
193
- keys = (' first name' , ' last name' , ' age' )
194
- fields = {}
195
- for key in keys:
196
- input = 𝔼(' input' )
197
- input .setAttribute(' type' , ' text' )
198
- fields[key] = input
199
- con.appendChild(𝕋(key))
200
- con.appendChild(input )
201
- con.appendChild(𝔼(' br' ))
202
-
203
- button = 𝔼(' button' )
204
- button.appendChild(𝕋(' submit' ))
205
- con.appendChild(button)
206
- @bind (button.onclick)
207
- def onclick ():
208
- ob = {}
209
- for key in fields.keys():
210
- elt = fields[key]
211
- ob[key] = elt.value
212
-
213
- jsondata = JSON .stringify(ob)
214
- ws.send(jsondata)
215
-
216
- searchform = document.getElementById(' SEARCH' )
217
- if searchform is None :
218
- searchform = 𝔼(' div' )
219
- searchform.setAttribute(' id' , ' SEARCH' )
220
- document.body.appendChild(searchform)
221
- h = 𝔼(' h3' )
222
- h.appendChild(𝕋(' search database:' ))
223
- searchform.appendChild( h )
224
-
225
- search_fields = {}
226
- for key in keys:
227
- input = 𝔼(' input' )
228
- input .setAttribute(' type' , ' text' )
229
- search_fields[key] = input
230
- searchform.appendChild(𝕋(key))
231
- searchform.appendChild(input )
232
- searchform.appendChild(𝔼(' br' ))
233
-
234
-
235
- sbutton = 𝔼(' button' )
236
- sbutton.appendChild(𝕋(' search' ))
237
- searchform.appendChild(sbutton)
238
- @bind (sbutton.onclick)
239
- def onsearch ():
240
- s = []
241
- for key in search_fields.keys():
242
- elt = search_fields[key]
243
- # # note ES6 syntax for a computed key name `[key]` ##
244
- o = {
245
- [key] : elt.value
246
- }
247
- s.append( o )
248
- ws.send( JSON .stringify(s) )
249
-
188
+ with 𝕖𝕝𝕥 as " document.createElement(%s )" :
189
+
190
+ con = document.getElementById(' FORM' )
191
+ h = 𝕖𝕝𝕥(' h3' )-> (' Update Database:' )
192
+ con-> (h)
193
+
194
+ keys = (' first name' , ' last name' , ' age' )
195
+ fields = {}
196
+ for key in keys:
197
+ input = 𝕖𝕝𝕥(' input' )-> (type =' text' )
198
+ fields[key] = input
199
+ con-> (
200
+ key,
201
+ input ,
202
+ 𝕖𝕝𝕥(' br' )
203
+ )
204
+
205
+ button = 𝕖𝕝𝕥(' button' )
206
+ button-> (' submit' )
207
+ con-> (button)
208
+
209
+ @bind (button.onclick)
210
+ def onclick ():
211
+ ob = {}
212
+ for key in fields.keys():
213
+ elt = fields[key]
214
+ ob[key] = elt.value
215
+
216
+ jsondata = JSON .stringify(ob)
217
+ ws.send(jsondata)
218
+
219
+ searchform = document.getElementById(' SEARCH' )
220
+ if searchform is None :
221
+ searchform = 𝕖𝕝𝕥(' div' )-> (id =" SEARCH" )
222
+ document.body.appendChild(searchform)
223
+ searchform-> ( 𝕖𝕝𝕥(' h3' )-> (' search database:' ) )
224
+
225
+ search_fields = {}
226
+ for key in keys:
227
+ input = 𝕖𝕝𝕥(' input' )-> (type =' text' )
228
+ search_fields[key] = input
229
+ searchform-> (
230
+ key,
231
+ input ,
232
+ 𝕖𝕝𝕥(' br' )
233
+ )
234
+
235
+
236
+ sbutton = 𝕖𝕝𝕥(' button' )-> (' search' )
237
+ searchform-> (sbutton)
238
+
239
+ @bind (sbutton.onclick)
240
+ def onsearch ():
241
+ s = []
242
+ for key in search_fields.keys():
243
+ elt = search_fields[key]
244
+ # # note ES6 syntax for a computed key name `[key]` ##
245
+ o = {
246
+ [key] : elt.value
247
+ }
248
+ s.append( o )
249
+ ws.send( JSON .stringify(s) )
250
250
251
251
252
252
```
0 commit comments