@@ -24,20 +24,10 @@ protocol StateSettable {
2424 stores [ key] = store
2525 }
2626
27- public func register< State> ( store: Store < State > , for type: State . Type ) {
28- let key = String ( describing: type)
29- stores [ key] = store
30- }
31-
3227 public func store< State> ( key: String , as type: State . Type ) -> Store < State > ? {
3328 return stores [ key] as? Store < State >
3429 }
3530
36- public func store< State> ( for type: State . Type ) -> Store < State > ? {
37- let key = String ( describing: type)
38- return stores [ key] as? Store < State >
39- }
40-
4131 public func removeStore( key: String ) {
4232 stores. removeValue ( forKey: key)
4333 }
@@ -56,10 +46,6 @@ protocol StateSettable {
5646}
5747
5848public extension StoreManager {
59- static func get< State> ( _ type: State . Type ) -> Store < State > ? {
60- shared. store ( for: type)
61- }
62-
6349 static func get< State> ( key: String , as type: State . Type ) -> Store < State > ? {
6450 shared. store ( key: key, as: type)
6551 }
@@ -82,10 +68,10 @@ public struct UseStore<State: Codable, Value>: DynamicProperty {
8268 private let keyPath : KeyPath < State , Value >
8369 @StateObject private var store : Store < State >
8470
85- public init ( _ keyPath: KeyPath < State , Value > ) {
71+ public init ( _ keyPath: KeyPath < State , Value > , key : String ) {
8672 self . keyPath = keyPath
87- let foundStore = StoreManager . shared. store ( for : State . self)
88- guard let foundStore else { fatalError ( " Store not found for \( State . self ) " ) }
73+ let foundStore = StoreManager . shared. store ( key : key , as : State . self)
74+ guard let foundStore else { fatalError ( " Store not found for key: \( key ) " ) }
8975 self . _store = StateObject ( wrappedValue: foundStore)
9076 }
9177
0 commit comments