diff --git a/view/vptch.js b/view/vptch.js index 73f5e36f9a8661b28e77a4c5e9067b206fe9a1a2..da4dfc8571b5201628a1967239ed3f299a84c21b 100644 --- a/view/vptch.js +++ b/view/vptch.js @@ -111,128 +111,6 @@ function PatchSet(View) { return patch } // end writeCurrent - let mergeHunkList = (patch, debug) => { - return new Promise((resolve, reject) => { - let loadedDefsList = [] - // num to load, - let ns = patch.hunks.length - // ok, a promise walker, n is hunk[i] - let pld = async (n) => { - // what we want, - let spec = patch.hunks[n] - let existing = view.defs[n] - if (debug) console.log(`PATCH ${view.interpreterName}: hunkmerge, at ${n}`) - if (debug) { - console.log('view shows:', view.defs[n]) - console.log('patch wants:', patch.hunks[n]) - } - // if we have one, - if (existing !== undefined) { - // it's a merge, this is only cool if it's the same type, - // then we can mupdate state - if (existing.type !== spec.type) { - reject(`exiting patch merge at ${n} hunk, dissimilar types`) - } else { - // check state, - for (let st in existing.states) { - if (debug) console.log(`state change: st`, spec.states[st]) - // check if each exists, tho - if (spec.states[st]) { - if (existing.states[st].value === spec.states[st].value) { - if (debug) console.log('continue') - continue - } else { - // oh boy - if (debug)console.log(`${n} UPPER BOUND STATECHANGE CALL`) - try { - if (debug)if (true) console.log(`STCHNG: PATCH ${view.interpreterName}: req change for state: ${existing.states[st].name}`) - await view.requestStateChange(existing.states[st], spec.states[st].value) - } catch (err) { - reject(`error in requesting state change during patch merge ${err}`) - } - if (debug)console.log(`${n} LOWER BOUND STATECHANGE CALL`) - } - } // state doesn't exist, - } // end for-existing-states - } - } else { - // not existing, so just a straightforward add - try { - if (debug) console.log(`PATCH ${view.interpreterName}: req add new hunk of type ${spec.type} and name ${spec.name}`) - await view.requestAddHunk(spec.type, spec.name, spec.states).then((def) => { - loadedDefsList.push(def) - }) - } catch (err) { - reject(`error in requesting new hunk during patch merge ${err}`) - } - // ... .then(() => { pld(n++) }).catch((errmsg) => { reject(`exiting patch merge at ${n} hunk, err...`)}) - } // - // done w/ states, - if ((n++) < (ns - 1)) { - pld(n++) - } else { - // done w/ n - resolve(loadedDefsList) - } - } // end async pld, - // kickoff, - pld(0) - }) - } // end mergeHunkList - - let mergeLinkList = async (patch, debug) => { - return new Promise((resolve, reject) => { - // I think I'm still a bit off on the ideal syntax for these, but - let ns = patch.hunks.length - // the bumptool - let lnkLoader = async (n) => { - //console.log('lnkLoader', n) - for (let op in patch.hunks[n].outputs) { - if (patch.hunks[n].outputs[op].connections) { - for (let cn of patch.hunks[n].outputs[op].connections) { - let opHunkIndex = n - let opIndex = op - let inHunkIndex = cn.inHunkIndex - let inIndex = cn.inHunkInput - // the output, the input - let opDef = view.defs[opHunkIndex].outputs[opIndex] - let ipDef = view.defs[inHunkIndex].inputs[inIndex] - // these should exist, if not ... - if (opDef === undefined) { - reject("output doesn't exist for this link request") - } - if (ipDef === undefined) { - reject("input doesn't exist for this link request") - } - // check if we can find this already existing, - let existing = opDef.connections.find((cand) => { - // candidate would be an inputdef, - return cand === ipDef - }) - if (!existing) { - try { - //console.log('add conn from', opHunkIndex, opIndex, inHunkIndex, inIndex) - // TODO: sometimes hunks change, and inputs go away ... we need to catch those errs here - await view.requestAddLink(opDef, ipDef) - } catch (err) { - reject(err) - } - } else { - //console.log('exists:', opHunkIndex, opIndex, inHunkIndex, inIndex) - } - } - } // end if-has-connections - } // end for-each-output - if ((n++) < (ns - 1)) { - lnkLoader(n++) - } else { - resolve(`loaded ${n} links`) - } - } // fin lnkloader - lnkLoader(0) - }) - } - this.getPatch = (name) => { return gg.getJson('/save/contexts/' + view.interpreterName + '/' + name + '.json') }