ncuillery / sample_bloc_migration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sample_bloc_migration

Sample project to illustrate a difficulty to migrate to Bloc 8.x.x when using a transformEvents method that emit events of different types (in 8.x.x this method is replaced by an event-level transformation API, whereas transformEvents operates at the global level).

The use-case demo-ed here is a debounced suggestion box with a special attention to the pending state:

  • The suggestion box enters in its pending state as soon as the first key is pressed (we don't wait for the debounce duration because the debounce duration is a "perceived waiting time" from the user perspective)
  • When the suggestion box doesn't contain enough characters, we clear the suggestions immediately without waiting for the debouced duration (no pending state because nothing happens)

EDIT

I finally managed to migrate to Bloc 8.x.x by introducing a new event: TypeSuggestionEvent.

This event is added for each character typed in the search field. If the request is valid, the pending state is emitted, otherwise we clear the suggestions immediately (empty state emitted)

In both case we emit the debounced FetchSuggestionEvent which also verify if the query is valid before requesting the API. If we don't, when when the query becomes invalid (by typing back the characters with Backspace), there is a FetchSuggestionEvent fired for the last valid query and we don't want that to happen. By emitting the FetchSuggestionEvent even if the query is invalid, we replace this undesirable event by a new one that does nothing.

About


Languages

Language:C++ 37.6%Language:Dart 32.8%Language:CMake 17.8%Language:HTML 8.8%Language:C 1.6%Language:Swift 0.9%Language:Kotlin 0.3%Language:Objective-C 0.1%