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 }); }
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 }); }