mirror of
				https://github.com/checktheroads/hyperglass
				synced 2024-05-11 05:55:08 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			616 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			616 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { devtools } from 'zustand/middleware';
 | 
						|
 | 
						|
import type { StateCreator, SetState, GetState, StoreApi } from 'zustand';
 | 
						|
 | 
						|
/**
 | 
						|
 * Wrap a zustand state function with devtools, if applicable.
 | 
						|
 *
 | 
						|
 * @param store zustand store function.
 | 
						|
 * @param name Store name.
 | 
						|
 */
 | 
						|
// eslint-disable-next-line @typescript-eslint/ban-types
 | 
						|
export function withDev<T extends object = {}>(
 | 
						|
  store: StateCreator<T>,
 | 
						|
  name: string,
 | 
						|
): StateCreator<T> {
 | 
						|
  if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
 | 
						|
    return devtools<T, SetState<T>, GetState<T>, StoreApi<T>>(store, { name });
 | 
						|
  }
 | 
						|
  return store;
 | 
						|
}
 |