Пример #1
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);
    }
Пример #2
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);
    }
Пример #3
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();
    }