mirror of
				https://github.com/reduxjs/redux-devtools.git
				synced 2025-10-31 16:07:45 +03:00 
			
		
		
		
	Return last non-undefined state from getState()
This commit is contained in:
		
							parent
							
								
									aa5ee9b6c6
								
							
						
					
					
						commit
						41e444f75c
					
				|  | @ -203,6 +203,7 @@ function unliftState(liftedState) { | ||||||
|  * Unlifts the DevTools store to act like the app's store. |  * Unlifts the DevTools store to act like the app's store. | ||||||
|  */ |  */ | ||||||
| function unliftStore(liftedStore, reducer) { | function unliftStore(liftedStore, reducer) { | ||||||
|  |   let lastDefinedState; | ||||||
|   return { |   return { | ||||||
|     ...liftedStore, |     ...liftedStore, | ||||||
|     devToolsStore: liftedStore, |     devToolsStore: liftedStore, | ||||||
|  | @ -211,7 +212,11 @@ function unliftStore(liftedStore, reducer) { | ||||||
|       return action; |       return action; | ||||||
|     }, |     }, | ||||||
|     getState() { |     getState() { | ||||||
|       return unliftState(liftedStore.getState()); |       const state = unliftState(liftedStore.getState()); | ||||||
|  |       if (state !== undefined) { | ||||||
|  |         lastDefinedState = state; | ||||||
|  |       } | ||||||
|  |       return lastDefinedState; | ||||||
|     }, |     }, | ||||||
|     getReducer() { |     getReducer() { | ||||||
|       return reducer; |       return reducer; | ||||||
|  |  | ||||||
|  | @ -197,6 +197,22 @@ describe('devTools', () => { | ||||||
|     expect(spy.calls[0].arguments[0]).toMatch( |     expect(spy.calls[0].arguments[0]).toMatch( | ||||||
|       /ReferenceError/ |       /ReferenceError/ | ||||||
|     ); |     ); | ||||||
|  | 
 | ||||||
|  |     spy.restore(); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('returns the last non-undefined state from getState', () => { | ||||||
|  |     let spy = spyOn(console, 'error'); | ||||||
|  | 
 | ||||||
|  |     store.dispatch({ type: 'INCREMENT' }); | ||||||
|  |     store.dispatch({ type: 'DECREMENT' }); | ||||||
|  |     store.dispatch({ type: 'INCREMENT' }); | ||||||
|  |     store.dispatch({ type: 'INCREMENT' }); | ||||||
|  |     expect(store.getState()).toBe(2); | ||||||
|  | 
 | ||||||
|  |     store.replaceReducer(counterWithBug); | ||||||
|  |     expect(store.getState()).toBe(1); | ||||||
|  | 
 | ||||||
|     spy.restore(); |     spy.restore(); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user