mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-02-27 08:50:37 +03:00
implementing replaying flag to mark actions which are actually replayed
This commit is contained in:
parent
600134b5d3
commit
7cd1deb8a0
|
@ -59,7 +59,7 @@ const INIT_ACTION = { type: '@@INIT' };
|
|||
/**
|
||||
* Computes the next entry in the log by applying an action.
|
||||
*/
|
||||
function computeNextEntry(reducer, action, state, error) {
|
||||
function computeNextEntry(reducer, action, state, error, replaying) {
|
||||
if (error) {
|
||||
return {
|
||||
state,
|
||||
|
@ -70,7 +70,7 @@ function computeNextEntry(reducer, action, state, error) {
|
|||
let nextState = state;
|
||||
let nextError;
|
||||
try {
|
||||
nextState = reducer(state, action);
|
||||
nextState = reducer(state, action, replaying);
|
||||
} catch (err) {
|
||||
nextError = err.toString();
|
||||
if (typeof window === 'object' && typeof window.chrome !== 'undefined') {
|
||||
|
@ -97,7 +97,8 @@ function recomputeStates(
|
|||
committedState,
|
||||
actionsById,
|
||||
stagedActionIds,
|
||||
skippedActionIds
|
||||
skippedActionIds,
|
||||
replaying
|
||||
) {
|
||||
// Optimization: exit early and return the same reference
|
||||
// if we know nothing could have changed.
|
||||
|
@ -120,7 +121,7 @@ function recomputeStates(
|
|||
const shouldSkip = skippedActionIds.indexOf(actionId) > -1;
|
||||
const entry = shouldSkip ?
|
||||
previousEntry :
|
||||
computeNextEntry(reducer, action, previousState, previousError);
|
||||
computeNextEntry(reducer, action, previousState, previousError, replaying);
|
||||
|
||||
nextComputedStates.push(entry);
|
||||
}
|
||||
|
@ -170,6 +171,10 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
|
|||
// value whenever we feel like we don't have to recompute the states.
|
||||
let minInvalidatedStateIndex = 0;
|
||||
|
||||
// For now, potentially any action except PERFORM_ACTION is considered
|
||||
// as replay
|
||||
let replaying = true;
|
||||
|
||||
switch (liftedAction.type) {
|
||||
case ActionTypes.RESET: {
|
||||
// Get back to the state the store was created with.
|
||||
|
@ -245,6 +250,10 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
|
|||
stagedActionIds = [...stagedActionIds, actionId];
|
||||
// Optimization: we know that only the new action needs computing.
|
||||
minInvalidatedStateIndex = stagedActionIds.length - 1;
|
||||
|
||||
// This is the first time Action is actually performed, therefore
|
||||
// we don't consider this replay
|
||||
replaying = false;
|
||||
break;
|
||||
}
|
||||
case ActionTypes.IMPORT_STATE: {
|
||||
|
@ -262,6 +271,8 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
|
|||
break;
|
||||
}
|
||||
case '@@redux/INIT': {
|
||||
replaying = false;
|
||||
|
||||
// Always recompute states on hot reload and init.
|
||||
minInvalidatedStateIndex = 0;
|
||||
break;
|
||||
|
@ -281,7 +292,8 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
|
|||
committedState,
|
||||
actionsById,
|
||||
stagedActionIds,
|
||||
skippedActionIds
|
||||
skippedActionIds,
|
||||
replaying
|
||||
);
|
||||
monitorState = monitorReducer(monitorState, liftedAction);
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue
Block a user