Example #1
0
        public static IServiceCollection AddReduxStore <TState, TAction>(
            this IServiceCollection configure,
            TState initialState,
            Reducer <TState, TAction> rootReducer,
            Action <ReduxOptions <TState> > options = null)
        {
            configure.AddSingleton <DevToolsInterop>();
            var reduxOptions = new ReduxOptions <TState>();

            options?.Invoke(reduxOptions);
            configure.AddSingleton <Store <TState, TAction> >(sp => new Store <TState, TAction>(initialState, rootReducer, reduxOptions, sp.GetRequiredService <DevToolsInterop>()));
            return(configure);
        }
Example #2
0
        public Store(TState initialState, Reducer <TState, TAction> rootReducer, ReduxOptions <TState> options, DevToolsInterop devToolsInterop)
        {
            _initialState    = initialState;
            _rootReducer     = rootReducer;
            _options         = options;
            _devToolsInterop = devToolsInterop;

            State = initialState;

            _devToolsInterop.Reset      += OnDevToolsReset;
            _devToolsInterop.TimeTravel += OnDevToolsTimeTravel;
            _devToolsInterop.Log("initial", _options.StateSerializer(State));

            History = new List <HistoricEntry <TState, object> >
            {
                new HistoricEntry <TState, object>(State)
            };
        }