mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
fix: sheet destroy (#1705)
* fix: sheet destroy * chore: unmount properly * chore: check against fast cleanup * chore: remove debug code
This commit is contained in:
@@ -87,7 +87,7 @@ export default function boot({ app, context }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const cells = {};
|
const cells = {};
|
||||||
const cellsUnmount = {};
|
const componentsUnmount = [];
|
||||||
const components = [];
|
const components = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -98,19 +98,17 @@ export default function boot({ app, context }) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
cells,
|
cells,
|
||||||
addCell(id, cell, unmount) {
|
addCell(id, cell) {
|
||||||
cells[id] = cell;
|
cells[id] = cell;
|
||||||
cellsUnmount[id] = unmount;
|
|
||||||
},
|
},
|
||||||
removeCell(id) {
|
removeCell(id) {
|
||||||
delete cells[id];
|
delete cells[id];
|
||||||
cellsUnmount[id]();
|
|
||||||
delete cellsUnmount[id];
|
|
||||||
},
|
},
|
||||||
add(component) {
|
add(component, unmount) {
|
||||||
(async () => {
|
(async () => {
|
||||||
await rendered;
|
await rendered;
|
||||||
components.push(component);
|
components.push(component);
|
||||||
|
componentsUnmount.push(unmount);
|
||||||
appRef.current.setComps(components);
|
appRef.current.setComps(components);
|
||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
@@ -119,9 +117,11 @@ export default function boot({ app, context }) {
|
|||||||
await rendered;
|
await rendered;
|
||||||
const ix = components.indexOf(component);
|
const ix = components.indexOf(component);
|
||||||
if (ix !== -1) {
|
if (ix !== -1) {
|
||||||
|
componentsUnmount[ix]?.();
|
||||||
components.splice(ix, 1);
|
components.splice(ix, 1);
|
||||||
|
componentsUnmount.splice(ix, 1);
|
||||||
}
|
}
|
||||||
appRef.current.setComps(components);
|
appRef?.current?.setComps(components);
|
||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
setMuiThemeName(themeName) {
|
setMuiThemeName(themeName) {
|
||||||
@@ -141,10 +141,11 @@ export default function boot({ app, context }) {
|
|||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
destroy() {
|
destroy() {
|
||||||
Object.keys(cellsUnmount).forEach((c) => {
|
componentsUnmount.forEach((c) => {
|
||||||
cellsUnmount[c]();
|
c && c();
|
||||||
});
|
});
|
||||||
modelStore.destroy();
|
modelStore.destroy();
|
||||||
|
root.unmount();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
modelStore,
|
modelStore,
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ export default function glue({
|
|||||||
};
|
};
|
||||||
model.on('closed', unmount);
|
model.on('closed', unmount);
|
||||||
|
|
||||||
root.add(portal);
|
root.add(portal, unmount);
|
||||||
// Cannot use model.id as it is not unique in a given mashup
|
// Cannot use model.id as it is not unique in a given mashup
|
||||||
root.addCell(currentId, cellRef, unmount);
|
root.addCell(currentId, cellRef);
|
||||||
|
|
||||||
return [unmount, cellRef];
|
return [unmount, cellRef];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,28 +15,35 @@ export default function useExistingModel({ app, qId, options = {} }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function storeModel(m) {
|
let isCleaned = false;
|
||||||
if (modelStore.get(m.id)) {
|
let cleanupFn = () => {};
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Nebula gets the model from this store in some of its
|
|
||||||
// core functions, so it must always be stored here.
|
|
||||||
modelStore.set(m.id, m);
|
|
||||||
m.once('closed', () => {
|
|
||||||
modelStore.clear(m.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchObject(modelId) {
|
async function fetchObject(modelId) {
|
||||||
const m = modelStore.get(modelId) || (await app.getObject(modelId));
|
const m = modelStore.get(modelId) || (await app.getObject(modelId));
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = Promise.resolve(sessionModel || fetchObject(qId));
|
async function fetchModel() {
|
||||||
p.then((m) => {
|
const m = await Promise.resolve(sessionModel || fetchObject(qId));
|
||||||
storeModel(m);
|
if (isCleaned) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!modelStore.get(m.id)) {
|
||||||
|
modelStore.set(m.id, m);
|
||||||
|
const onClosed = () => {
|
||||||
|
modelStore.clear(m.id);
|
||||||
|
};
|
||||||
|
m.once('closed', onClosed);
|
||||||
|
cleanupFn = () => {
|
||||||
|
m.removeListener('closed', onClosed);
|
||||||
|
};
|
||||||
|
}
|
||||||
setModel(m);
|
setModel(m);
|
||||||
});
|
}
|
||||||
|
fetchModel();
|
||||||
|
return () => {
|
||||||
|
isCleaned = true;
|
||||||
|
cleanupFn();
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ export default function glue({
|
|||||||
);
|
);
|
||||||
navigation.setSheetRef(sheetRef);
|
navigation.setSheetRef(sheetRef);
|
||||||
|
|
||||||
root.add(portal);
|
root.add(portal, unmount);
|
||||||
return [unmount, sheetRef];
|
return [unmount, sheetRef];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user