@@ -103,12 +103,12 @@ internal struct StoreContext {
103103 let key = AtomKey ( atom, overrideScopeKey: override? . scopeKey)
104104 let cache = lookupCache ( of: atom, for: key)
105105 let newCache = cache ?? makeNewCache ( of: atom, for: key, override: override)
106- let isInserted = store. graph. children [ key, default: [ ] ] . insert ( transaction. key) . inserted
106+ let isNew = store. graph. children [ key, default: [ ] ] . insert ( transaction. key) . inserted
107107
108108 // Add an `Edge` from the upstream to downstream.
109109 store. graph. dependencies [ transaction. key, default: [ ] ] . insert ( key)
110110
111- if isInserted || cache == nil {
111+ if isNew || cache == nil {
112112 notifyUpdateToObservers ( )
113113 }
114114
@@ -132,15 +132,14 @@ internal struct StoreContext {
132132 requiresObjectUpdate: requiresObjectUpdate,
133133 notifyUpdate: notifyUpdate
134134 )
135- let isInserted = store. state. subscriptions [ key, default: [ : ] ] . updateValue ( subscription, forKey: container. key) == nil
136135
137- // Register the subscription to both the store and the container.
138- container. subscriptions [ key] = subscription
136+ store. state. subscriptions [ key, default: [ : ] ] . updateValue ( subscription, forKey: container. key)
139137 container. unsubscribe = { keys in
140138 unsubscribe ( keys, for: container. key)
141139 }
140+ let isNew = container. subscribingKeys. insert ( key) . inserted
142141
143- if isInserted || cache == nil {
142+ if isNew || cache == nil {
144143 notifyUpdateToObservers ( )
145144 }
146145
@@ -201,7 +200,7 @@ internal struct StoreContext {
201200 let override = lookupOverride ( of: atom)
202201 let key = AtomKey ( atom, overrideScopeKey: override? . scopeKey)
203202
204- container. subscriptions . removeValue ( forKey : key)
203+ container. subscribingKeys . remove ( key)
205204 unsubscribe ( [ key] , for: container. key)
206205 }
207206
@@ -380,10 +379,10 @@ private extension StoreContext {
380379 }
381380 }
382381
383- func unsubscribe( _ keys: [ AtomKey ] , for subscriptionKey: SubscriptionKey ) {
382+ func unsubscribe< Keys : Sequence < AtomKey > > ( _ keys: Keys , for subscriptionKey: SubscriptionKey ) {
384383 let store = getStore ( )
385384
386- for key in keys {
385+ for key in ContiguousArray ( keys) {
387386 store. state. subscriptions [ key] ? . removeValue ( forKey: subscriptionKey)
388387 checkRelease ( for: key)
389388 }
0 commit comments