diff options
author | David Thompson <dthompson2@worcester.edu> | 2024-07-05 15:04:36 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2024-07-05 15:04:36 -0400 |
commit | be39f9f57fa1ddb5b1d161f1ef9a69bd9cf8630f (patch) | |
tree | a377c080e319e2b3c342497bcdf6417f1a1d1bc8 /chapter-7/propagators.js | |
parent | b33079617253f844db5d7352280504b8f1851483 (diff) |
Propagator improvements and cleanup.
Diffstat (limited to 'chapter-7/propagators.js')
-rw-r--r-- | chapter-7/propagators.js | 78 |
1 files changed, 5 insertions, 73 deletions
diff --git a/chapter-7/propagators.js b/chapter-7/propagators.js index 1477a86..c392ad1 100644 --- a/chapter-7/propagators.js +++ b/chapter-7/propagators.js @@ -3,89 +3,21 @@ window.addEventListener("load", async () => { reflect_wasm_dir: "hoot", user_imports: { window: { - scrollTo: window.scrollTo, - setTimeout: setTimeout, - getWindow: function() { - return window; - }, + setTimeout: setTimeout }, document: { makeTextNode: Document.prototype.createTextNode.bind(document), makeElement: Document.prototype.createElement.bind(document), - getElementById: Document.prototype.getElementById.bind(document), - getBody: function() { - return document.body; - }, + body: () => document.body, }, element: { - firstChild: (elem) => elem.firstChild, - nextSibling: (elem) => elem.nextSibling, - appendChild: function(parent, child) { - return parent.appendChild(child); - }, - setAttribute: function(elem, attr, value) { - return elem.setAttribute(attr, value); - }, - getAttribute: function(elem, attr) { - return elem.getAttribute(attr); - }, - getProperty: function(elem, property, dflt) { - // The little + '' ensures the value is a string - return value = elem[property] + ''; - }, - setProperty: function(elem, property, new_value) { - elem[property] = new_value; - }, + appendChild: (parent, child) => parent.appendChild(child), + setAttribute: (elem, attr, value) => elem.setAttribute(attr, value), getValue: (elem) => elem.value, setValue: (elem, val) => elem.value = val, - remove: function(elem) { - elem.remove(); - }, replaceWith: (oldElem, newElem) => oldElem.replaceWith(newElem), - addEventListener: function(elem, name, f) { - elem.addEventListener(name, f); - }, + addEventListener: (elem, name, f) => elem.addEventListener(name, f) }, - websocket: { - create: function(uri) { - ws = new WebSocket(uri); - return ws; - }, - registerHandler: function(sock, handler, f) { - sock[handler] = function (event) { - if (handler == "onmessage") { - f(event.data); - } else { - f(event); - } - }; - }, - send: function(sock, message) { - sock.send(message); - }, - }, - notification: { - create: function(text) { - return new Notification(text); - }, - permission: function() { - return Notification.permission; - }, - requestPermission: Notification.requestPermission, - }, - promise: { - on: function(promise, f) { - promise.then(f); - }, - }, - localStorage: { - getItem: (key) => localStorage.getItem(key) || "#f", - setItem: (key, value) => localStorage.setItem(key, value) - }, - location: { - protocol: () => location.protocol, - hostname: () => location.hostname - } } }); }); |