Last active
          September 24, 2017 21:00 
        
      - 
      
- 
        Save max-winderbaum/f9d33448445f0079673527ab6e12a6d1 to your computer and use it in GitHub Desktop. 
    Poor Man's Dependency Injection
  
        
  
    
      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
    
  
  
    
  | import dep1 from '../dep1'; | |
| import dep2 from '../dep2'; | |
| const defaultDeps = { | |
| dep1, | |
| dep2, | |
| }; | |
| export function _myModuleFactory({ dep1, dep2 } = defaultDeps) { | |
| const myModule = {}; | |
| // Module code here | |
| return myModule; | |
| } | |
| export default _myModuleFactory(); | 
  
    
      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
    
  
  
    
  | import { _myModuleFactory } from './depInj.js'; | |
| const mockDep1; | |
| const mockDep2; | |
| const testableMyModule = _myModuleFactory({ | |
| dep1: mockDep1, | |
| dep2: mockDep2, | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment