mattak / Unidux

Redux Architecture for Unity 🎩
MIT License
385 stars 27 forks source link

Can we have nested StateElement? #127

Open benzsuankularb opened 6 years ago

benzsuankularb commented 6 years ago

Can we have deep nested of StateElement?

mattak commented 6 years ago

@benzsuankularb Sorry for late response!

Now not supporting deepnested StateElement, because Store class cannot reset nested property.

I think it should support nested StateElement. I'll work to fix it on my free time. and of course PR is always welcome!

jsmilovic commented 4 years ago

the store class does not reset properly but the change for this I believe is


        public static void ResetStateChanged(IStateChanged state)
        {
            if (state != null)
            {
                state.SetStateChanged(false);
            }

            var properties = state.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = property.GetValue(state, null);

                if (value != null && value is StateElement)
                {
                    ResetStateChanged((IStateChanged)value);
                }

                if (value != null && value is IStateChanged)
                {
                    var changedValue = (IStateChanged) value;
                    changedValue.SetStateChanged(false);
                }
            }

            var fields = state.GetType().GetFields();

            foreach (var field in fields)
            {
                var value = field.GetValue(state);

                if (value != null && value is StateElement)
                {
                    ResetStateChanged((IStateChanged)value);
                }

                if (value != null && value is IStateChanged)
                {
                    var changedValue = (IStateChanged) value;
                    changedValue.SetStateChanged(false);
                }
            }
        }

How do we file PRs for this project? Is there some sort of system in place? @mattak Are there other changes that need to be in place for this to work?