コード例 #1
0
        public override On <TState> CreateParentReducer(On <TFeatureState> on)
        {
            var parentStateProperties = typeof(TState).GetProperties();

            return(new On <TState>
            {
                Reduce = (state, action) =>
                {
                    if (on?.Reduce == null)
                    {
                        return state;
                    }

                    var featureState = _featureSelector(state);
                    var reducerResult = on.Reduce(featureState, action);

                    if (featureState.IsDeepEqual(reducerResult))
                    {
                        return state;
                    }

                    var featureProperty = parentStateProperties
                                          .SingleOrDefault(p =>
                    {
                        return p.GetValue(state) == featureState;
                    });

                    if (featureProperty == null)
                    {
                        throw new NotSupportedException(
                            $"A sub-reducer cannot find the feature reducer of `{typeof(TFeatureState).Name}` inside `{typeof(TState).Name}`."
                            );
                    }

                    var stateCopy = state.Copy();
                    featureProperty.SetValue(stateCopy, reducerResult);

                    return stateCopy;
                },
                Types = on.Types
            });
        }
コード例 #2
0
        public override On <TState> CreateParentReducer(On <TFeatureState> on)
        {
            return(new On <TState>
            {
                Reduce = (state, action) =>
                {
                    if (on?.Reduce == null)
                    {
                        return state;
                    }

                    var featureState = _featureSelector(state);
                    var reducerResult = on.Reduce(featureState, action);

                    if (featureState.IsDeepEqual(reducerResult))
                    {
                        return state;
                    }

                    return _stateReducer(state, reducerResult);
                },
                Types = on.Types
            });
        }
コード例 #3
0
 public abstract On <TState> CreateParentReducer(On <TFeatureState> on);