quran/quran.com-frontend-next

Batch consecutive dispatches

Aberta

#738 aberto em 11 de nov. de 2021

 (0 comentário) (2 reações) (0 responsável)TypeScript (616 forks)auto 404
help wanted

Métricas do repositório

Stars
 (1.888 estrelas)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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.

Guia do colaborador