Open smeijer opened 7 years ago
Editing is fun; but deleting often requires confirmation. I would suggest to show the real power of sagas, and add a deleteTodo saga that takes a user confirmation before deleting anything.
deleteTodo
confirmation
Something like:
try { const { confirmed } = yield race({ confirmed: take(CONFIRM_DELETE_TODO), cancelled: take(CANCEL_DELETE_TODO), }); if (!confirmed) { put ({ type: DELETE_TODO_CANCELLED }); return; } const { data } = yield call(api.delete, { payload }); yield put({ type: DELETE_TODO_SUCCESS, payload: result }); } catch (err) { yield put({ type: DELETE_TODO_ERROR, payload: { error: error.message } }); }
Bonus; race against a timeout to force the user to 'confirm' before x seconds.
x
good idea, I'll add this behavior next time I'll be editing stuff
Editing is fun; but deleting often requires confirmation. I would suggest to show the real power of sagas, and add a
deleteTodo
saga that takes a userconfirmation
before deleting anything.Something like:
Bonus; race against a timeout to force the user to 'confirm' before
x
seconds.