Add a cleanup
hook
- Move view-related cleanup code out of core. - Call `remove` on `_converse.chatboxviews` during cleanup
This commit is contained in:
parent
5579e82fb9
commit
2fcce78144
@ -135,6 +135,11 @@ converse.plugins.add('converse-chatboxviews', {
|
||||
|
||||
|
||||
/************************ BEGIN Event Handlers ************************/
|
||||
api.listen.on('cleanup', () => {
|
||||
_converse?.chatboxviews.remove();
|
||||
delete _converse.chatboxviews;
|
||||
});
|
||||
|
||||
api.listen.on('chatBoxesInitialized', () => {
|
||||
_converse.chatboxviews = new _converse.ChatBoxViews({
|
||||
'model': _converse.chatboxes
|
||||
|
@ -554,6 +554,7 @@ converse.plugins.add('converse-controlbox', {
|
||||
|
||||
|
||||
/******************** Event Handlers ********************/
|
||||
api.listen.on('cleanup', () => (delete _converse.controlboxtoggle));
|
||||
|
||||
api.listen.on('chatBoxViewsInitialized', () => {
|
||||
_converse.chatboxes.on('add', item => {
|
||||
|
@ -1307,18 +1307,13 @@ async function getLoginCredentialsFromBrowser () {
|
||||
}
|
||||
|
||||
|
||||
function cleanup () {
|
||||
// Make sure everything is reset in case this is a subsequent call to
|
||||
// converse.initialize (happens during tests).
|
||||
// Make sure everything is reset in case this is a subsequent call to
|
||||
// converse.initialize (happens during tests).
|
||||
async function cleanup () {
|
||||
await _converse.api.trigger('cleanup', {'synchronous': true});
|
||||
_converse.router.history.stop();
|
||||
unregisterGlobalEventHandlers();
|
||||
delete _converse.controlboxtoggle;
|
||||
if (_converse.chatboxviews) {
|
||||
delete _converse.chatboxviews;
|
||||
}
|
||||
if (_converse.connection) {
|
||||
_converse.connection.reset();
|
||||
}
|
||||
_converse.connection?.reset();
|
||||
_converse.stopListening();
|
||||
_converse.off();
|
||||
}
|
||||
@ -1528,7 +1523,7 @@ Object.assign(converse, {
|
||||
* });
|
||||
*/
|
||||
async initialize (settings) {
|
||||
cleanup();
|
||||
await cleanup();
|
||||
PROMISES.forEach(name => api.promises.add(name));
|
||||
setUnloadEvent();
|
||||
initSettings(settings);
|
||||
|
Loading…
Reference in New Issue
Block a user