Support unregistering notification handlers

This commit is contained in:
D. Berge
2025-08-08 12:20:58 +02:00
parent 134e3bce4e
commit b583dc6c02
2 changed files with 16 additions and 1 deletions

View File

@@ -4,6 +4,10 @@ function registerHandler({ commit }, { table, handler }) {
commit('REGISTER_HANDLER', { table, handler });
}
function unregisterHandler({ commit }, { table, handler }) {
commit('UNREGISTER_HANDLER', { table, handler });
}
function processServerEvent({ commit, dispatch, state, rootState }, message) {
//console.log("processServerEvent", message);
// Error handling for invalid messages

View File

@@ -15,7 +15,18 @@ function REGISTER_HANDLER(state, { table, handler }) {
if (!state.handlers[table]) {
state.handlers[table] = [];
}
state.handlers[table].push(handler);
if (!state.handlers[table].includes(handler)) {
state.handlers[table].push(handler);
}
}
function UNREGISTER_HANDLER(state, { table, handler }) {
if (state.handlers[table]) {
const handlerIndex = state.handlers[table].findIndex(el => el === handler);
if (handlerIndex != -1) {
state.handlers[table].splice(handlerIndex, 1);
}
}
}