mirror of
https://github.com/Redocly/redoc.git
synced 2025-05-31 19:23:07 +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) {
|
static init(schemaUrl, options) {
|
||||||
|
if (Redoc.appRef) {
|
||||||
|
Redoc.dispose();
|
||||||
|
}
|
||||||
return SchemaManager.instance().load(schemaUrl)
|
return SchemaManager.instance().load(schemaUrl)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
(new OptionsManager()).options = options;
|
(new OptionsManager()).options = options;
|
||||||
return bootstrap(Redoc);
|
return bootstrap(Redoc);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => {
|
(appRef) => {
|
||||||
|
Redoc.appRef = appRef;
|
||||||
redocEvents.bootstrapped.next();
|
redocEvents.bootstrapped.next();
|
||||||
console.log('ReDoc bootstrapped!');
|
console.log('ReDoc bootstrapped!');
|
||||||
//resolve();
|
//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]]);
|
Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user