oreqizer / reactizer-2016

(UNMAINTAINED) The most hipster React and React Native boilerplate! :smiling_imp:
https://reactizer.herokuapp.com
MIT License
73 stars 6 forks source link

Add 'deleteTodo' saga with confirmation yield #18

Open smeijer opened 7 years ago

smeijer commented 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.

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.

oreqizer commented 7 years ago

good idea, I'll add this behavior next time I'll be editing stuff