refactor(hq): 抽离卡片行情订阅客户端
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from './AiPickModels';
|
||||
import { AllCardsCard } from '../common/AllCardsModels';
|
||||
import { AiPickDataFetcher } from './AiPickDataFetcher';
|
||||
import { AiPickHqRequestClient } from './AiPickHqRequestClient';
|
||||
import { cellColor, cellValue, formatColName } from './AiPickUtils';
|
||||
import {
|
||||
EMPTY_IMAGE_DARK,
|
||||
@@ -34,7 +35,7 @@ export struct AiPickNodeComponent {
|
||||
@State tabContentWidth: number = 0;
|
||||
@State tabScrollOffset: number = 0;
|
||||
@State showExplainSheet: boolean = false;
|
||||
private quoteUnsubscribe: (() => void) | undefined;
|
||||
private hqUnsubscribe: (() => void) | undefined;
|
||||
|
||||
private showTabGradient(): boolean {
|
||||
const maxOffset = this.tabContentWidth - this.tabViewportWidth;
|
||||
@@ -49,7 +50,7 @@ export struct AiPickNodeComponent {
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
this.stopSubscribeQuotes();
|
||||
this.stopSubscribeHq();
|
||||
}
|
||||
|
||||
// 只负责从公共 Mock 获取并更新卡片配置。
|
||||
@@ -59,25 +60,25 @@ export struct AiPickNodeComponent {
|
||||
|
||||
// 只负责请求并更新卡片展示数据。
|
||||
private async updateCardData(): Promise<void> {
|
||||
this.stopSubscribeQuotes();
|
||||
this.stopSubscribeHq();
|
||||
this.cardData = { tabs: [] };
|
||||
const fetcher = AiPickDataFetcher.getInstance();
|
||||
try {
|
||||
const tabs = await fetcher.fetchCardData();
|
||||
this.cardData = { tabs };
|
||||
if (tabs.length > 0) {
|
||||
this.subscribeQuotes();
|
||||
this.subscribeHq();
|
||||
}
|
||||
} catch {
|
||||
this.stopSubscribeQuotes();
|
||||
this.stopSubscribeHq();
|
||||
this.cardData = { tabs: [] };
|
||||
}
|
||||
}
|
||||
|
||||
// 使用当前 CardData 的全部 Tab 合约订阅行情,推送后整体更新 CardData。
|
||||
private subscribeQuotes(): void {
|
||||
this.stopSubscribeQuotes();
|
||||
this.quoteUnsubscribe = AiPickDataFetcher.getInstance().subscribeQuotes(
|
||||
private subscribeHq(): void {
|
||||
this.stopSubscribeHq();
|
||||
this.hqUnsubscribe = AiPickHqRequestClient.getInstance().subscribeHq(
|
||||
this.cardData,
|
||||
(cardData: CardData): void => {
|
||||
this.cardData = cardData;
|
||||
@@ -85,10 +86,10 @@ export struct AiPickNodeComponent {
|
||||
);
|
||||
}
|
||||
|
||||
private stopSubscribeQuotes(): void {
|
||||
if (this.quoteUnsubscribe !== undefined) {
|
||||
this.quoteUnsubscribe();
|
||||
this.quoteUnsubscribe = undefined;
|
||||
private stopSubscribeHq(): void {
|
||||
if (this.hqUnsubscribe !== undefined) {
|
||||
this.hqUnsubscribe();
|
||||
this.hqUnsubscribe = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user