refactor(message): replace SubscriptionManager with Zustand selectors
All checks were successful
Frontend CI / ota-android (push) Successful in 11m17s
Frontend CI / build-and-push-web (push) Successful in 25m8s
Frontend CI / build-android-apk (push) Successful in 59m7s

Remove custom SubscriptionManager class and adopt Zustand's built-in
selector mechanism for reactive state updates. This simplifies the
architecture by eliminating manual subscription management and relying
on Zustand's automatic dependency tracking for component re-renders.

Key changes:
- Remove SubscriptionManager class from store.ts
- Replace all notifySubscribers calls with direct store updates
- Update hooks to use Zustand selectors with useShallow for complex data
- Remove subscribe/unsubscribe patterns from MessageManager
- Simplify EmbeddedChat to use selector instead of local state
- Rename requestConversationListRefresh to refreshConversations
This commit is contained in:
lafay
2026-03-31 19:15:13 +08:00
parent 94c11062f0
commit 259de04f3e
14 changed files with 198 additions and 993 deletions

View File

@@ -6,6 +6,7 @@
* - 直接使用 zustand store 进行状态管理
* - 服务层移至 services/ 目录
* - 新增 hooks.ts 封装常用逻辑
* - 移除了 SubscriptionManager改用 Zustand selector 进行响应式订阅
*/
// ==================== 主管理器 ====================
@@ -14,11 +15,8 @@ export { messageManager, MessageManager } from './MessageManager';
// ==================== 状态管理 ====================
export {
useMessageStore,
subscriptionManager,
normalizeConversationId,
mergeMessagesById,
notifySubscribers,
subscribeToMessages,
} from './store';
export type { MessageState, MessageActions, MessageStore } from './store';
@@ -86,7 +84,6 @@ export {
useConversation,
useCreateConversation,
useUpdateConversation,
useActiveConversation,
// 消息相关
useMessages,
@@ -103,6 +100,8 @@ export {
// 通用
useMessageManager,
useConnectionStatus,
useIsInitialized,
} from './hooks';
// ==================== 默认导出 ====================