예제 #1
0
        public virtual async Task <Maybe <ReducerResult <TData> > > Reduce(Maybe <MutatingContext <TData> > state, IStateAction action)
        {
            try
            {
                var typedAction = (TAction)action;

                if (Validator == null)
                {
                    return(await Reduce(state, (TAction)action));
                }
                var result = await Validator.ValidateAsync(typedAction);

                return(!result.IsValid ? ReducerResult.Fail(state, result.Errors.Select(f => f.ErrorMessage)) : await Reduce(state, (TAction)action));
            }
            catch (Exception e)
            {
                return(ReducerResult.Fail(state, new[] { e.Message }));
            }
        }
예제 #2
0
 protected Task <Maybe <ReducerResult <TData> > > FailAsync(Maybe <MutatingContext <TData> > data, IEnumerable <string> errors)
 => Task.FromResult(ReducerResult.Fail(data, errors));
예제 #3
0
 protected Task <Maybe <ReducerResult <TData> > > SucessAsync(Maybe <MutatingContext <TData> > data)
 => Task.FromResult(ReducerResult.Sucess(data));
예제 #4
0
 protected Maybe <ReducerResult <TData> > Fail(Maybe <MutatingContext <TData> > data, IEnumerable <string> errors)
 => ReducerResult.Fail(data, errors);
예제 #5
0
 protected Maybe <ReducerResult <TData> > Sucess(Maybe <MutatingContext <TData> > data)
 => ReducerResult.Sucess(data);