Move the Demo app from ObservableObject to the Observation framework

Abierto
#476 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ios, macos, swift

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Swift
Estrellas
2.9k
Forks
519
Merge medio
2 d 14 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MacPaw/OpenAI

Todos los issues de MacPaw/OpenAI

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.