3// Returns boolean indicating if the swap was successful.
4// Requires that the two signal graphs have exactly the same
6ElmRuntime.swap = function(from, to) {
7 function similar(nodeOld,nodeNew) {
8 var idOkay = nodeOld.id === nodeNew.id;
9 var lengthOkay = nodeOld.kids.length === nodeNew.kids.length;
10 return idOkay && lengthOkay;
12 function swap(nodeOld,nodeNew) {
13 nodeNew.value = nodeOld.value;
16 var canSwap = depthFirstTraversals(similar, from.inputs, to.inputs);
17 if (canSwap) { depthFirstTraversals(swap, from.inputs, to.inputs); }
18 from.node.parentNode.replaceChild(to.node, from.node);
22// Returns false if the node operation f ever fails.
23function depthFirstTraversals(f, queueOld, queueNew) {
24 if (queueOld.length !== queueNew.length) return false;
25 queueOld = queueOld.slice(0);
26 queueNew = queueNew.slice(0);
29 while (queueOld.length > 0 && queueNew.length > 0) {
30 var nodeOld = queueOld.pop();
31 var nodeNew = queueNew.pop();
32 if (seen.indexOf(nodeOld.id) < 0) {
33 if (!f(nodeOld, nodeNew)) return false;
34 queueOld = queueOld.concat(nodeOld.kids);
35 queueNew = queueNew.concat(nodeNew.kids);
36 seen.push(nodeOld.id);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list