public override ExampleState <int> Reduce(ExampleState <int> state, ExampleAction action)
        {
            var nextState = new ExampleState <int>();

            nextState.Value = state.Value;

            switch (action.Type)
            {
            case "Add":
                nextState.Value += action.Data;
                return(nextState);

            default:
                return(nextState);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var initialState = new ExampleState <int>();
            var store        = new Store <ExampleState <int>, ExampleAction>(initialState, new ExampleReducer());

            store.Subscribe((state) =>
            {
                Console.WriteLine("Total is");
                Console.WriteLine(state.Value);
            });

            while (true)
            {
                Console.WriteLine("Input integer");
                var input = Convert.ToInt32(Console.ReadLine());

                var action = new ExampleAction();

                action.Type = "Add";
                action.Data = input;

                store.Dispatch(action);
            }
        }