mapEventToState method

  1. @override
Stream<FastAppDictBlocState> mapEventToState(
  1. FastAppDictBlocEvent event
)
override

Must be implemented when a class extends BidirectionalBloc. mapEventToState is called whenever an event is added and will convert that event into a new BloC state. It can yield zero, one or several states for an event.

Implementation

@override
Stream<FastAppDictBlocState> mapEventToState(
  FastAppDictBlocEvent event,
) async* {
  final payload = event.payload;
  final type = event.type;

  _logger.debug('Event received: $type');

  if (type == FastAppDictBlocEventType.init) {
    yield* handleInitEvent();
  } else if (type == FastAppDictBlocEventType.initialized) {
    if (payload is List<FastDictEntryEntity>) {
      yield* handleInitializedEvent(payload);
    }
  } else if (isInitialized) {
    switch (type) {
      case FastAppDictBlocEventType.retrieveEntries:
        yield* handleRetrieveEntriesEvent();
      case FastAppDictBlocEventType.entriesRetrieved:
        if (payload is List<FastDictEntryEntity>) {
          yield* handleEntriesRetrievedEvent(payload);
        }
      case FastAppDictBlocEventType.deleteEntries:
        yield* handleDeleteEntriesEvent(payload);

      case FastAppDictBlocEventType.patchEnties:
        if (payload is List<FastDictEntryEntity>) {
          yield* handlePatchEntriesEvent(payload);
        }

      default:
        break;
    }
  } else {
    assert(false, 'FastAppDictBloc is not initialized yet.');
  }
}