Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Last active March 24, 2018 14:53
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 hedgerh/64a98583bd3a3edde8853c45ee9f1e5b to your computer and use it in GitHub Desktop.
Save hedgerh/64a98583bd3a3edde8853c45ee9f1e5b to your computer and use it in GitHub Desktop.
function* countdown() {
yield call(delay, toMilliseconds(480));
yield put(showLogoutWarning());
yield call(delay, toMilliseconds(120));
yield put(logout());
}
function* watchForActivity() {
while (true) {
yield takeLatest(action => action.type !== ' SHOW_LOGOUT_WARNING', countdown);
}
}
function* watchNavigation() {
while(true) {
let task;
const action = yield take(['NAVIGATE', 'LOGOUT']);
if (task) {
yield cancel(task);
}
if (action.type === 'NAVIGATE' && isSensitiveRoute(action.url)) {
task = yield fork(watchForActivity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment