Skip to content

Instantly share code, notes, and snippets.

@lmorchard
Created March 7, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmorchard/11e8baaadbf41f5616ed8ac69c18c445 to your computer and use it in GitHub Desktop.
Save lmorchard/11e8baaadbf41f5616ed8ac69c18c445 to your computer and use it in GitHub Desktop.
Hacky loader that waits until initial Redux store changes settle down
const unsubscribeLoader = store.subscribe(() => {
if (selectors.loaderDelayExpired(store.getState())) {
// State settled down long enough for timer to expire - stop listening.
unsubscribeLoader();
} else {
// Reset the timer again.
startLoaderDelay();
}
});
// Utility to (re)start up a timer to dismiss the loading indicator
let loaderTimer = null;
function startLoaderDelay() {
if (loaderTimer) {
clearTimeout(loaderTimer);
}
loaderTimer = setTimeout(
() => store.dispatch(actions.ui.setLoaderDelayExpired(true)),
LOADER_DELAY_PERIOD
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment