No announcement yet.

Redux Bindings

  • Filter
  • Time
  • Show
Clear All
new posts

    Redux Bindings

    Hi, just published the Bridge.Redux bindings library to github. I tried as much possible to give it a csharp-ish look and feel. In the example app it is demonstrated how to use it and it should be straight-forward for the ones who are familiar with Redux. Thunk middleware is included. However, I still did not publish a Nuget package of it as I am not sure if it is complete and whether the design is sound. Feel free to hack around and give suggestions. Also, for the ones who are really interested, I opened an issue on the Bridge.React library to try to get these two libraries work together somehow. Any suggestions would be appreciated.

    "Show me the code!"... you got it :)
    Here is an example of a simple counter reducer, looks pretty much like its javascript equivalen tbut with types, an intwould have worked fine but I chose for a complex type example
    public static Reducer<Counter> CounterReducer()
        return Reducer<Counter>.Create<SimpleAction>((state, action) =>
            if (state.IsUndefined())
                return new Counter { Value = 0 };
            if (action.Type == ActionTypes.Increment)
                return new Counter { Value = state.Value + 1 };
            if (action.Type == ActionTypes.Decrement)
                return new Counter { Value = state.Value - 1 };
            return state;
    And here is an "App", keep in mind that Reducer<T> can be assigned to T, (i.e. Counter myCounter = Reducers.CounterReducer()) thats how Reducer<T> Redux.CombineReducers<T>(T state) works as it will take a simple object literal of which the properties can be composed of mutiple seperate reducers. That is the beauty of Redux library

    var appReducer = Redux.CombineReducers(new AppState
        User = Reducers.UserReducer(),
        Counter = Reducers.CounterReducer()
    var store = Redux.CreateStore(appReducer);
    store.Subscribe(() => Console.WriteLine(store.GetState()));
    Last edited by zaid94; 2016-09-06 @ 09:44 PM. Reason: typo