mirror of
https://github.com/zadam/trilium.git
synced 2024-11-12 10:44:42 +08:00
28 lines
643 B
JavaScript
28 lines
643 B
JavaScript
|
const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION";
|
||
|
const ENTITY_CHANGED = "ENTITY_CHANGED";
|
||
|
|
||
|
const eventListeners = {};
|
||
|
|
||
|
function subscribe(eventType, listener) {
|
||
|
eventListeners[eventType] = eventListeners[eventType] || [];
|
||
|
eventListeners[eventType].push(listener);
|
||
|
}
|
||
|
|
||
|
function emit(eventType, data) {
|
||
|
const listeners = eventListeners[eventType];
|
||
|
|
||
|
if (listeners) {
|
||
|
for (const listener of listeners) {
|
||
|
// not awaiting for async processing
|
||
|
listener(data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
subscribe,
|
||
|
emit,
|
||
|
// event types:
|
||
|
ENTER_PROTECTED_SESSION,
|
||
|
ENTITY_CHANGED
|
||
|
};
|