diff --git a/lib/components/Redoc/redoc.js b/lib/components/Redoc/redoc.js index 3af2f23d..a7995001 100644 --- a/lib/components/Redoc/redoc.js +++ b/lib/components/Redoc/redoc.js @@ -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]]);