Dispose redoc on reload

This commit is contained in:
Roman Hotsiy 2016-01-15 19:01:09 +02:00
parent 7f5482d2aa
commit a81caaf8ad

View File

@ -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]]);