GuillaumeSalles / redux.NET

Redux.NET is a predictable state container for .NET apps. Inspired by https://github.com/reactjs/redux.
713 stars 87 forks source link

[WIP] Awaitable store with async saga support #62

Open cmeeren opened 7 years ago

cmeeren commented 7 years ago

This is a work in progress. Posting here as a PR so we can discuss. Particularly interested in what @dcolthorp has to say. Regarding https://github.com/GuillaumeSalles/redux.NET/issues/47#issuecomment-290694783, this PR provides a way of registering sagas using an action observable AND awaiting the completion of all actions in the store. See unit tests for details.

Due to necessity I branched this off of my previous branch (PR #60), hence why the commit from that PR also shows up in this PR.

I've just lumped all code together in one file for now.

The distinct features in this PR are:

Things to do before this can be merged:

cmeeren commented 7 years ago

@dcolthorp It should be exception safe now. Calling Dispatch (on any store) or await DispatchAsync() (on AwaitableStore) will 1) bubble up the exception, and 2) make sure that the async task count is decremented.

I've added a ton of tests, check them out to see how it's used. Some tests might be unnecessary due to being pretty much being guaranteed by .NET, but much of it was copy-paste and I didn't stop to think too hard on whether all the tests were strictly needed.

cmeeren commented 7 years ago

I've updated the initial comment with more information.

@dcolthorp Regarding https://github.com/GuillaumeSalles/redux.NET/issues/47#issuecomment-290535579 and your mention of TakeLatest: I tried experimenting, but couldn't find a solution that was simpler than simply letting the sagas themselves handle this. I do that already in a few of my listeners.