Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Move the Demo app from ObservableObject to the Observation framework

未关闭
#476 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
ios, macos, swift

调研方向

Start with APIProvidedView.init, where the stores are created, then read ChatStore and ResponsesStore and the list of stores in the issue. Migrate each ObservableObject to @Observable, update view ownership from @StateObject/@ObservedObject to @State/@Bindable, and remove ChatStore.selectedConversationPublisher. The work is done when the listed stores no longer use ObservableObject, store creation happens once, and the Demo builds and runs on iOS 17/macOS 14.

由索引模型根据 Issue 内容生成。

描述

The Demo app's stores are ObservableObjects. A view that observes one redraws whenever any of its @Published properties changes, whatever the view shows. While a reply streams, ChatStore and ResponsesStore change dozens of times a second, so every view observing them redraws that often too, the app's root included. In one streamed Chats reply (iOS 27 simulator), ChatStore changed 381 times, and APIProvidedView, ContentView, ChatView and the conversation list each redrew 334 times.

With the Observation framework (@Observable), a view redraws only when a property it read changes. The Demo targets iOS 17 and macOS 14, where Observation is available.

The goal is to move the Demo to Observation first, and only then decide whether anything still updates too often and needs pacing. This came up in the review of #475: the conversation list redraws on every streamed change.

Types to move

  • Streaming stores: ChatStore, ResponsesStore
  • Other stores: AssistantStore, FilesStore, ImageStore, MCPToolsStore, MiscStore, SpeechStore, ResponsesSettingsStore
  • View helper: ChatMessagesPacer, which paces the messages handed to ExyteChat's ChatView

Notes

  • Views: @StateObject becomes @State, and @ObservedObject becomes a plain property, or @Bindable where the view needs bindings (ChatView binds $store.conversations and $store.isSendingMessage). Views that only pass a store on, such as ContentView, MiscView and AssistantsView with ChatStore, then no longer redraw when it changes.
  • Creating the stores: APIProvidedView creates them in its init. @StateObject evaluates its initial value once, but @State evaluates it on every init and keeps only the first, and MCPToolsStore starts connecting in its own init. The stores need to be created once some other way.
  • Combine: ChatStore.selectedConversationPublisher is built on $selectedConversationID, which @Observable doesn't provide. Nothing uses it, so it can go.
主要语言
Swift
星标
2.9k
派生
519
平均合并
2 天 14 小时
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MacPaw/OpenAI 的其他 Issue

查看 MacPaw/OpenAI 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。