quran/quran.com-frontend-next

Batch consecutive dispatches

Aperta

#738 aperta il 11 nov 2021

 (0 commenti) (2 reazioni) (0 assegnatari)TypeScript (616 fork)auto 404
help wanted

Metriche repository

Star
 (1888 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Redux strongly recommends avoiding dispatching many actions in a row but our codebase contains multiple places that has consecutive dispatches for example:

const onPlayClick = () => {
    dispatch(setRepeatSettings(verseRepetition));
    dispatch(
      playFrom({
        chapterId: Number(chapterId),
        reciterId: reciter.id,
        verseKey: verseRepetition.from,
      }),
    );
    onClose();
  };

or

if (newYPosition > 50 && direction === ScrollDirection.Down) {
        dispatch({ type: setIsMobileMinimizedForScrolling.type, payload: true });
        dispatch({ type: setIsExpanded.type, payload: false });
        dispatch({ type: setIsVisible.type, payload: false });
      } else if (newYPosition >= 0 && direction === ScrollDirection.Up) {
        dispatch({ type: setIsMobileMinimizedForScrolling.type, payload: false });
        dispatch({ type: setIsExpanded.type, payload: true });
        dispatch({ type: setIsVisible.type, payload: true });
      }

We need to find a better way to handle those cases as this affects performance.

Guida contributor