ActorDependantBloc<Event extends ActorDependantEvent, State extends Object> constructor

ActorDependantBloc<Event extends ActorDependantEvent, State extends Object>(
  1. State initialState, {
  2. required List<ActorDependencyDefinition<ListenableBloc, dynamic, dynamic, dynamic>> definitions,
})

Implementation

ActorDependantBloc(
  State initialState, {
  required this.definitions,
}) : super(initialState) {
  on<_AutoInitEvent>((event, emit) async {
    for (var definition in definitions) {
      _subscriptions.add(
        definition.bloc.events().listen((event) {
          /// Check if this is a repoService definition and if so, check if we should trigger the handler for current event
          if (definition is ActorRepoServiceDependencyDefinition && definition.groupEvents != null) {
            if (!definition.groupEvents!.contains((event as RepoServiceBlocEvent).group)) {
              return;
            }
          }

          if (isClosed) return;

          add(
            _HandledEvent(
              definition: definition,
              event: event,
            ),
          );

          // definition.handler(event, emit, state);
        }),
      );
    }

    await _completer.future;
  });

  on<_HandledEvent>((event, emit) async {
    await event.definition.handler(event.event, emit, state, (event) {
      if (isClosed) return;
      add(event);
    });
  });

  add(
    const _AutoInitEvent(),
  );
}