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

Question: Get notice when command is executed #35

Closed
AlexBacich opened this issue Dec 29, 2019 · 8 comments
Closed

Question: Get notice when command is executed #35

AlexBacich opened this issue Dec 29, 2019 · 8 comments

Comments

@AlexBacich
Copy link
Contributor

RefreshIndicator widget requires parameter Future in order to function (finish circling value received).

I'm wondering if there is a way to make RxCommand friend with RefreshIndicator.

Problem is that once I call execute() for my command I get void result.

What I want to do is call command and return Future with null emitted once command finishes with data or error.

@escamoteur
Copy link
Collaborator

what about using isExecuting.where(x=>0==false).take(1)? do that in a getter so that it is executed everytime?

@AlexBacich
Copy link
Contributor Author

Hi @escamoteur , thanks for the answer. Here's solution I've came up so far. I'm sure it can be optimized but don't yet no ideas

Future<void> getHistory() async {
      getHistoryCommand.execute();
      return getHistoryCommand.isExecuting.where((b) => b == false).take(2).last;
    }

Even if I add delay after getHistoryCommand.execute() it still fires isExecuting = false first. So I have to put take(2) instead of take(1)

@escamoteur
Copy link
Collaborator

Ah, that is interesting. Not sure if I should count this as an error.
May I propose:

getHistoryCommand.isExecuting.distinctUnique.where((b) => b == false).take(1).last

Then it won't break in case I deide to remove the initial emitting of false.

Great that this works for you.

@AlexBacich
Copy link
Contributor Author

AlexBacich commented Dec 31, 2019

I guess supposed behavior is to emit initially false only if command isn't executing.
Anyway, what you are proposing is excellent idea.
If I'm not the only one who needs this maybe helper function will be nice to have. Like

Future<TResult> executeAsFuture([param])  {
     this.execute([param]);
    return this.isExecuting.distinctUnique.where((b) => b == false).take(1).last;
}

Will do in my project as extension anyway.

@escamoteur
Copy link
Collaborator

Good idea!

@AlexBacich
Copy link
Contributor Author

Hey @escamoteur , just another observation in regards of commands flow.

If I run command BEFORE widget if built for the first time - there are problems with creating RxLoader.
Basically it never receives state 'isExecuting = true' so not showing loader. Only after command is finished it receives first state.

As a workaround solution - command should be launched in init state after widget is built once. Like this:
WidgetsBinding.instance.addPostFrameCallback((_) => bloc.initialCommand());

Guess there's nothing to do here since moving all streams to behavior subjects would be an overkill. Or not?

@escamoteur
Copy link
Collaborator

Did you set the parameter emitsLastValueToNewSubscriptions to true? Then the Streams are BehaviourSubjects

@AlexBacich
Copy link
Contributor Author

ah, you already did it ) It works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants