bloc icon indicating copy to clipboard operation
bloc copied to clipboard

feat: dryRedo on replay_bloc

Open bernaferrari opened this issue 2 years ago • 1 comments

I love bloc and cubit, but I'm fighting with a few limitations.

Imagine Cubit as the Navigation stack (back/forward button, etc). I wish I could do this:

  • I am on screen A, move to screen B, go back to A. Move B to the trash. I can't "redo" to go to B because B is on the trash, so I would need to check like trash.contains(dryRedo()). I don't want to redo. I want to know if I can redo based on redo value without removing it from its stack.
  • Browser back-stack. You might want to see a preview of the previous/next page. Maybe even the full back history, in a list. The following image is not possible with cubit: image

Possible Desired Solutions

  • Something like dryRedo() / dryUndo() (maybe a better name?), that gets the value, but doesn't remove from the history.
  • Making history and current index not private. So the user could do history.range(index, history.length) and get the forward redo history.
  • Make List<T> undoValues(int? limit) and List<T> redoValues(int? limit), so redoValues(1).first would do what I want.

The last one is slightly more verbose but seems better. I also like the second one. If it were public inside the bloc, at least, I would be able to fix myself. Maybe with tuples it could be (int, ?) getHistoryIndex.

bernaferrari avatar Sep 19 '22 17:09 bernaferrari

Hello, I'm currently coding a note-taking app where this functionality will also be useful. The range function could be implemented using the take function: https://api.dart.dev/stable/3.0.0/dart-core/Iterable/take.html. But currently, emit doesn't know on which event it was called: https://github.com/felangel/bloc/blob/master/packages/replay_bloc/lib/src/replay_cubit.dart#L67 Without this information, you couldn't add an undo history of a column like Adding stroke or something else.

CodeDoctorDE avatar Sep 17 '23 16:09 CodeDoctorDE