handlerLoopBreakpoint.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function loopBreakpoint(block, { prevBlockData }) {
  2. const currentLoop = this.loopList[block.data.loopId];
  3. return new Promise((resolve) => {
  4. let validLoopData = false;
  5. if (currentLoop) {
  6. validLoopData =
  7. currentLoop.type === 'numbers'
  8. ? true
  9. : currentLoop.index <= currentLoop.data.length - 1;
  10. }
  11. if (
  12. currentLoop &&
  13. currentLoop.index < currentLoop.maxLoop - 1 &&
  14. validLoopData
  15. ) {
  16. resolve({
  17. data: '',
  18. nextBlockId: [{ id: currentLoop.blockId }],
  19. });
  20. } else {
  21. if (currentLoop.type === 'elements') {
  22. const loopElsIndex = this.loopEls.findIndex(
  23. ({ blockId }) => blockId === currentLoop.blockId
  24. );
  25. if (loopElsIndex !== -1) this.loopEls.splice(loopElsIndex, 1);
  26. }
  27. delete this.loopList[block.data.loopId];
  28. delete this.engine.referenceData.loopData[block.data.loopId];
  29. resolve({
  30. data: prevBlockData,
  31. nextBlockId: this.getBlockConnections(block.id),
  32. });
  33. }
  34. });
  35. }
  36. export default loopBreakpoint;