add unload hooks

This commit is contained in:
Guillermo Rauch 2016-07-13 22:18:06 -07:00
parent 0ce6df417b
commit f4474e747d
2 changed files with 18 additions and 1 deletions

View file

@ -28,6 +28,11 @@ let termPropsDecorators;
const { path, localPath } = plugins.getBasePaths(); const { path, localPath } = plugins.getBasePaths();
const clearModulesCache = () => { const clearModulesCache = () => {
// trigger unload hooks
modules.forEach((mod) => {
if (mod.onRendererUnload) mod.onRendererUnload(window);
});
// clear require cache // clear require cache
for (const entry in window.require.cache) { for (const entry in window.require.cache) {
if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) { if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) {
@ -132,6 +137,10 @@ const loadModules = () => {
tabsPropsDecorators.push(mod.getTabsProps); tabsPropsDecorators.push(mod.getTabsProps);
} }
if (mod.onRendererWindow) {
mod.onRendererWindow(window);
}
return mod; return mod;
}) })
.filter((mod) => !!mod); .filter((mod) => !!mod);
@ -360,7 +369,9 @@ function getDecorated (parent, name) {
return decorated[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) { export function decorate (Component, name) {
return class extends React.Component { return class extends React.Component {
render () { render () {

View file

@ -115,6 +115,12 @@ function getPluginVersions () {
} }
function clearCache (mod) { function clearCache (mod) {
// trigger unload hooks
modules.forEach((mod) => {
if (mod.onUnload) mod.onUnload();
});
// clear require cache
for (const entry in require.cache) { for (const entry in require.cache) {
if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) { if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) {
delete require.cache[entry]; delete require.cache[entry];