Exemplo n.º 1
0
 public void ReplaceReducer(Reducer nextReducer)
 {
     Reducer = nextReducer;
     InvokeDispatcher(ReduxAction.ReplaceReducerAction);
 }
Exemplo n.º 2
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();
    }