Exemple #1
0
        public void ObserveHistoryOnReset()
        {
            // Arrange
            var initialState = CreateInitialTodoListState();
            var store        = new TodoListStore(
                Setup.TodoListStore.Reducers.CreateReducers(),
                initialState,
                true
                );

            // Act
            int observeCount = 0;
            ReduxHistory <TodoListState>?lastHistory = null;

            store.ObserveHistory()
            .Subscribe(history =>
            {
                observeCount++;
                lastHistory = history;
            });

            DispatchAllActions(store);

            store.Reset();

            // Assert
            observeCount.ShouldBe(5);
            var previousState = lastHistory?.PreviousStates.ShouldHaveSingleItem();

            previousState?.Action.ShouldBeOfType <InitializeStoreAction>();
            lastHistory?.FutureActions.ShouldBeEmpty();
        }
Exemple #2
0
        public void ObserveHistoryOnReset()
        {
            // Arrange
            var initialState = CreateInitialTodoListState();
            var store        = new TodoListStore(
                Setup.TodoListStore.Reducers.CreateReducers(),
                initialState,
                true
                );

            // Act
            int observeCount = 0;
            ReduxHistory <TodoListState> lastHistory = null;

            store.ObserveHistory()
            .Subscribe(history =>
            {
                observeCount++;
                lastHistory = history;
            });

            DispatchAllActions(store);

            store.Reset();

            // Assert
            Assert.Equal(5, observeCount);
            Assert.Single(lastHistory.PreviousStates);
            Assert.IsType <InitializeStoreAction>(lastHistory.PreviousStates[0].Action);
            Assert.Empty(lastHistory.FutureActions);
        }
Exemple #3
0
        private ImmutableList <HistoryRecord> _selectHistoryRecords <T>(ReduxHistory <T> history, T currentState)
            where T : class, IImmutable, new()
        {
            var mementosOrderedByDate = history.PreviousStates
                                        .OrderBy(memento => memento.Date)
                                        .ToList();

            var res = mementosOrderedByDate.Select((memento, index) => new HistoryRecord {
                Date          = memento.Date,
                Action        = memento.Action,
                PreviousState = memento.PreviousState,
                NextState     = index < mementosOrderedByDate.Count - 1
                            ? mementosOrderedByDate[index + 1].PreviousState
                            : currentState
            }).ToImmutableList();

            return(res);
        }