mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-11-04 01:37:32 +03:00 
			
		
		
		
	Dispose redoc on reload
This commit is contained in:
		
							parent
							
								
									7f5482d2aa
								
							
						
					
					
						commit
						a81caaf8ad
					
				| 
						 | 
				
			
			@ -82,13 +82,17 @@ export default class Redoc extends BaseComponent {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  static init(schemaUrl, options) {
 | 
			
		||||
    if (Redoc.appRef) {
 | 
			
		||||
      Redoc.dispose();
 | 
			
		||||
    }
 | 
			
		||||
    return SchemaManager.instance().load(schemaUrl)
 | 
			
		||||
    .then(() => {
 | 
			
		||||
      (new OptionsManager()).options = options;
 | 
			
		||||
      return bootstrap(Redoc);
 | 
			
		||||
    })
 | 
			
		||||
    .then(
 | 
			
		||||
      () => {
 | 
			
		||||
      (appRef) => {
 | 
			
		||||
        Redoc.appRef = appRef;
 | 
			
		||||
        redocEvents.bootstrapped.next();
 | 
			
		||||
        console.log('ReDoc bootstrapped!');
 | 
			
		||||
        //resolve();
 | 
			
		||||
| 
						 | 
				
			
			@ -100,6 +104,20 @@ export default class Redoc extends BaseComponent {
 | 
			
		|||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static dispose() {
 | 
			
		||||
    let dom = new BrowserDomAdapter();
 | 
			
		||||
    let el = dom.query('redoc');
 | 
			
		||||
    let parent = el.parentElement;
 | 
			
		||||
    let nextSibling = el.nextElementSibling;
 | 
			
		||||
 | 
			
		||||
    Redoc.appRef && Redoc.appRef.dispose();
 | 
			
		||||
    Redoc.appRef = null;
 | 
			
		||||
 | 
			
		||||
    // Redoc dispose removes host element, so need to restore it
 | 
			
		||||
    el = dom.createElement('redoc');
 | 
			
		||||
    el.innerText = 'Loading...';
 | 
			
		||||
    parent.insertBefore(el, nextSibling);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user