mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:07:08 +00:00
Support unregistering notification handlers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user