from a discord discussion with Rich Harris ❤️
          Created
          June 22, 2018 15:46 
        
      - 
      
 - 
        
Save saibotsivad/675ee4d02a71d23405baffa4b1fb8489 to your computer and use it in GitHub Desktop.  
    render components to target elements you don't have control over
  
        
        
  
    
      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 { SomeChart } from './components/SomeChart.html'; | |
| import { SomeOtherThing } from './components/SomeOtherThing.html'; | |
| const embeds = { | |
| 'some-chart': SomeChart, | |
| 'some-other-thing': SomeOtherThing | |
| }; | |
| document.on('ready', () => { | |
| [...document.querySelectorAll('.interactive')].forEach(target => { | |
| const Component = embeds[target.dataset.embed]; | |
| new Component({ target }); | |
| }); | |
| }); | 
  
    
      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
    
  
  
    
  | <div class="interactive" data-embed="some-chart"></div> | |
| <script src="path/to/bundle.js"></script> | |
| <!-- later, in a separate embed (which ends up in the same big blob of HTML) --> | |
| <div class="interactive" data-embed="some-other-thing"></div> | |
| <script src="path/to/bundle.js"></script> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment