mirror of
				https://github.com/reduxjs/redux-devtools.git
				synced 2025-10-31 16:07:45 +03:00 
			
		
		
		
	Fix usage of filtered actions with slider-monitor (#983)
* Use jumpToAction instead of jumpToState * Jumping to action is time traveling * Fix bad null check * Fix types * Fix JUMP_TO_ACTION handling * Use indexOf
This commit is contained in:
		
							parent
							
								
									3930411ade
								
							
						
					
					
						commit
						b4f2958dda
					
				|  | @ -51,7 +51,8 @@ export default class Monitor<S, A extends Action<unknown>> { | ||||||
|     this.lastAction && /^@@redux\/(INIT|REPLACE)/.test(this.lastAction); |     this.lastAction && /^@@redux\/(INIT|REPLACE)/.test(this.lastAction); | ||||||
|   isMonitorAction = () => |   isMonitorAction = () => | ||||||
|     this.lastAction && this.lastAction !== 'PERFORM_ACTION'; |     this.lastAction && this.lastAction !== 'PERFORM_ACTION'; | ||||||
|   isTimeTraveling = () => this.lastAction === 'JUMP_TO_STATE'; |   isTimeTraveling = () => | ||||||
|  |     this.lastAction === 'JUMP_TO_STATE' || this.lastAction === 'JUMP_TO_ACTION'; | ||||||
|   isPaused = () => { |   isPaused = () => { | ||||||
|     if (this.paused) { |     if (this.paused) { | ||||||
|       if (this.lastAction !== 'BLOCKED') { |       if (this.lastAction !== 'BLOCKED') { | ||||||
|  |  | ||||||
|  | @ -104,11 +104,9 @@ export interface MonitorActionAction { | ||||||
| export interface JumpToStateAction { | export interface JumpToStateAction { | ||||||
|   type: 'JUMP_TO_STATE'; |   type: 'JUMP_TO_STATE'; | ||||||
|   index: number; |   index: number; | ||||||
|   actionId: number; |  | ||||||
| } | } | ||||||
| export interface JumpToActionAction { | export interface JumpToActionAction { | ||||||
|   type: 'JUMP_TO_ACTION'; |   type: 'JUMP_TO_ACTION'; | ||||||
|   index: number; |  | ||||||
|   actionId: number; |   actionId: number; | ||||||
| } | } | ||||||
| export interface PauseRecordingAction { | export interface PauseRecordingAction { | ||||||
|  |  | ||||||
|  | @ -217,10 +217,10 @@ export function dispatchAction( | ||||||
|   if (action.type === 'JUMP_TO_STATE' || action.type === 'JUMP_TO_ACTION') { |   if (action.type === 'JUMP_TO_STATE' || action.type === 'JUMP_TO_ACTION') { | ||||||
|     const id = state.selected || state.current; |     const id = state.selected || state.current; | ||||||
|     const liftedState = state.states[id]; |     const liftedState = state.states[id]; | ||||||
|     let currentStateIndex = action.index; |     const currentStateIndex = | ||||||
|     if (typeof currentStateIndex === 'undefined' && action.actionId) { |       action.type === 'JUMP_TO_STATE' | ||||||
|       currentStateIndex = liftedState.stagedActionIds.indexOf(action.actionId); |         ? action.index | ||||||
|     } |         : liftedState.stagedActionIds.indexOf(action.actionId); | ||||||
|     return { |     return { | ||||||
|       ...state, |       ...state, | ||||||
|       states: { |       states: { | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ import reducer from './reducers'; | ||||||
| import SliderButton from './SliderButton'; | import SliderButton from './SliderButton'; | ||||||
| 
 | 
 | ||||||
| // eslint-disable-next-line @typescript-eslint/unbound-method
 | // eslint-disable-next-line @typescript-eslint/unbound-method
 | ||||||
| const { reset, jumpToState } = ActionCreators; | const { reset, jumpToAction } = ActionCreators; | ||||||
| 
 | 
 | ||||||
| interface ExternalProps<S, A extends Action<unknown>> { | interface ExternalProps<S, A extends Action<unknown>> { | ||||||
|   // eslint-disable-next-line @typescript-eslint/ban-types
 |   // eslint-disable-next-line @typescript-eslint/ban-types
 | ||||||
|  | @ -151,11 +151,12 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
|       this.pauseReplay(); |       this.pauseReplay(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.props.dispatch(jumpToState(value)); |     this.props.dispatch(jumpToAction(this.props.stagedActionIds[value])); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   startReplay = () => { |   startReplay = () => { | ||||||
|     const { computedStates, currentStateIndex, dispatch } = this.props; |     const { computedStates, currentStateIndex, dispatch, stagedActionIds } = | ||||||
|  |       this.props; | ||||||
| 
 | 
 | ||||||
|     if (computedStates.length < 2) { |     if (computedStates.length < 2) { | ||||||
|       return; |       return; | ||||||
|  | @ -164,20 +165,20 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
| 
 | 
 | ||||||
|     let stateIndex; |     let stateIndex; | ||||||
|     if (currentStateIndex === computedStates.length - 1) { |     if (currentStateIndex === computedStates.length - 1) { | ||||||
|       dispatch(jumpToState(0)); |       dispatch(jumpToAction(stagedActionIds[0])); | ||||||
|       stateIndex = 0; |       stateIndex = 0; | ||||||
|     } else if (currentStateIndex === computedStates.length - 2) { |     } else if (currentStateIndex === computedStates.length - 2) { | ||||||
|       dispatch(jumpToState(currentStateIndex + 1)); |       dispatch(jumpToAction(stagedActionIds[currentStateIndex + 1])); | ||||||
|       return; |       return; | ||||||
|     } else { |     } else { | ||||||
|       stateIndex = currentStateIndex + 1; |       stateIndex = currentStateIndex + 1; | ||||||
|       dispatch(jumpToState(currentStateIndex + 1)); |       dispatch(jumpToAction(stagedActionIds[currentStateIndex + 1])); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let counter = stateIndex; |     let counter = stateIndex; | ||||||
|     const timer = window.setInterval(() => { |     const timer = window.setInterval(() => { | ||||||
|       if (counter + 1 <= computedStates.length - 1) { |       if (counter + 1 <= computedStates.length - 1) { | ||||||
|         dispatch(jumpToState(counter + 1)); |         dispatch(jumpToAction(stagedActionIds[counter + 1])); | ||||||
|       } |       } | ||||||
|       counter += 1; |       counter += 1; | ||||||
| 
 | 
 | ||||||
|  | @ -198,7 +199,7 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.props.currentStateIndex === this.props.computedStates.length - 1) { |     if (this.props.currentStateIndex === this.props.computedStates.length - 1) { | ||||||
|       this.props.dispatch(jumpToState(0)); |       this.props.dispatch(jumpToAction(this.props.stagedActionIds[0])); | ||||||
| 
 | 
 | ||||||
|       this.loop(0); |       this.loop(0); | ||||||
|     } else { |     } else { | ||||||
|  | @ -213,7 +214,11 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
|     const aLoop = () => { |     const aLoop = () => { | ||||||
|       const replayDiff = Date.now() - currentTimestamp; |       const replayDiff = Date.now() - currentTimestamp; | ||||||
|       if (replayDiff >= timestampDiff) { |       if (replayDiff >= timestampDiff) { | ||||||
|         this.props.dispatch(jumpToState(this.props.currentStateIndex + 1)); |         this.props.dispatch( | ||||||
|  |           jumpToAction( | ||||||
|  |             this.props.stagedActionIds[this.props.currentStateIndex + 1] | ||||||
|  |           ) | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
|         if ( |         if ( | ||||||
|           this.props.currentStateIndex >= |           this.props.currentStateIndex >= | ||||||
|  | @ -275,7 +280,11 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
|     this.pauseReplay(); |     this.pauseReplay(); | ||||||
| 
 | 
 | ||||||
|     if (this.props.currentStateIndex !== 0) { |     if (this.props.currentStateIndex !== 0) { | ||||||
|       this.props.dispatch(jumpToState(this.props.currentStateIndex - 1)); |       this.props.dispatch( | ||||||
|  |         jumpToAction( | ||||||
|  |           this.props.stagedActionIds[this.props.currentStateIndex - 1] | ||||||
|  |         ) | ||||||
|  |       ); | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  | @ -283,7 +292,11 @@ class SliderMonitor<S, A extends Action<unknown>> extends (PureComponent || | ||||||
|     this.pauseReplay(); |     this.pauseReplay(); | ||||||
| 
 | 
 | ||||||
|     if (this.props.currentStateIndex !== this.props.computedStates.length - 1) { |     if (this.props.currentStateIndex !== this.props.computedStates.length - 1) { | ||||||
|       this.props.dispatch(jumpToState(this.props.currentStateIndex + 1)); |       this.props.dispatch( | ||||||
|  |         jumpToAction( | ||||||
|  |           this.props.stagedActionIds[this.props.currentStateIndex + 1] | ||||||
|  |         ) | ||||||
|  |       ); | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user