Odonno / ReduxSimple

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

Project fails when using multiple feature states of the same type #72

Closed IamMartinPeek closed 4 years ago

IamMartinPeek commented 4 years ago

Hey Guys,

you got a cool framework there, but unfortunately it doesn´t work me on Xamarin-App. As soon as I add the Line "Store = new ReduxStore(CreateReducers(), RootState.Initial, false);" to my App.cs, it crashes while creating the Sub-Reducers. Only information i get of exception: System.TypeInitializationException: 'The type initializer for 'MyApp' threw an exception.'

Can you help me ? :)

IamMartinPeek commented 4 years ago

Okay I go the fail now, somehow he didnt like that I had 3 Sub-States from the same type. Can someone explain to me how I can reuse a state-type with the same (Sub-)Reducers for other Substates ?

The error happens when creating the sub-reducers: 'Sequence contains more than one matching element'

Odonno commented 4 years ago

Hi @IamPeek

I am not aware of the issue you're describing. Can you please provide a short reproduction code so that I can fix the issue?

Thank you.

IamMartinPeek commented 4 years ago

The State: image

The Reducers: image

The Selectors: image

Here I want to create Sub-Reducers: image

Thats the error: image

When I delete two of the OrderListStates in the Rootstate it works...

You know what I mean now ? :)

IamMartinPeek commented 4 years ago

Has something to do with the selectors i guess ? :)

Odonno commented 4 years ago

It seems to be, yes. I will add some tests to reproduce your error.

Odonno commented 4 years ago

Good. I can reproduce your error. The error comes from here: https://github.com/Odonno/ReduxSimple/blob/cd8ad984e6897e455b8fd684543edbbe260cd694/ReduxSimple/Reducers.Sub.cs#L81-L82

IamMartinPeek commented 4 years ago

Soooo... you gonna fix it ? :D

Odonno commented 4 years ago

Well, I am trying to figure out a solution. The fact is that .NET reflection isn't helping me much on this. I assumed that each nested state would be of a different type. So that I match the type to know which reducers to apply to the given type.

I did it that way because I did not find a way to do the relation with the property path, ex: RootState.NestedState1. I will check.

Odonno commented 4 years ago

The fastest way for you to fix it would be to create 3 different types for each of your nested state.

Odonno commented 4 years ago

The other way around for me would be to apply the reducers to all nested state that match the type. But then this...

var reducers1 = CreateSubReducers(
  nestedReducers.ToArray(),
  SelectNested1 // THIS !
);

...would have no sense anymore.

I am not sure which way is the best way. I will keep looking at the reflection documentation but from now on, I did not find anything useful.

Odonno commented 4 years ago

@IamPeek Well, after a deep thinking, I come with a really smart solution to deal with this. I'll use the relentless use of references of C# as its advantage. Because with reference objects, I can test the equality of the updated feature state and all the properties of the parent state.

So, it should work all the time.. and if it doesn't (not sure why) well, there will be no failure because we will fallback to the previous state anyway.

I'll ship a new version soon.

Odonno commented 4 years ago

v3.2.0 is now available. Let me know if your project now works like expected.

Thank you for your patience.

IamMartinPeek commented 4 years ago

Hey Mate its working now. Thank your very much :) Using this Framework for a bachelor thesis by the way :)

Odonno commented 4 years ago

Good. What is the subject of your bachelor thesis?