handlePatchValueEvent method

  1. @override
  2. @protected
Stream<S> handlePatchValueEvent(
  1. covariant FastCalculatorBlocEventPayload<FastCalculatorResults>? payload
)
override

Handles the patch value event by updating the calculator state and document with the given payload.

Implementation

@override
@protected
Stream<S> handlePatchValueEvent(
  covariant FastCalculatorBlocEventPayload? payload,
) async* {
  final saveUserEntry = await canSaveUserEntry();

  if (!saveUserEntry) {
    yield* super.handlePatchValueEvent(payload);
  } else if (payload != null && payload.key != null) {
    final value = payload.value;
    final key = payload.key!;
    final state = await patchCalculatorState(key, value);

    if (state != null) {
      final newDocument = await patchCalculatorDocument(key, value);

      debugLog(
        'Patching calculator document with key: $key and value: $value',
        debugLabel: debugLabel,
      );

      if (newDocument != null) document = newDocument;

      yield* processCalculatorValueChange(state);
    }
  }
}