diff --git a/hunks/view.js b/hunks/view.js index 036fb517d3731ef9c777e986e9ce7ccb099174f9..921b4cf4fc5ced1e476139cad678d4de629e8b05 100644 --- a/hunks/view.js +++ b/hunks/view.js @@ -1020,6 +1020,22 @@ function View() { /* ------------------------- PIPING -------------------------- */ /* --------------------------- ---------------------------- */ + let relink = (indice) => { + if(defs[indice].type !== 'link') { + return + } + let ldef = defs[indice] + // if we are within some other context, + if(this.within){ + // where this.within is <ptr to linkdef> in another view, + if(ldef.states[1].value == this.within.ind){ + // soul-bond w/ the link, + ldef.upstream = this.within // link -> link, + this.within.downstream = ldef + } + } + } + // return inputdef-to-which connected, // assume always 1d path, bail if not this.trace = (opdef) => { @@ -1028,26 +1044,18 @@ function View() { return opdef.conn[0] } - // for any link in any context, build some route up to - // some view that exists in the browser level - // and return ... ? - this.routelink = (link) => { + // for any link, find / build a route up to a view, from its' 1st input / output - that are assumed to be manager + // message ports to the manager within that link... + this.getLinkContext = (ldef) => { // oof async so nice return new Promise(async (resolve, reject) => { - /* - ok, this thing either (1) finds the view that this link is connected to (write / use a trace fn) - or ! it builds that route, do this - - at the moment, your bug / curiosity is that the post-refresh messages aren't 'fresh' - they're registering - as updates - however, we should be able to assume that a view refresh really wipes the whole thing, - also! you're adding multiple views. add only one view, see if problem persists, continue - -> might have been that you were calling refresh on the new-view, it was messaging the old-view, due - to graph double-up coonnectivity - */ // ok, - let tr = this.trace(link.outputs[1]) + let view + let tr = this.trace(ldef.outputs[1]) if(tr){ if(tr.parent.type == 'view'){ - resolve(tr.parent.hunk) + // keep our ptrs together + view = tr.parent.hunk } else { console.error('need to write case for this, likely that we are link->link here') reject('no link traversing trace yet, pls write') @@ -1055,16 +1063,18 @@ function View() { } else { try { let vdef = await window.tlv.requestAddHunk('view') - // almost definitely the easiest way to handle this is to give our local defs - // a .hunk, this way (1) we know they're local - the view will always be local - - // proceeding, these would be route-builders, - await this.requestAddLink(vdef.outputs[0], link.inputs[1]) - await this.requestAddLink(link.inputs[1], vdef.outputs[0]) - resolve(vdef.hunk) + await this.requestAddLink(vdef.outputs[0], ldef.inputs[1]) + await this.requestAddLink(ldef.inputs[1], vdef.outputs[0]) + view = vdef.hunk // views are always toplevel hunks, so they always have these handles } catch (err) { reject(err) } } + if(view){ + view.within = ldef + ldef.contains = view + resolve(view) + } }) } @@ -1200,6 +1210,8 @@ function View() { if (verbose) console.log('updating hunk at', spec.ind) nd = updateDef(spec) } + // we manage our connectivity to other views, + relink(spec.ind) // set the flag, then call the callback setDefUpdate(spec.ind) // the promise-this callback, @@ -1230,6 +1242,7 @@ function View() { // how we commune -> ui, write ah reset fn if (stDef.reset) stDef.reset() if (cbd) cbd.callback(stDef) + // should we check links here ? } catch { // this is a likely early arrival of a state change update, // meaning we are likely *still* going to rx the def, with the update @@ -1242,8 +1255,9 @@ function View() { let rmid = MSGS.readFrom(msg, inc + 1, 'uint16').item removeDef(rmid) if (cbd) cbd.callback(rmid) + // link check ? break - case MK.LINKALIVE: + case MK.LINKALIVE: // -> wirealive if (msgverbose) console.log('VIEW MSG is a link to put') let nlnk = {} //console.log("LINK MSG IS", msg) @@ -1258,7 +1272,7 @@ function View() { if (cbd) cbd.errback('err for view to putLink') } break - case MK.LINKREMOVED: + case MK.LINKREMOVED: // wireremoved if (msgverbose) console.log('VIEW MSG is a link to cut') let rlnk = {} rlnk.outInd = MSGS.readFrom(msg, inc + 1, 'uint16').item diff --git a/view/blocks.js b/view/blocks.js index ef62937b138e3ba360882abce7b261ae10a702d4..e113cdfbe6b4cce89aac3ecfb962cd528c52e62e 100644 --- a/view/blocks.js +++ b/view/blocks.js @@ -53,17 +53,6 @@ let getBlockStackWidth = (blocks) => { // oboy, let makeLink = (ldef, titleblock) => { // ok, we have a new link, - // if the def's context is within another link, chance we are the reciprocal, check: - if(ldef.context.within){ - // if this link's context is *within* some link-definition, are we the hookup? - if(ldef.states[1].value == ldef.context.within.ind){ - // if this link's 'otherlink' (indice of link-conn-to) value is the same as it's contexts' container's indice, - ldef.upstream = ldef.context.within - ldef.context.within.downstream = ldef - // so, I want to distinguish direction here because I have more or less given up on rendering / working with non-dag graphs, - // for the moment. - } - } if(!ldef.upstream){ let squid = $('<div>').addClass('loosebutton').addClass('block').get(0) squid.position = () => { @@ -74,26 +63,22 @@ let makeLink = (ldef, titleblock) => { ldef.blocks.push(squid) let open = (evt) => { // returns the view that connects to this link, - ldef.context.routelink(ldef).then((view) => { - // the link (def) contains the view (hunk direct) - ldef.contains = view - // the hunk is 'within' the link ... ?? - view.within = ldef + ldef.context.getLinkContext(ldef).then((view) => { // oh lawd - ldef.contains.plane = $('<div>').addClass('subplane').addClass('block').attr('id', `${ldef.name}_plane`).get(0) - ldef.contains.plane.position = () => { + view.plane = $('<div>').addClass('subplane').addClass('block').attr('id', `${ldef.name}_plane`).get(0) + view.plane.position = () => { return { x: 0, y: getBlockStackHeight(ldef.blocks) } } - ldef.contains.plane.handle = ldef // this is a throwaway ... and maybe ah bugfarm - ldef.blocks.push(ldef.contains.plane) - titleblock.take(ldef.contains.plane) - $(window.tlv.plane).append(ldef.contains.plane) - dt.addResizeHandle(ldef.contains.plane) - ldef.contains.plane.onresize = (deltas) => { - let size = dt.readContainerSize(ldef.contains.plane) + view.plane.handle = view // this is a throwaway ... and maybe ah bugfarm + ldef.blocks.push(view.plane) + titleblock.take(view.plane) + $(window.tlv.plane).append(view.plane) + dt.addResizeHandle(view.plane) + view.plane.onresize = (deltas) => { + let size = dt.readContainerSize(view.plane) size.x += deltas.x size.y += deltas.y - dt.writeContainerSize(ldef.contains.plane, size) + dt.writeContainerSize(view.plane, size) repositionDef(ldef) if(ldef.downstream){ repositionDef(ldef.downstream) @@ -114,6 +99,8 @@ let makeLink = (ldef, titleblock) => { }) } let close = (evt) => { + // 'ldef.contains' is a ptr to the context (view) that is w i t h i n the link, accoring + // to our earlier piping, ldef.contains = view returned here wipeContext(ldef.contains) $(ldef.contains.plane).remove() // arduous: rm from ldef, and from titleblock,