Browse Source

Merge pull request #103 from csbun/fix/compile-code-get-next-nodes

fix(compile-code): run imove-branch node port condition only once
master
狼叔 4 years ago
committed by GitHub
parent
commit
4a1dbb0cd5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      example/src/pages/index.tsx
  2. 25
      packages/compile-code/src/template/logic.ts

4
example/src/pages/index.tsx

@ -7,8 +7,8 @@ const onSave = (data: { nodes: any; edges: any }): void => {
function Arrange(): JSX.Element {
return (
<div style={{height: '100vh'}}>
<IMove onSave={onSave}/>
<div style={{ height: '100vh' }}>
<IMove onSave={onSave} />
</div>
);
}

25
packages/compile-code/src/template/logic.ts

@ -63,23 +63,30 @@ export default class Logic extends EventEmitter {
_getNextNodes(ctx, curNode, curRet) {
const nodes = [];
for (const edge of this.edges) {
let isMatched = edge.source.cell === curNode.id;
// NOTE: if it is a imove-branch node, each port's condition should be tested whether it is matched
if (curNode.shape === SHAPES.BRANCH) {
let matchedPort = '';
// NOTE: if it is a imove-branch node, find out which port match the curRet condition
const isCurNodeShapeBranch = curNode.shape === SHAPES.BRANCH;
let curNodeMatchedPort = '';
if (isCurNodeShapeBranch) {
const { ports } = curNode.data;
for (const key in ports) {
const { condition } = ports[key];
// eslint-disable-next-line no-new-func
const ret = new Function('ctx', 'return ' + condition)(ctx);
if (ret === Boolean(curRet)) {
matchedPort = key;
break;
curNodeMatchedPort = key;
break; // for (const key in ports)
}
}
isMatched = isMatched && edge.source.port === matchedPort;
}
if (isMatched) {
// NOTE: find out next node via edges which source is curNode
for (const edge of this.edges) {
// edge's source is curNode
const isMatchedSource = edge.source.cell === curNode.id;
// if it is a imove-branch node, edge.source.port match curRet condition
const isMatchedPort = !isCurNodeShapeBranch || edge.source.port === curNodeMatchedPort;
if (isMatchedSource && isMatchedPort) {
// NOTE: not each edge both has source and target
const nextNode = this.nodes.find((item) => item.id === edge.target.cell);
nextNode && nodes.push(nextNode);

Loading…
Cancel
Save