Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine event handling in android backend (#98) #125

Open
wants to merge 1 commit into
base: flutter
Choose a base branch
from

Conversation

gavv
Copy link
Member

@gavv gavv commented Feb 7, 2025

  • Add 2 new enums: agent.StateEvent and agent.FailureEvent.
    We'll use them instead of string code when emitting events
    from agent to model, to ensure that model won't have an
    implicit dependency on some magic strings.

  • refreshState() generates StateEvent. No matter what even we got
    from kotlin, we always check actual state we have right now and
    generate event according to that state. This way we can be sure
    that events received by model will be consistent with the state
    that it observes when calling receiverIsAlive/senderIsAlive.

  • onError() translates error codes from kotlin to higher-level
    failure event codes. Model translates these error codes to
    localized error messages. UI shows these messages.

- Add 2 new enums: agent.StateEvent and agent.FailureEvent.
  We'll use them instead of string code when emitting events
  from agent to model, to ensure that model won't have an
  implicit dependency on some magic strings.

- refreshState() generates StateEvent. No matter what even we got
  from kotlin, we always check actual state we have right now and
  generate event according to that state. This way we can be sure
  that events received by model will be consistent with the state
  that it observes when calling receiverIsAlive/senderIsAlive.

- onError() translates error codes from kotlin to higher-level
  failure event codes. Model translates these error codes to
  localized error messages. UI shows these messages.
@gavv gavv added ready for review Pull request can be reviewed flutter migration labels Feb 7, 2025
@gavv gavv requested a review from Izchomatik February 7, 2025 13:23
@@ -2,6 +2,18 @@ import 'package:event/event.dart';

import 'android_bridge.g.dart';

/// Event codes for state change events.
enum StateEvent {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are ok with this - I would like to have the event enums as two additional separate files: state_event.dart and failure_event.dart


await refreshState();

switch (errorCode) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a default clause as well (something like an unspecified error or something)

@Izchomatik Izchomatik added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flutter migration needs revision Pull request should be revised by its author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants