refactor(core): introduce EventBus and refactor store infrastructure
- Add EventBus for decoupled event-driven communication between services - Add EventSubscriber component for centralized event handling - Add requestDedupe utility for shared request deduplication - Refactor api/wsService to use eventBus instead of direct router navigation - Extract MessageMapper.toCachedMessages for consistent message mapping - Remove deprecated BaseManager and CacheBus classes - Improve @mention rendering with memberMap support in segment rendering - Update hooks to use useRef instead of useState for fetch tracking
This commit is contained in:
44
src/infrastructure/EventSubscriber.tsx
Normal file
44
src/infrastructure/EventSubscriber.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useEffect } from 'react';
|
||||
import { router } from 'expo-router';
|
||||
import * as Haptics from 'expo-haptics';
|
||||
import { eventBus, AppEvent } from '@/core/events/EventBus';
|
||||
import { hrefVerificationGuide } from '@/navigation/hrefs';
|
||||
|
||||
let verificationModalShown = false;
|
||||
|
||||
export function EventSubscriber() {
|
||||
useEffect(() => {
|
||||
return eventBus.subscribe((event: AppEvent) => {
|
||||
switch (event.type) {
|
||||
case 'NAVIGATE':
|
||||
router.push(event.payload.path);
|
||||
break;
|
||||
|
||||
case 'NAVIGATE_BACK':
|
||||
router.back();
|
||||
break;
|
||||
|
||||
case 'SHOW_VERIFICATION_MODAL':
|
||||
if (verificationModalShown) return;
|
||||
verificationModalShown = true;
|
||||
router.push(hrefVerificationGuide());
|
||||
setTimeout(() => {
|
||||
verificationModalShown = false;
|
||||
}, 3000);
|
||||
break;
|
||||
|
||||
case 'VIBRATE':
|
||||
Haptics.notificationAsync(
|
||||
event.payload.type === 'message'
|
||||
? Haptics.NotificationFeedbackType.Success
|
||||
: event.payload.type === 'group_message'
|
||||
? Haptics.NotificationFeedbackType.Warning
|
||||
: Haptics.NotificationFeedbackType.Error
|
||||
).catch(() => {});
|
||||
break;
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user