From e925203130a160b995e812093d153fee46f5faae Mon Sep 17 00:00:00 2001
From: Jake <jake.read@cba.mit.edu>
Date: Sun, 25 Nov 2018 20:46:28 -0500
Subject: [PATCH] slowly figuring out how to module-ify bower

---
 client/client.js      |  2 +-
 client/divtools.js    | 41 ++++++++++++++---------------------------
 client/ui/uiButton.js | 15 ++++++++++++++-
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/client/client.js b/client/client.js
index 4d591fd..91d9e42 100644
--- a/client/client.js
+++ b/client/client.js
@@ -516,7 +516,7 @@ document.onkeydown = function(evt) {
 function writeModuleOptionMenu(modRep) {
     var menuDom = document.createElement('div')
     menuDom.id = 'perModuleMenu'
-    menuDom.style.left = 10 + modrep.dom.domElem.offsetLeft + modrep.dom.domElem.offsetWidth + 'px'
+    menuDom.style.left = 10 + modRep.dom.domElem.offsetLeft + modRep.dom.domElem.offsetWidth + 'px'
     menuDom.style.top = modRep.dom.domElem.offsetTop + 'px'
     // future: rm all inputs, rm all outputs, rename, open (heirarchy)
     var opts = ['delete', 'copy']
diff --git a/client/divtools.js b/client/divtools.js
index 81c28db..228bb6d 100644
--- a/client/divtools.js
+++ b/client/divtools.js
@@ -256,42 +256,29 @@ function writeUiElement(container, rep, key) {
     // pull the representation object from what we were sent 
     var ui = rep.ui[key]
     console.log('write ui', ui)
+    console.log('at rep', rep)
+
+    //import script from ui.clientPath 
 
     // load this thing,
+    
     ui.script = document.createElement('script')
+    container.appendChild(ui.script)
+    // it loads and executes when this is set 
+    ui.script.src = ui.clientPath 
+    // events 
+    
     ui.script.onerror = function(err){
         console.log('ERR from ui script', err)
     }
-    ui.script.onload = function(msg){
-        console.log('script loaded ?')
-    }
 
-    container.appendChild(ui.script)
-
-    ui.script.src = ui.clientPath 
-
-
-
-    // make an xhttp request for the code 
-    /*
-    var request = new XMLHttpRequest()
-    request.open('GET', ui.clientPath)
-    request.responseType = 'text/javascript'
-    request.onLoad = function() {
-        console.log(request.response)
+    ui.script.onload = function(msg){
+        console.log('script loaded')
+        // how many of these functions exist ?
+        registerNewModule(rep.description.id, key)
     }
-    request.send()
-    
 
-    fetch(ui.clientPath).then(function(response) {
-        response.text().then(function(text) {
-            console.log(text)
-            console.log(ui)
-            ui.script.appendChild(document.createTextNode(text))
-            container.apppendChild(ui.script)
-        })
-    })
-    */
+    // now we'll hook it up to the socket ?
 
     /*
     // give it access to the socket, 
diff --git a/client/ui/uiButton.js b/client/ui/uiButton.js
index dada8bd..fc8e551 100644
--- a/client/ui/uiButton.js
+++ b/client/ui/uiButton.js
@@ -1 +1,14 @@
-console.log('hello lib load')
\ No newline at end of file
+(function(){
+	socketSend('console', 'loading new iife')
+
+	this.init = function(){
+		socketSend('console', 'hello from' + this.parentId + this.key)
+	}
+
+	// expect this to only be used once
+	window.registerNewModule = function(id, key){
+		this.parentId = id 
+		this.key = key 
+		this.init() 
+	}
+})()
\ No newline at end of file
-- 
GitLab