ctrl/validMovesFinder.js
function listenForWorkerResults() {
    chessWorker.addEventListener('message', (event) => {
      const gameId = event.data.reqid.gameRootMessage;
      const { ply } = event.data.reqid;

      if (event.data.topic === 'dests') {
        const destsMapKey = getDestsKey(gameId, ply);
        const awaitingDestsObs = get(awaitingWorkerResponses, destsMapKey);

        if (awaitingDestsObs) {
          const validDests = event.data.payload.dests;
          awaitingDestsObs.set(validDests);
          delete awaitingWorkerResponses[destsMapKey];
        }
      } else if (event.data.topic === 'threefoldTest') {
        const canDrawKey = getDrawKey(gameId, ply);

        const awaitingCanDraw = get(awaitingWorkerResponses, canDrawKey);

        if (awaitingCanDraw) {
          const canClaimDraw = event.data.payload.threefoldRepetition;
          awaitingCanDraw.set(canClaimDraw);
          delete awaitingWorkerResponses[canDrawKey];
        }
      }
    });
  }
function listenForWorkerResults() {
    chessWorker.addEventListener('message', (event) => {
      const gameId = event.data.reqid.gameRootMessage;
      const { ply } = event.data.reqid;

      if (event.data.topic === 'dests') {
        const destsMapKey = getDestsKey(gameId, ply);
        const awaitingDestsObs = get(awaitingWorkerResponses, destsMapKey);

        if (awaitingDestsObs) {
          const validDests = event.data.payload.dests;
          awaitingDestsObs.set(validDests);
          delete awaitingWorkerResponses[destsMapKey];
        }
      } else if (event.data.topic === 'threefoldTest') {
        const canDrawKey = getDrawKey(gameId, ply);

        const awaitingCanDraw = get(awaitingWorkerResponses, canDrawKey);

        if (awaitingCanDraw) {
          const canClaimDraw = event.data.payload.threefoldRepetition;
          awaitingCanDraw.set(canClaimDraw);
          delete awaitingWorkerResponses[canDrawKey];
        }
      }
    });
  }
function listenForWorkerResults ( ) { chessWorker . addEventListener ( 'message' , ( event ) => { const gameId = event . data . reqid . gameRootMessage ; const { ply } = event . data . reqid ; if ( event . data . topic === 'dests' ) { const destsMapKey = getDestsKey ( gameId , ply ) ; const awaitingDestsObs = get ( awaitingWorkerResponses , destsMapKey ) ; if ( awaitingDestsObs ) { const validDests = event . data . payload . dests ; awaitingDestsObs . set ( validDests ) ; delete awaitingWorkerResponses [ destsMapKey ] ; } } else if ( event . data . topic === 'threefoldTest' ) { const canDrawKey = getDrawKey ( gameId , ply ) ; const awaitingCanDraw = get ( awaitingWorkerResponses , canDrawKey ) ; if ( awaitingCanDraw ) { const canClaimDraw = event . data . payload . threefoldRepetition ; awaitingCanDraw . set ( canClaimDraw ) ; delete awaitingWorkerResponses [ canDrawKey ] ; } } } ) ; }
Listens for respones from the chess webworker and updates observables awaiting the response
Listens for respones from the chess webworker and updates observables awaiting the response