mirror of
https://github.com/xodio/xod.git
synced 2026-02-20 02:01:20 +01:00
Merge pull request #2023 from xodio/fix-flatten-for-unbound-custom-type
Fix bug in flattening when uppermost custom type terminal has no input links
This commit is contained in:
@@ -654,6 +654,9 @@ const traverseUpAndCollectTerminalChain = R.curry(
|
||||
R.compose(R.equals(nextNodeId), Link.getLinkInputNodeId),
|
||||
links
|
||||
);
|
||||
// If the uppermost node has no input link — return collected data
|
||||
if (!nextLink) return collected;
|
||||
|
||||
return R.compose(
|
||||
traverseUpAndCollectTerminalChain(terminalNodeIds, links),
|
||||
R.over(R.lensIndex(0), R.append(nextNodeId)),
|
||||
|
||||
@@ -554,6 +554,117 @@
|
||||
"type": "xod/patch-nodes/input-byte"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@/test-wrapped-i2c": {
|
||||
"nodes": {
|
||||
"wrapped-i2c-node": {
|
||||
"id": "wrapped-i2c-node",
|
||||
"position": {
|
||||
"x": -2,
|
||||
"y": -1,
|
||||
"units": "slots"
|
||||
},
|
||||
"type": "@/wrapped-i2c"
|
||||
}
|
||||
},
|
||||
"path": "@/main"
|
||||
},
|
||||
"@/wrapped-i2c": {
|
||||
"links": {
|
||||
"terminal-to-node": {
|
||||
"id": "terminal-to-node",
|
||||
"input": {
|
||||
"nodeId": "test-node",
|
||||
"pinKey": "input-i2c"
|
||||
},
|
||||
"output": {
|
||||
"nodeId": "input-i2c-terminal",
|
||||
"pinKey": "__out__"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nodes": {
|
||||
"test-node": {
|
||||
"id": "test-node",
|
||||
"position": {
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"units": "slots"
|
||||
},
|
||||
"type": "xod/i2c/test"
|
||||
},
|
||||
"input-i2c-terminal": {
|
||||
"id": "input-i2c-terminal",
|
||||
"label": "I2C",
|
||||
"position": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"units": "slots"
|
||||
},
|
||||
"type": "xod/i2c/input-i2c"
|
||||
}
|
||||
},
|
||||
"path": "@/wrapped-i2c"
|
||||
},
|
||||
"xod/i2c/i2c": {
|
||||
"attachments": [
|
||||
{
|
||||
"filename": "patch.cpp",
|
||||
"encoding": "utf-8",
|
||||
"content": "// implementation"
|
||||
}
|
||||
],
|
||||
"nodes": {
|
||||
"output-self": {
|
||||
"id": "output-self",
|
||||
"position": {
|
||||
"units": "slots",
|
||||
"x": 2,
|
||||
"y": 2
|
||||
},
|
||||
"type": "xod/patch-nodes/output-self"
|
||||
},
|
||||
"niix": {
|
||||
"id": "niix",
|
||||
"position": {
|
||||
"units": "slots",
|
||||
"x": 2,
|
||||
"y": 1
|
||||
},
|
||||
"type": "xod/patch-nodes/not-implemented-in-xod"
|
||||
}
|
||||
},
|
||||
"path": "xod/i2c/i2c"
|
||||
},
|
||||
"xod/i2c/test": {
|
||||
"attachments": [
|
||||
{
|
||||
"filename": "patch.cpp",
|
||||
"encoding": "utf-8",
|
||||
"content": "// implementation"
|
||||
}
|
||||
],
|
||||
"nodes": {
|
||||
"input-i2c": {
|
||||
"id": "input-i2c",
|
||||
"position": {
|
||||
"units": "slots",
|
||||
"x": 2,
|
||||
"y": 2
|
||||
},
|
||||
"type": "xod/i2c/input-i2c"
|
||||
},
|
||||
"niix": {
|
||||
"id": "niix",
|
||||
"position": {
|
||||
"units": "slots",
|
||||
"x": 2,
|
||||
"y": 1
|
||||
},
|
||||
"type": "xod/patch-nodes/not-implemented-in-xod"
|
||||
}
|
||||
},
|
||||
"path": "xod/i2c/test"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1359,6 +1359,25 @@ describe('Flatten', () => {
|
||||
'color-nested~nested-again~hsl-node-to-watch-node-pin-input-string'
|
||||
));
|
||||
|
||||
it('should not create a cast node for a custom type if it not needed', () => {
|
||||
const flatProject = flatten(project, '@/test-wrapped-i2c');
|
||||
Helper.expectEitherRight(newProject => {
|
||||
const nodeIds = R.compose(
|
||||
R.map(Node.getNodeId),
|
||||
Patch.listNodes,
|
||||
Project.getPatchByPathUnsafe('@/test-wrapped-i2c')
|
||||
)(newProject);
|
||||
|
||||
const links = R.compose(
|
||||
Patch.listLinks,
|
||||
Project.getPatchByPathUnsafe('@/test-wrapped-i2c')
|
||||
)(newProject);
|
||||
|
||||
assert.sameMembers(['wrapped-i2c-node~test-node'], nodeIds);
|
||||
assert.isEmpty(links);
|
||||
}, flatProject);
|
||||
});
|
||||
|
||||
it('should return Either.Left if custom type does not have a cast node', () => {
|
||||
const flatProject = flatten(project, '@/test-no-cast-node');
|
||||
Helper.expectEitherError(
|
||||
|
||||
Reference in New Issue
Block a user