ваше сообщение коммита

This commit is contained in:
2025-05-01 02:53:34 +03:00
parent 01f96a9b80
commit ef2da22c70
15 changed files with 1369 additions and 1000 deletions

View File

@@ -0,0 +1,43 @@
import { ref } from 'vue';
// Простая шина событий на основе ref
const listeners = ref({});
export default {
// Подписка на событие
on(event, callback) {
if (!listeners.value[event]) {
listeners.value[event] = [];
}
listeners.value[event].push(callback);
// Возвращаем функцию отписки
return () => {
this.off(event, callback);
};
},
// Отписка от события
off(event, callback) {
if (!listeners.value[event]) return;
const idx = listeners.value[event].indexOf(callback);
if (idx > -1) {
listeners.value[event].splice(idx, 1);
}
// Очистка пустых массивов
if (listeners.value[event].length === 0) {
delete listeners.value[event];
}
},
// Вызов события с передачей данных
emit(event, data) {
if (!listeners.value[event]) return;
listeners.value[event].forEach(callback => {
callback(data);
});
}
};