Exemple #1
0
        static void Main(string[] args)
        {
            var thunkMiddleware     = StandardMiddleware.CreateThunkMiddleware();
            var loggerMiddleware    = StandardMiddleware.CreateStdoutLoggerMiddleware();
            var thunkFirstEnhancer  = Ops.ApplyMiddleware(thunkMiddleware, loggerMiddleware);
            var loggerFirstEnhancer = Ops.ApplyMiddleware(loggerMiddleware, thunkMiddleware);

            CreateTestWithEnhancer("Thunk first", thunkFirstEnhancer);
            CreateTestWithEnhancer("Logger first", loggerFirstEnhancer);

            // You will notice that when thunk middleware is the first parameter of ApplyMiddleware,
            // the messages inside `incrementIfOdd` prints int between the messages in the logger.
            // In other words, logger middleware calls thunk middleware. This happens because the
            // middleware is composed right to left, so the last middleware in the list gets called
            // first, and it in turn calls the other middleware.
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var loggerMiddleware = StandardMiddleware.CreateStdoutLoggerMiddleware();
            var enhancer         = Redux.Ops.ApplyMiddleware(loggerMiddleware);

            // Create the store with preloaded value of 100.
            counterStore = Ops <int> .CreateStore(Counter.Reduce, 100, enhancer);

            Console.WriteLine("Initial state: " + counterStore.State); // 0

            counterStore.Dispatch(Counter.Increment());                // 101
            counterStore.Dispatch(Counter.Decrement());                // 100
            counterStore.Dispatch(Counter.Increment());                // 101
            counterStore.Dispatch(Counter.Increment());                // 102

            // Shouldn't output anything.
            counterStore.Dispatch(new ReduxAction("DUMMY_ACTION"));

            counterStore.Dispatch(Counter.ChangeBy(-3)); //  99
            counterStore.Dispatch(Counter.ChangeBy(5));  // 104

            Console.ReadKey();
        }