mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
add unload hooks
This commit is contained in:
parent
0ce6df417b
commit
f4474e747d
2 changed files with 18 additions and 1 deletions
|
|
@ -28,6 +28,11 @@ let termPropsDecorators;
|
|||
const { path, localPath } = plugins.getBasePaths();
|
||||
|
||||
const clearModulesCache = () => {
|
||||
// trigger unload hooks
|
||||
modules.forEach((mod) => {
|
||||
if (mod.onRendererUnload) mod.onRendererUnload(window);
|
||||
});
|
||||
|
||||
// clear require cache
|
||||
for (const entry in window.require.cache) {
|
||||
if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) {
|
||||
|
|
@ -132,6 +137,10 @@ const loadModules = () => {
|
|||
tabsPropsDecorators.push(mod.getTabsProps);
|
||||
}
|
||||
|
||||
if (mod.onRendererWindow) {
|
||||
mod.onRendererWindow(window);
|
||||
}
|
||||
|
||||
return mod;
|
||||
})
|
||||
.filter((mod) => !!mod);
|
||||
|
|
@ -360,7 +369,9 @@ function getDecorated (parent, name) {
|
|||
return decorated[name];
|
||||
}
|
||||
|
||||
// for each component, we return the `react-proxy`d component
|
||||
// for each component, we return a higher-order component
|
||||
// that wraps with the higher-order components
|
||||
// exposed by plugins
|
||||
export function decorate (Component, name) {
|
||||
return class extends React.Component {
|
||||
render () {
|
||||
|
|
|
|||
|
|
@ -115,6 +115,12 @@ function getPluginVersions () {
|
|||
}
|
||||
|
||||
function clearCache (mod) {
|
||||
// trigger unload hooks
|
||||
modules.forEach((mod) => {
|
||||
if (mod.onUnload) mod.onUnload();
|
||||
});
|
||||
|
||||
// clear require cache
|
||||
for (const entry in require.cache) {
|
||||
if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) {
|
||||
delete require.cache[entry];
|
||||
|
|
|
|||
Loading…
Reference in a new issue