Odonno / ReduxSimple

Simple Stupid Redux Store using Reactive Extensions
http://www.nuget.org/packages/ReduxSimple/
MIT License
144 stars 20 forks source link

Reducers.On support of async #67

Closed wizd closed 4 years ago

wizd commented 4 years ago

How to support async mode for the On method? Actions in my app are mostly async.

On<Action, State>( async (state, action) => { return await ... })

Error CS4010 Cannot convert async lambda expression to delegate type 'Func<State, Action, State>'. An async lambda expression may return void, Task or Task, none of which are convertible to 'Func<State, Action, State>'.

Odonno commented 4 years ago

Hi @wizd

Why would you make async actions? It is not relevant given that reducers should be pure functions and async is not pure. If you want to make async calls, you need to create effects.

I do not have a schema about that right now but I can show the one made by the @ngrx team:

image

You have 2 loops:

I hope it's clear. Feel free to ask question if you need to!

wizd commented 4 years ago

Thank you for the guide. I found it a little hard to migrate legacy code to the redux pattern. ReduxSimple is a great library though the learning curve is quite steep. I like it.

On Sat, Nov 30, 2019 at 4:49 AM David Bottiau notifications@github.com wrote:

Hi @wizd https://github.com/wizd

Why would you make async actions? It is not relevant given that reducers should be pure functions and async is not pure. If you want to make async calls, you need to create effects.

I do not have a schema about that right now but I can show the one made by the @ngrx https://github.com/ngrx team:

[image: image] https://user-images.githubusercontent.com/6053067/69889549-d2b95100-12f1-11ea-9cc2-4a51b37c780b.png

You have 2 loops:

  • pure loop (with state, reducers and selectors, then the state mutates the components)
  • impure loop (effects that listen to actions, and can dispatch new actions to update the state)

I hope it's clear. Feel free to ask question if you need to!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Odonno/ReduxSimple/issues/67?email_source=notifications&email_token=AAVUHV6PR55S75ZCZQAWEF3QWF56VA5CNFSM4JS6TVA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFPRFOI#issuecomment-559878841, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVUHV3T6HFHQV4EM2JHG4TQWF56VANCNFSM4JS6TVAQ .