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. 37
      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 { function Arrange(): JSX.Element {
return ( return (
<div style={{height: '100vh'}}> <div style={{ height: '100vh' }}>
<IMove onSave={onSave}/> <IMove onSave={onSave} />
</div> </div>
); );
} }

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

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

Loading…
Cancel
Save