feat: 增加首次加载标志以优化数据请求逻辑
- 在FeedListFeature中新增isLoaded属性,确保仅在首次加载时请求feed数据,提升性能和用户体验。
This commit is contained in:
@@ -11,6 +11,8 @@ struct FeedListFeature {
|
||||
var isEditFeedPresented: Bool = false // 新增:控制 EditFeedView 弹窗
|
||||
// 新增:动态内容
|
||||
var moments: [MomentsInfo] = []
|
||||
// 新增:只加载一次标志
|
||||
var isLoaded: Bool = false
|
||||
}
|
||||
|
||||
enum Action: Equatable {
|
||||
@@ -28,7 +30,9 @@ struct FeedListFeature {
|
||||
func reduce(into state: inout State, action: Action) -> Effect<Action> {
|
||||
switch action {
|
||||
case .onAppear:
|
||||
// 页面展示时自动请求 feed 数据
|
||||
// 只在首次加载时请求 feed 数据
|
||||
guard !state.isLoaded else { return .none }
|
||||
state.isLoaded = true
|
||||
return .send(.fetchFeeds)
|
||||
case .fetchFeeds:
|
||||
state.isLoading = true
|
||||
|
Reference in New Issue
Block a user