-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide information that action is being replayed #263
Changes from all commits
600134b
7cd1deb
9e5ae82
0382e6c
2e25fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the user already has a meaning for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking about serializability. However, it does make sense to ignore that field when actions are serialized anyway. Agreed that the naming clash can potentially be an issue, will re-work this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gaearon Only issue I am seeing here is that Not sure if that's acceptable. |
||
} 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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favour of keeping the original reference untouched, of course it is a performance penalty.