szurubooru/client/js/events.js

36 lines
643 B
JavaScript
Raw Normal View History

2016-04-07 19:03:49 +02:00
'use strict';
let listeners = [];
function unlisten(messageClass) {
listeners[messageClass] = [];
}
2016-04-07 19:03:49 +02:00
function listen(messageClass, handler) {
if (!(messageClass in listeners)) {
listeners[messageClass] = [];
}
listeners[messageClass].push(handler);
}
function notify(messageClass, message) {
if (!(messageClass in listeners)) {
return;
}
for (let handler of listeners[messageClass]) {
handler(message);
}
}
module.exports = {
Success: 1,
Error: 2,
Info: 3,
Authentication: 4,
2016-04-12 23:49:46 +02:00
SettingsChange: 5,
2016-04-07 19:03:49 +02:00
notify: notify,
listen: listen,
unlisten: unlisten,
2016-04-07 19:03:49 +02:00
};