Example #1
0
        public static CounterState Reducer(CounterState state, IAction action)
        {
            switch (action)
            {
            case IncrementCounterAction a:
                return(new CounterState(state)
                {
                    Count = (state?.Count ?? 0) + 1
                });

            case DecrementCounterAction a:
                return(new CounterState(state)
                {
                    Count = (state?.Count ?? 0) - 1
                });

            case StartCounterAction a:
                return(new CounterState(state)
                {
                    Started = true
                });

            case StopCounterAction a:
                return(new CounterState(state)
                {
                    Started = false
                });

            case SyncCounterStateAction a:
                return(a.CounterState);

            default:
                return(state);
            }
        }
Example #2
0
 public CounterState(CounterState other)
 {
     if (other == null)
     {
         this.Count   = 0;
         this.Started = false;
     }
     else
     {
         this.Count   = other.Count;
         this.Started = other.Started;
     }
 }