diff --git a/README.md b/README.md index 66e653e48ce3e0f3dae4cb09e9b49d72ee6e14fb..a8936dd706667bee7ce97c74077e3b8cf72f5422 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,12 @@ ## what it do -... now ... -- modules templates and state management seems ready to work -- want to make sensical pass-back objects: - - core server mod is memory representation - - interfaces strip of state-changing things - - and event particulars - - everytime we update anything, just send a complete representation back and forth, sweep on the other side - - and a top level: this is the thing we load and save from - - somehow links need to live in the module representations ... - -- refactor ui with new everything -- terminal serves terminal input line (client, css) -- input lines comes thru to setter, to output, to gcode +- state variables good, +- should only change in UI on server ack (so need to write our own ui classes) + - doesn't even change on ack at the moment + - let's get to the pnt when we can see a g0 come thru the mode state + +- for attaching inputs / outsput to / from with ui and loading etc / have to hold onto inputs / outputs and connections differently? i.e. can send from ui -> server to conn. id to id. but can't read out of server rep. which ids con. to which ids ## remember diff --git a/client/client.js b/client/client.js index f3e786f5bc2aa2e965b9fda2d106e9355e4df24d..fae2534de0a1466f06fa2c639adfaac4d096ed4b 100644 --- a/client/client.js +++ b/client/client.js @@ -10,7 +10,6 @@ var lastPos = {} // drawing / div-ing var wrapper = {} -var dt = new DT() // div tools // client fns @@ -19,6 +18,7 @@ function socketSend(type, data) { type: type, data: data } + console.log('SEND', msg) sckt.send(JSON.stringify(msg)) } @@ -45,6 +45,7 @@ function socketRecv(evt) { var recv = JSON.parse(evt.data) var type = recv.type var data = recv.data + console.log('RECV', recv) // tree banger switch (type) { case 'console': @@ -112,16 +113,10 @@ function addRep(rep) { // at server: how to do .onChange() ? console.log(rep) for (key in rep.state) { - if (key.indexOf('_') !== 0 & key != 'emitters'){ - // confusion is here - getting only _ values, when send new state - // want to do it w/o these, for - // probably keep things very clear, sending only mod.states, tl.conn and mod.uis back and forth? - // write fn that wraps thos? - var newi = datui.add(rep.state, key) - newi.onFinishChange(function(value){ - putState(rep) - }) - } + var newi = datui.add(rep.state, key) + newi.onFinishChange(function(value){ + putState(rep) + }) } rep.ui.dat = datui stateElem.appendChild(datui.domElement) @@ -178,21 +173,7 @@ function addRep(rep) { // update state from server to UI function changeState(data){ - /* - console.log(data.state) - - var oldState = reps[data.id].state - var newState = data.state - - for (key in newState) { - if (isStateKey(key)) { - if (oldState[key] != newState[key]) { - oldState[key] = newState[key] - console.log('changeState', key, 'to', newState[key], 'in', data.id) - } - } - } - */ + console.log('now would change state in', data.id, 'this', data.state) } function isStateKey(key){ diff --git a/server.js b/server.js index ad59c3a7f51ff2e14fd50815cca5f23b78a7dde2..17631f4a30b1e5067a81bad773d98ab414c5f829 100644 --- a/server.js +++ b/server.js @@ -61,6 +61,7 @@ function socketSend(type, data) { type: type, data: data } + console.log('SEND', msg) sckt.send(JSON.stringify(msg)) } } @@ -69,6 +70,7 @@ function socketRecv(evt) { var recv = JSON.parse(evt) var type = recv.type var data = recv.data + console.log('RECV', recv) // bang thru switch (type) { case 'console': @@ -200,8 +202,27 @@ function putReps() { } function putRep(mod) { - // dump the whole mod, rep'd as json - socketSend('put rep', mod) + // scrape for only things we'll want to represent + var rep = { + id: mod.id, + description: mod.description, + inputs: mod.inputs, + outputs: mod.outputs, + state: {} + } + + // holds UI information - to load mods at location + if(mod.rep != null){ + rep.rep = mod.rep + } + + for(var key in mod.state){ + if(isStateKey(key)){ + rep.state[key] = mod.state[key] + } + } + + socketSend('put rep', rep) } // update state from UI to server @@ -210,18 +231,13 @@ function changeState(data) { // should just recv all state, walk tree for differences var oldState = modules[data.id].state var newState = data.state - console.log('got new state', newState) // rep only holds proper key-values w/o emitters, _values etc - for (key in newState) { + for (var key in newState) { if (isStateKey(key)) { - console.log(key) if (oldState[key] !== newState[key]) { - console.log('changeStatz', key, 'to', newState[key], 'in', data.id) + console.log('CHANGE STATE', key, 'to', newState[key], 'in', data.id) oldState[key] = newState[key] - console.log(oldState) - // deeb bug in here, watch this: - // console.log('changeStatz', key, 'to', newState[key], 'in', data.id) - // has to do with key... going away, changing, after set? wtf is that? + //console.log(oldState) } } } @@ -238,9 +254,16 @@ function isStateKey(key){ // push new state from server to UI function putState(mod) { // push just the state to the individual mod + // copy only the keys we want to see + var state = {} + for (var key in mod.state){ + if(isStateKey(key)){ + state[key] = mod.state[key] + } + } var data = { id: mod.id, - state: mod.state + state: state } socketSend('put state', data) }