示例#1
0
 public static Store<TState, TAction> AddReduxStore<TState, TAction>(
     this IServiceCollection configure,
     TState initialState,
     Reducer<TState, TAction> rootReducer,
     Action<ReduxOptions<TState>> options = null)
 {
     var reduxOptions = new ReduxOptions<TState>();
     options?.Invoke(reduxOptions);
     var store = new Store<TState, TAction>(initialState, rootReducer, reduxOptions);
     configure.AddSingleton(store);
     return store;
 }
示例#2
0
        public static IServiceCollection AddReduxStore <TState, TAction>(
            this IServiceCollection configure,
            TState initialState,
            Reducer <TState, TAction> rootReducer,
            Action <ReduxOptions <TState> > options = null)
        {
            configure.AddScoped <DevToolsInterop>();
            var reduxOptions = new ReduxOptions <TState>();

            options?.Invoke(reduxOptions);
            configure.AddScoped <Store <TState, TAction> >(sp => new Store <TState, TAction>(initialState, rootReducer, reduxOptions, sp.GetRequiredService <DevToolsInterop>()));
            return(configure);
        }
示例#3
0
        public static Store <TState, TAction> AddReduxStore <TState, TAction>(
            this IServiceCollection configure,
            TState initialState,
            Reducer <TState, TAction> rootReducer,
            Action <ReduxOptions <TState> > options = null)
        {
            JSRuntime = configure.BuildServiceProvider().GetService <IJSInProcessRuntime>();

            var reduxOptions = new ReduxOptions <TState>();

            options?.Invoke(reduxOptions);
            var store = new Store <TState, TAction>(initialState, rootReducer, reduxOptions);

            configure.AddSingleton(store);
            return(store);
        }
示例#4
0
        public Store(TState initialState, Reducer <TState, TAction> rootReducer, ReduxOptions <TState> options, IJSRuntime jsRuntime)
        {
            _initialState = initialState;
            _rootReducer  = rootReducer;
            _options      = options;

            State = initialState;
            DevToolsInterop.JSRuntime   = jsRuntime;
            DevToolsInterop.Reset      += OnDevToolsReset;
            DevToolsInterop.TimeTravel += OnDevToolsTimeTravel;
            DevToolsInterop.Log("initial", _options.StateSerializer(State));

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