change handlermanager to use Map to prevent garbage
This commit is contained in:
Vendored
+28
-29
@@ -346,19 +346,18 @@
|
|||||||
}
|
}
|
||||||
var HandlerManager = class {
|
var HandlerManager = class {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.handlers = /* @__PURE__ */ new Set();
|
this.handlers = /* @__PURE__ */ new Map();
|
||||||
// manage
|
// manage
|
||||||
this.addHandler = (handler) => {
|
this.setHandler = (id, handler) => {
|
||||||
this.handlers.add(handler);
|
this.handlers.set(id, handler);
|
||||||
|
console.log(this.handlers.size);
|
||||||
};
|
};
|
||||||
this.deleteHandler = (handler) => {
|
this.deleteHandler = (id) => {
|
||||||
this.handlers.delete(handler);
|
this.handlers.delete(id);
|
||||||
};
|
};
|
||||||
// trigger
|
// trigger
|
||||||
this.trigger = (item) => {
|
this.trigger = (item) => {
|
||||||
for (const handler of this.handlers) {
|
[...this.handlers.values()].forEach((handler) => handler(item));
|
||||||
handler(item);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1618,8 +1617,9 @@
|
|||||||
this.settingsModel = settingsModel2;
|
this.settingsModel = settingsModel2;
|
||||||
this.connectionModel = connectionModel2;
|
this.connectionModel = connectionModel2;
|
||||||
this.loadChats();
|
this.loadChats();
|
||||||
connectionModel2.messageHandlerManager.addHandler(this.messageHandler);
|
connectionModel2.messageHandlerManager.setHandler("chat-list", this.messageHandler);
|
||||||
connectionModel2.messageSentHandlerManager.addHandler(
|
connectionModel2.messageSentHandlerManager.setHandler(
|
||||||
|
"chat-list",
|
||||||
this.messageSentHandler
|
this.messageSentHandler
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2258,14 +2258,6 @@
|
|||||||
this.BUILD = "Build 26.04.13.E";
|
this.BUILD = "Build 26.04.13.E";
|
||||||
// CONTEXT
|
// CONTEXT
|
||||||
this.contextStack = /* @__PURE__ */ new Map();
|
this.contextStack = /* @__PURE__ */ new Map();
|
||||||
this.logContexts = () => {
|
|
||||||
console.log(
|
|
||||||
"context",
|
|
||||||
this.contexts.map(
|
|
||||||
(x) => x.contextDebugDescription + "-" + x.contextId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
this.closeContext = (contextId) => {
|
this.closeContext = (contextId) => {
|
||||||
if (!this.contexts.map((context) => context.contextId).includes(contextId))
|
if (!this.contexts.map((context) => context.contextId).includes(contextId))
|
||||||
return;
|
return;
|
||||||
@@ -2274,7 +2266,6 @@
|
|||||||
this.contextStack.delete(currentContext.contextId);
|
this.contextStack.delete(currentContext.contextId);
|
||||||
if (currentContext.contextId == contextId) break;
|
if (currentContext.contextId == contextId) break;
|
||||||
}
|
}
|
||||||
this.logContexts();
|
|
||||||
};
|
};
|
||||||
this.handleKeyDown = (e) => {
|
this.handleKeyDown = (e) => {
|
||||||
if (_CoreViewModel.checkIsKeystroke(e) == false) return;
|
if (_CoreViewModel.checkIsKeystroke(e) == false) return;
|
||||||
@@ -2305,7 +2296,6 @@
|
|||||||
set context(context) {
|
set context(context) {
|
||||||
if (this.contextStack.has(context.contextId)) return;
|
if (this.contextStack.has(context.contextId)) return;
|
||||||
this.contextStack.set(context.contextId, context);
|
this.contextStack.set(context.contextId, context);
|
||||||
this.logContexts();
|
|
||||||
}
|
}
|
||||||
// util
|
// util
|
||||||
static checkIsKeystroke(e) {
|
static checkIsKeystroke(e) {
|
||||||
@@ -2747,7 +2737,8 @@
|
|||||||
bulkSubscribe([this.selectedYear, this.selectedMonth], () => {
|
bulkSubscribe([this.selectedYear, this.selectedMonth], () => {
|
||||||
this.loadMonthTasks();
|
this.loadMonthTasks();
|
||||||
});
|
});
|
||||||
boardsAndTasksModel.taskHandlerManager.addHandler(
|
boardsAndTasksModel.taskHandlerManager.setHandler(
|
||||||
|
"calendar" + this.chatViewModel.chatModel.id,
|
||||||
(taskFileContent) => {
|
(taskFileContent) => {
|
||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
}
|
}
|
||||||
@@ -3355,7 +3346,8 @@
|
|||||||
this.selectedPage.subscribeSilent(() => {
|
this.selectedPage.subscribeSilent(() => {
|
||||||
this.storeLastUsedView();
|
this.storeLastUsedView();
|
||||||
});
|
});
|
||||||
boardsAndTasksModel.taskHandlerManager.addHandler(
|
boardsAndTasksModel.taskHandlerManager.setHandler(
|
||||||
|
this.boardInfo.fileId,
|
||||||
(taskFileContent) => {
|
(taskFileContent) => {
|
||||||
if (taskFileContent.boardId != this.boardInfo.fileId) return;
|
if (taskFileContent.boardId != this.boardInfo.fileId) return;
|
||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
@@ -3504,7 +3496,8 @@
|
|||||||
this.chatViewModel = chatViewModel;
|
this.chatViewModel = chatViewModel;
|
||||||
this.chatViewModel.registerContext("tasks" /* Tasks */, this);
|
this.chatViewModel.registerContext("tasks" /* Tasks */, this);
|
||||||
this.selectedBoardId.subscribeSilent(this.updateContexts);
|
this.selectedBoardId.subscribeSilent(this.updateContexts);
|
||||||
boardsAndTasksModel.boardHandlerManager.addHandler(
|
boardsAndTasksModel.boardHandlerManager.setHandler(
|
||||||
|
"task-page" + this.chatViewModel.chatModel.id,
|
||||||
(boardInfoFileContent) => {
|
(boardInfoFileContent) => {
|
||||||
this.showBoardInList(boardInfoFileContent);
|
this.showBoardInList(boardInfoFileContent);
|
||||||
this.updateBoardIndices();
|
this.updateBoardIndices();
|
||||||
@@ -3634,14 +3627,16 @@
|
|||||||
this.coreViewModel,
|
this.coreViewModel,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
chatModel.chatMessageHandlerManager.addHandler(
|
chatModel.chatMessageHandlerManager.setHandler(
|
||||||
|
this.chatModel.id,
|
||||||
(chatMessage) => {
|
(chatMessage) => {
|
||||||
this.messagePageViewModel.showChatMessage(chatMessage);
|
this.messagePageViewModel.showChatMessage(chatMessage);
|
||||||
this.updateReadStatus();
|
this.updateReadStatus();
|
||||||
this.notificationViewModel.showNotification(chatMessage);
|
this.notificationViewModel.showNotification(chatMessage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
chatModel.reactionHandlerManager.addHandler(
|
chatModel.reactionHandlerManager.setHandler(
|
||||||
|
this.chatModel.id,
|
||||||
(reaction) => {
|
(reaction) => {
|
||||||
this.messagePageViewModel.handleReaction(reaction);
|
this.messagePageViewModel.handleReaction(reaction);
|
||||||
}
|
}
|
||||||
@@ -5958,7 +5953,8 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
this.updatePreviousAddresses();
|
this.updatePreviousAddresses();
|
||||||
coreViewModel2.connectionModel.connectionChangeHandlerManager.addHandler(
|
coreViewModel2.connectionModel.connectionChangeHandlerManager.setHandler(
|
||||||
|
"connection-view-model",
|
||||||
this.connectionChangeHandler
|
this.connectionChangeHandler
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6093,10 +6089,12 @@
|
|||||||
this.coreViewModel.closeContext(this.contextId);
|
this.coreViewModel.closeContext(this.contextId);
|
||||||
this.presentedModal.value = void 0;
|
this.presentedModal.value = void 0;
|
||||||
};
|
};
|
||||||
this.coreViewModel.fileTransferModel.fileHandlerManager.addHandler(
|
this.coreViewModel.fileTransferModel.fileHandlerManager.setHandler(
|
||||||
|
"file-transfer-view-model",
|
||||||
this.handleReceivedFile
|
this.handleReceivedFile
|
||||||
);
|
);
|
||||||
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.addHandler(
|
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.setHandler(
|
||||||
|
"file-transfer-view-model",
|
||||||
() => this.initiateTransfer()
|
() => this.initiateTransfer()
|
||||||
);
|
);
|
||||||
this.registerKeyStroke("backspace" /* CloseOrCancel */, this.hideModal);
|
this.registerKeyStroke("backspace" /* CloseOrCancel */, this.hideModal);
|
||||||
@@ -6442,7 +6440,8 @@
|
|||||||
};
|
};
|
||||||
this.storageModel = storageModel2;
|
this.storageModel = storageModel2;
|
||||||
this.connectionModel = connectionModel2;
|
this.connectionModel = connectionModel2;
|
||||||
this.connectionModel.messageHandlerManager.addHandler(
|
this.connectionModel.messageHandlerManager.setHandler(
|
||||||
|
"file-transfer",
|
||||||
this.handleMessage
|
this.handleMessage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ export default class ChatListModel {
|
|||||||
this.connectionModel = connectionModel;
|
this.connectionModel = connectionModel;
|
||||||
this.loadChats();
|
this.loadChats();
|
||||||
|
|
||||||
connectionModel.messageHandlerManager.addHandler(this.messageHandler);
|
connectionModel.messageHandlerManager.setHandler("chat-list", this.messageHandler);
|
||||||
connectionModel.messageSentHandlerManager.addHandler(
|
connectionModel.messageSentHandlerManager.setHandler("chat-list",
|
||||||
this.messageSentHandler,
|
this.messageSentHandler,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export default class FileTransferModel {
|
|||||||
this.storageModel = storageModel;
|
this.storageModel = storageModel;
|
||||||
this.connectionModel = connectionModel;
|
this.connectionModel = connectionModel;
|
||||||
|
|
||||||
this.connectionModel.messageHandlerManager.addHandler(
|
this.connectionModel.messageHandlerManager.setHandler("file-transfer",
|
||||||
this.handleMessage,
|
this.handleMessage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,22 +173,20 @@ export function checkDoesObjectMatchSearch<T>(
|
|||||||
export type Handler<T> = (item: T) => void;
|
export type Handler<T> = (item: T) => void;
|
||||||
|
|
||||||
export class HandlerManager<T> {
|
export class HandlerManager<T> {
|
||||||
handlers = new Set<Handler<T>>();
|
handlers = new Map<string, Handler<T>>();
|
||||||
|
|
||||||
// manage
|
// manage
|
||||||
addHandler = (handler: Handler<T>): void => {
|
setHandler = (id: string, handler: Handler<T>): void => {
|
||||||
this.handlers.add(handler);
|
this.handlers.set(id, handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteHandler = (handler: Handler<T>): void => {
|
deleteHandler = (id: string): void => {
|
||||||
this.handlers.delete(handler);
|
this.handlers.delete(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
// trigger
|
// trigger
|
||||||
trigger = (item: T): void => {
|
trigger = (item: T): void => {
|
||||||
for (const handler of this.handlers) {
|
[...this.handlers.values()].forEach((handler) => handler(item));
|
||||||
handler(item);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
chatModel.chatMessageHandlerManager.addHandler(
|
chatModel.chatMessageHandlerManager.setHandler(this.chatModel.id,
|
||||||
(chatMessage: ChatMessage) => {
|
(chatMessage: ChatMessage) => {
|
||||||
this.messagePageViewModel.showChatMessage(chatMessage);
|
this.messagePageViewModel.showChatMessage(chatMessage);
|
||||||
this.updateReadStatus();
|
this.updateReadStatus();
|
||||||
@@ -181,7 +181,7 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
|
|||||||
this.notificationViewModel.showNotification(chatMessage);
|
this.notificationViewModel.showNotification(chatMessage);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
chatModel.reactionHandlerManager.addHandler(
|
chatModel.reactionHandlerManager.setHandler(this.chatModel.id,
|
||||||
(reaction: ChatMessageReaction) => {
|
(reaction: ChatMessageReaction) => {
|
||||||
this.messagePageViewModel.handleReaction(reaction);
|
this.messagePageViewModel.handleReaction(reaction);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ export default class ConnectionViewModel {
|
|||||||
constructor(public readonly coreViewModel: CoreViewModel) {
|
constructor(public readonly coreViewModel: CoreViewModel) {
|
||||||
this.updatePreviousAddresses();
|
this.updatePreviousAddresses();
|
||||||
|
|
||||||
coreViewModel.connectionModel.connectionChangeHandlerManager.addHandler(
|
coreViewModel.connectionModel.connectionChangeHandlerManager.setHandler(
|
||||||
|
"connection-view-model",
|
||||||
this.connectionChangeHandler,
|
this.connectionChangeHandler,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ export class Context {
|
|||||||
this.keystrokes.set(key, fn);
|
this.keystrokes.set(key, fn);
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(public contextDebugDescription: string) {}
|
constructor(public contextDebugDescription: string) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ContextHost<T> extends Context {
|
export class ContextHost<T> extends Context {
|
||||||
|
|||||||
@@ -173,11 +173,11 @@ export default class FileTransferViewModel extends Context {
|
|||||||
constructor(public readonly coreViewModel: CoreViewModel) {
|
constructor(public readonly coreViewModel: CoreViewModel) {
|
||||||
super("file-transfer");
|
super("file-transfer");
|
||||||
|
|
||||||
this.coreViewModel.fileTransferModel.fileHandlerManager.addHandler(
|
this.coreViewModel.fileTransferModel.fileHandlerManager.setHandler("file-transfer-view-model",
|
||||||
this.handleReceivedFile,
|
this.handleReceivedFile,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.addHandler(
|
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.setHandler("file-transfer-view-model",
|
||||||
() => this.initiateTransfer(),
|
() => this.initiateTransfer(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
boardsAndTasksModel.taskHandlerManager.addHandler(
|
boardsAndTasksModel.taskHandlerManager.setHandler(this.boardInfo.fileId,
|
||||||
(taskFileContent: TaskFileContent) => {
|
(taskFileContent: TaskFileContent) => {
|
||||||
if (taskFileContent.boardId != this.boardInfo.fileId) return;
|
if (taskFileContent.boardId != this.boardInfo.fileId) return;
|
||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
boardsAndTasksModel.taskHandlerManager.addHandler(
|
boardsAndTasksModel.taskHandlerManager.setHandler("calendar" + this.chatViewModel.chatModel.id,
|
||||||
(taskFileContent: TaskFileContent) => {
|
(taskFileContent: TaskFileContent) => {
|
||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ export default class TaskPageViewModel extends ContextHost<string> {
|
|||||||
this.selectedBoardId.subscribeSilent(this.updateContexts);
|
this.selectedBoardId.subscribeSilent(this.updateContexts);
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
boardsAndTasksModel.boardHandlerManager.addHandler(
|
boardsAndTasksModel.boardHandlerManager.setHandler("task-page" + this.chatViewModel.chatModel.id,
|
||||||
(boardInfoFileContent: BoardInfoFileContent) => {
|
(boardInfoFileContent: BoardInfoFileContent) => {
|
||||||
this.showBoardInList(boardInfoFileContent);
|
this.showBoardInList(boardInfoFileContent);
|
||||||
this.updateBoardIndices();
|
this.updateBoardIndices();
|
||||||
|
|||||||
Reference in New Issue
Block a user