Created
          August 8, 2025 02:02 
        
      - 
      
 - 
        
Save kilip/15dceca53049ee8bfb171a73c8885fa1 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Borrowed & modified from https://github.com/jenseng/abuse-the-platform/blob/main/app/utils/singleton.ts | |
| // Thanks @jenseng! | |
| export const singleton = <Value>( | |
| name: string, | |
| valueFactory: () => Value, | |
| ): Value => { | |
| const g = global as unknown as { __singletons: Record<string, unknown> }; | |
| g.__singletons ??= {}; | |
| g.__singletons[name] ??= valueFactory(); | |
| return g.__singletons[name] as Value; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment