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

feat: allow user to choose which event or state change to be captured in the changeStack or not #4178

Open
whowillcare opened this issue May 23, 2024 · 2 comments
Assignees
Labels
pkg:replay_bloc This issue is related to the replay_bloc package question Further information is requested waiting for response Waiting for follow up

Comments

@whowillcare
Copy link

Description

The current solution doesn't have a feature that allow user to specify which events to be added to the changeStack, and which ones are not, which will give user flexiblity to redo or undo specific states changes

Desired Solution

/// allow user to overwrite this method
  bool shouldChangeStack(State current, State next)=>true

@override
  void emit(State state) {
   if (shouldChangeStack(this.state,state)){
     _changeStack.add(
      _Change<State>(
        this.state,
        state,
        () {
          final event = _Redo();
          onEvent(event);
          onTransition(
            Transition(
              currentState: this.state,
              event: event,
              nextState: state,
            ),
          );
          // ignore: invalid_use_of_visible_for_testing_member
          super.emit(state);
        },
        (val) {
          final event = _Undo();
          onEvent(event);
          onTransition(
            Transition(
              currentState: this.state,
              event: event,
              nextState: val,
            ),
          );
          // ignore: invalid_use_of_visible_for_testing_member
          super.emit(val);
        },
      ),
    );
 }
    // ignore: invalid_use_of_visible_for_testing_member
    super.emit(state);
  }

Alternatives Considered

or keep the super.emit to an alternative method name, so the child class can always override the emit method for implementing the similar feature

Additional Context

which will save the resource and allow user to have more flexiblities

@felangel
Copy link
Owner

felangel commented Jun 4, 2024

Hi @whowillcare 👋
Thanks for opening an issue!

Are you able to provide a bit more context around your use-case? ReplayBloc has a shouldReplay API which seems like it might be what you're looking for.

@felangel felangel added question Further information is requested waiting for response Waiting for follow up pkg:replay_bloc This issue is related to the replay_bloc package labels Jun 4, 2024
@felangel felangel self-assigned this Jun 4, 2024
@whowillcare
Copy link
Author

whowillcare commented Jun 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:replay_bloc This issue is related to the replay_bloc package question Further information is requested waiting for response Waiting for follow up
Projects
None yet
Development

No branches or pull requests

2 participants