@@ -3,6 +3,7 @@ import Foundation
33import SwiftUI
44
55/// The information of a tab.
6+ @ObservableState
67public struct ChatTabInfo : Identifiable , Equatable {
78 public var id : String
89 public var title : String
@@ -52,7 +53,7 @@ public protocol ChatTabType {
5253}
5354
5455/// The base class for all chat tabs.
55- open class BaseChatTab {
56+ open class BaseChatTab : NSObject {
5657 /// A wrapper to support dynamic update of title in view.
5758 struct ContentView : View {
5859 var buildView : ( ) -> any View
@@ -61,18 +62,23 @@ open class BaseChatTab {
6162 }
6263 }
6364
64- public var id : String { chatTabViewStore . id }
65- public var title : String { chatTabViewStore . title }
65+ public var id : String = " "
66+ public var title : String = " "
6667 /// The store for chat tab info. You should only access it after `start` is called.
6768 public let chatTabStore : StoreOf < ChatTabItem >
68- /// The view store for chat tab info. You should only access it after `start` is called.
69- public let chatTabViewStore : ViewStoreOf < ChatTabItem >
7069
7170 private var didStart = false
71+ private var storeObservation : ObservationToken ?
7272
7373 public init ( store: StoreOf < ChatTabItem > ) {
7474 chatTabStore = store
75- chatTabViewStore = ViewStore ( store)
75+ super. init ( )
76+
77+ storeObservation = observe { [ weak self] in
78+ guard let self else { return }
79+ self . title = store. title
80+ self . id = store. id
81+ }
7682 }
7783
7884 /// The view for this chat tab.
@@ -220,12 +226,12 @@ public class EmptyChatTab: ChatTab {
220226 public convenience init ( id: String ) {
221227 self . init ( store: . init(
222228 initialState: . init( id: id, title: " Empty- \( id) " ) ,
223- reducer: ChatTabItem ( )
229+ reducer: { ChatTabItem ( ) }
224230 ) )
225231 }
226232
227233 public func start( ) {
228- chatTabViewStore . send ( . updateTitle( " Empty- \( id) " ) )
234+ chatTabStore . send ( . updateTitle( " Empty- \( id) " ) )
229235 }
230236}
231237
0 commit comments