From be39f9f57fa1ddb5b1d161f1ef9a69bd9cf8630f Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 5 Jul 2024 15:04:36 -0400 Subject: Propagator improvements and cleanup. --- chapter-7/propagators.js | 78 ++++-------------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) (limited to 'chapter-7/propagators.js') 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 - } } }); }); -- cgit v1.2.3