Files
frontend/src/core/events/EventBus.ts
lafay 705b365536
Some checks failed
Frontend CI / ota (android) (push) Successful in 3m11s
Frontend CI / ota (ios) (push) Successful in 3m31s
Frontend CI / build-and-push-web (push) Successful in 4m38s
Frontend CI / build-android-apk (push) Has been cancelled
refactor(core): distinguish network errors from auth failures and refactor real-time messaging pipeline
- Add isNetworkError() helper and FetchCurrentUserResult discriminated union to prevent logout on network failures
- Refactor authService to return { kind: 'user' } | { kind: 'auth_failed' } | { kind: 'network_error' }
- Update authStore to preserve login state on network errors, only logout on auth failures
- Replace WSMessageHandler with RealtimeIngestionPipeline for improved real-time message handling
- Remove MessageDeduplication service; add store-level idempotent addOrReplaceMessage for message dedup
- Add atomic systemUnreadCount operations to prevent race conditions
- Add SearchHeader component for consistent search UI across screens
- Add 'home' TabBar variant with underline style matching HomeScreen
- Add Jest test infrastructure and exclude tests from tsconfig
- Fix ChatScreen history lock being stuck when scrolling to latest messages
- Remove unused call_participant_joined/left WS event types
2026-06-21 17:17:15 +08:00

30 lines
840 B
TypeScript

type Subscriber<T> = (event: T) => void;
export type AppEvent =
| { type: 'NAVIGATE'; payload: { path: string; params?: Record<string, any> } }
| { type: 'NAVIGATE_BACK' }
| { type: 'SHOW_VERIFICATION_MODAL' }
| { type: 'VIBRATE'; payload: { type: 'message' | 'group_message' | 'call' } }
| { type: 'AUTH_LOGOUT' };
class EventBusClass {
private subscribers: Set<Subscriber<AppEvent>> = new Set();
emit(event: AppEvent): void {
this.subscribers.forEach(subscriber => {
try {
subscriber(event);
} catch (error) {
console.error('[EventBus] Subscriber error:', error);
}
});
}
subscribe(subscriber: Subscriber<AppEvent>): () => void {
this.subscribers.add(subscriber);
return () => this.subscribers.delete(subscriber);
}
}
export const eventBus = new EventBusClass();