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

Flipbook.play() should return a Future<Event> #244

Open
mnordine opened this issue Jun 17, 2016 · 5 comments
Open

Flipbook.play() should return a Future<Event> #244

mnordine opened this issue Jun 17, 2016 · 5 comments

Comments

@mnordine
Copy link
Contributor

current play() returns void. I think it'd be helpful to return a Future<Event> here. It would return _completeEvent.

Then, you could do something like:

await ani.play();

// Do next thing

as opposed to:

ani.addEventListener(Event.COMPLETE, doNextThing);
ani.play();

doNextThing(Event e)
{
  // Do next thing
}
@bp74
Copy link
Owner

bp74 commented Jun 17, 2016

Thanks for the proposal. Getting a future from the play method looks natural.
But there is also a third way to write the code:

ani.play();
await ani.onComplete.first;

The "onComplete" getter returns the Event.Complete stream.
Every stream has a "first" getter to convert the stream in a future.

But still, your proposal is the easiest way to write this code. And it's not a breaking change!

@mnordine
Copy link
Contributor Author

Yep, I was actually already doing this in my code. If we return that future it would make it even more readable.

@bp74
Copy link
Owner

bp74 commented Jun 18, 2016

I did some changes to the FlipBook class, please take a look at the new method playWith:
https://github.com/bp74/StageXL/blob/master/lib/src/display_ex/flip_book.dart#L96

Would be great if you could give it a try!

@mnordine
Copy link
Contributor Author

lgtm. Only gripe you may get is that some people may expect juggler to be named parameter there as well, i.e.

ani.playWith(juggler: stage.juggler);

Personally, I think it's fine the way you have it, and a nice convenience function.

@bp74
Copy link
Owner

bp74 commented Jun 21, 2016

I'm still thinking about the named parameters. This is not only a thing of the Flipbook class but also all over the StageXL code. Have to think about the best way to fix or solve this.

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

No branches or pull requests

2 participants