Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have nested StateElement? #127

Open
benzsuankularb opened this issue Aug 13, 2018 · 2 comments
Open

Can we have nested StateElement? #127

benzsuankularb opened this issue Aug 13, 2018 · 2 comments

Comments

@benzsuankularb
Copy link

Can we have deep nested of StateElement?

@mattak
Copy link
Owner

mattak commented Sep 20, 2018

@benzsuankularb
Sorry for late response!

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

  • https://github.com/mattak/Unidux/blob/master/Assets/Plugins/Unidux/Scripts/Core/Store.cs#L107
  • 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 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 IStateChanged)
    {
    var changedValue = (IStateChanged) value;
    changedValue.SetStateChanged(false);
    }
    }
    }

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants