/// <summary>
        /// Constructor for SubTreeToFullTreeAdapter
        /// </summary>
        /// <param name="subTreeReducer">Instance of subtree reducer that needs to adapt.</param>
        public SubTreeToFullTreeAdapter(ISubTreeReducer <TState, TPart> subTreeReducer)
        {
            _subTreeReducer = subTreeReducer;
            var propertySelector = _subTreeReducer.PropertySelector;
            var memberExpr       = propertySelector.Body as MemberExpression ?? throw new ArgumentException(string.Format(
                                                                                                                "Expression '{0}' should be a field.",
                                                                                                                propertySelector.ToString()));
            MemberInfo memberInfo = memberExpr.Member;

            CompileGetterFunction(propertySelector, memberExpr);
            CompileSetterFunction(memberInfo);
            if (_setter is null)
            {
                throw new Exception("TState must provide an Immutable constructor, or public property setter");
            }
        }
示例#2
0
        /// <summary>
        /// Add a reducer that works in part/property (sub-tree) of application's state.
        /// </summary>
        /// <typeparam name="TPart">Type of property in which sub-tree reducer works.</typeparam>
        /// <param name="subTreeReducer">Instance of ISubTreeReducer</param>
        /// <returns>ReducerComposer for fluent-api.</returns>
        public ReducerComposer <TState> AddSubTreeReducer <TPart>(ISubTreeReducer <TState, TPart> subTreeReducer)
        {
            var stateReducer = new SubTreeToFullTreeAdapter <TState, TPart>(subTreeReducer);

            return(AddStateReducer(stateReducer));
        }
示例#3
0
 public TodoMvcReducer AddSubtreeReducer <TPart>(ISubTreeReducer <Todo, TPart> subTreeReducer)
 {
     _subReducers.Add(new SubTreeToFullTreeAdapter <Todo, TPart>(subTreeReducer));
     return(this);
 }