Exemple #1
0
 /// <summary>
 /// Adds state to the store
 /// </summary>
 /// <returns>Store that inludes passed state and reducer</returns>
 /// <param name="initialState">Initial state value</param>
 /// <param name="reducer">Reducer function</param>
 /// <typeparam name="TState">State type</typeparam>
 public new Store WithState <TState>(TState initialState, Func <TState, Action, TState> reducer)
 {
     return(TryCreateStore(() => WithState(
                               new StoreItem <TState>(
                                   StateWrapper.ForObject(() => initialState),
                                   reducer)
                               )
                           ));
 }
Exemple #2
0
 /// <summary>
 /// Adds state to the store.
 /// </summary>
 /// <returns>Store that inludes passed state and reducer</returns>
 /// <param name="initialState">Initial state value</param>
 /// <param name="reducer">Reducer for the state</param>
 /// <typeparam name="TState">State type</typeparam>
 public new Store WithState <TState, TReducer>(TState initialState, TReducer reducer) where TReducer : Reducer <TState>
 {
     return(TryCreateStore(() => WithState(
                               new StoreItem(
                                   StateWrapper.ForObject(() => initialState),
                                   ReducerWrapper.ForObject <TState, TReducer>(reducer))
                               )
                           ));
 }
Exemple #3
0
        internal static StateWrapper ForObject <T>(Func <T> func)
        {
            var result = new StateWrapper();

            Type type = typeof(T);

            if (!type.IsValueType)
            {
                throw new InvalidStateTypeException($"'{type.FullName}' cannot have reference type. Should have 'struct' type");
            }

            result.Original         = func();
            result.OriginalTypeName = type.FullName;

            if (!_gettersCache.ContainsKey(result.OriginalTypeName))
            {
                _gettersCache.Add(result.OriginalTypeName, new Dictionary <string, Func <object, object> >());
                result.BuildGetters(type, result.OriginalTypeName);
            }

            return(result);
        }
Exemple #4
0
 protected StoreItem(StateWrapper state)
 {
     State = state;
 }
Exemple #5
0
 internal StoreItem(StateWrapper state, ReducerWrapper reducer) : this(state)
 {
     Reducer = reducer;
 }