mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.24k stars 141 forks source link

Be able to have dispatcher throw when no listeners for message? #281

Closed bradtwurst closed 2 years ago

bradtwurst commented 2 years ago

I encountered a situation yesterday which was of my own making.

I had Dispatched a message that was not the same message that I was listening for in the reducer.

I spent quite of bit of time blaming a lot of other things when it was something quite simple.

It would be helpful, especially during the development process, to have the option to have the dispatcher throw an exception when there is no reducer/effect subscribing to that message.

mrpmorris commented 2 years ago

You could write your own middleware to grab the value of every feature in the store before an action is dispatched, and after dispatch throw an exception if object.ReferenceEquals returns true on every new value.

Be aware though, some actions are meant to trigger effects without updating state. Also, StoreInitializedAction doesn't change state.

bradtwurst commented 2 years ago

I could write the middleware to handle that for States, but what about Effects?

How could middleware be written to determine that no effects were called?

If, for example, I unintentionally typed in the incorrect action type in the Effects method definition, the only indication that something is wrong is when the effect doesn't handle the action.

Not that this situation should happen often, but if the library can basically say, "hey, you might have something wrong in your logic" during the development process, it keeps one level of my stupidness away from the code.

Is there anything exposed by Fluxor that I can use to review what effects and reducers are wired up?

mrpmorris commented 2 years ago

You'd write integration tests for that.

Use your app's code to create your ServiceCollection, and then mock out anything that talks to anything external, then assert they were called.