mirror of
				https://github.com/reduxjs/redux-devtools.git
				synced 2025-10-31 16:07:45 +03:00 
			
		
		
		
	* Replace Action<unknown> with Action<string> In anticipation of Redux 5 type changes * Fix lint errors * Create yellow-steaks-marry.md
		
			
				
	
	
		
			34 lines
		
	
	
		
			811 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			811 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Action } from 'redux';
 | |
| import { ChartMonitorAction, TOGGLE_VISIBILITY } from './actions';
 | |
| import { ChartMonitorProps } from './ChartMonitor';
 | |
| 
 | |
| function toggleVisibility<S, A extends Action<string>>(
 | |
|   props: ChartMonitorProps<S, A>,
 | |
|   state = props.defaultIsVisible,
 | |
|   action: ChartMonitorAction,
 | |
| ): boolean {
 | |
|   if (action.type === TOGGLE_VISIBILITY) {
 | |
|     return !state;
 | |
|   }
 | |
| 
 | |
|   if (props.defaultIsVisible !== undefined) {
 | |
|     return props.defaultIsVisible;
 | |
|   }
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| export interface ChartMonitorState {
 | |
|   isVisible?: boolean;
 | |
| }
 | |
| 
 | |
| export default function reducer<S, A extends Action<string>>(
 | |
|   props: ChartMonitorProps<S, A>,
 | |
|   state: ChartMonitorState | undefined = {},
 | |
|   action: ChartMonitorAction,
 | |
| ) {
 | |
|   return {
 | |
|     isVisible: toggleVisibility(props, state.isVisible, action),
 | |
|   };
 | |
| }
 |