示例#1
0
        public void Setup()
        {
            reduxSharpStore = new ReduxSharp.Store <AppState>(
                new AppReducer(),
                new AppState());

            reduxDotNetStore = new Redux.Store <AppState>(
                AppReducer.Reduce,
                new AppState());
        }
示例#2
0
        public void Setup()
        {
            reduxSharpStore = new ReduxSharp.Store <AppState>(
                new AppReducer(),
                new AppState(),
                new EmptyMiddleware <AppState>());

            reduxDotNetStore = new Redux.Store <AppState>(
                AppReducer.Reduce,
                new AppState(),
                EmptyMiddleware <AppState> .ApplyMiddleware);
        }
示例#3
0
    // Use this for initialization
    void Start()
    {
        var enhancer = Redux.composeEnhancer(new Redux.Enhancer[] {
            Redux.applyMiddleware(new Redux.Middleware[] {
                ReduxMiddleware.createLogger,
                ReduxMiddleware.createCrashReport
            }),
            Redux.Devtools.instrument(this.onChangeMonitoredState)
        });

        this.store = Redux.createStore(TodoList.reducer, null, enhancer);
        this.store.subscribe(this.onChangeState);
        this.onChangeState(this.store);
    }
示例#4
0
        public static void Main(string[] args)
        {
            var myStore = new Redux.Store <CounterState, CounterAction, CounterReducer>(new CounterState(0), new CounterReducer());

            Console.WriteLine("State: {0}", myStore.GetState().Value);

            var state = myStore.GetState();

            myStore.Dispatch(new CounterAction.Increment());
            myStore.Dispatch(new CounterAction.Increment());

            Console.WriteLine("State: {0} (look it's immutable!)", state.Value);
            Console.WriteLine("State: {0}", myStore.GetState().Value);
        }
示例#5
0
    // Use this for initialization
    void Start()
    {
        var finalReducer = Redux.combineReducers(new Redux.Reducer[] {
            Reducers.todos,
            Reducers.visibilityFilter
        });

        var enhancer = Redux.composeEnhancer(new Redux.Enhancer[] {
            Redux.applyMiddleware(new Redux.Middleware[] {
                ReduxMiddleware.createLogger,
                ReduxMiddleware.createCrashReport
            }),
            Redux.Devtools.instrument(this.onChangeMonitoredState)
        });

        this.store = Redux.createStore(finalReducer, null, enhancer);
        this.store.subscribe(this.onChangeState);
        this.onChangeState(this.store);
    }
示例#6
0
 void onChangeState(Redux.Store store)
 {
     this.todos            = (Item[])store.getState(Reducers.todos);
     this.visibilityFilter = (string)store.getState(Reducers.visibilityFilter);
 }
示例#7
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("----------- Add reducers");

        var reducers = new Redux.Reducer[] {
            Reducers.sumResult,
            Reducers.multiplyResult
        };

//		var type = typeof (Reducers);
//		var methods = type.GetMethods (
//			System.Reflection.BindingFlags.NonPublic |
//			System.Reflection.BindingFlags.Public |
//			System.Reflection.BindingFlags.Static |
//			System.Reflection.BindingFlags.FlattenHierarchy);
//
//		var reducers = new List<Redux.Reducer> ();
//		foreach (var method in methods) {
//			if (method.DeclaringType.FullName == type.FullName) {
//				//reducers
//				Expression.Lambda<Redux.Reducer> (
//					Expression.Call (Expression.Convert (input, o.GetType ()), method), input).Compile ();
//			}
//		}

        this.store = Redux.createStore(
            Redux.combineReducers(reducers),
            null,
            Redux.applyMiddleware(new Redux.Middleware[] {
            ReduxMiddleware.createThunk,
            ReduxMiddleware.createLogger,
            ReduxMiddleware.createCrashReport
        })
            );

        Debug.Log("----------- Subscribe");

        var unsubscribe = this.store.subscribe(this.onChangeState);

        {
            Debug.Log("----------- Dispatch");

            this.store.dispatch(ActionCreators.sum(10, 20));
            this.store.dispatch(ActionCreators.multiply(10, 20));

            Debug.Log("----------- Remove reducers");

            Redux.removeReducers(new Redux.Reducer[] {
                Reducers.multiplyResult
            });

            Debug.Log("----------- Dispatch");

            try {
                this.store.dispatch(ActionCreators.sum(100, 200));
                this.store.dispatch(ActionCreators.multiply(100, 200));
            } catch (Redux.Error e) {
                Debug.LogError(e.Message);
            }
        }

        Debug.Log("----------- Unsubscribe");

        unsubscribe();
    }
示例#8
0
 void onChangeState(Redux.Store store)
 {
     Debug.Log("sum: " + store.getState(Reducers.sumResult));
     Debug.Log("multiply: " + store.getState(Reducers.multiplyResult));
 }