@@ -103,12 +103,12 @@ internal struct StoreContext {
103
103
let key = AtomKey ( atom, overrideScopeKey: override? . scopeKey)
104
104
let cache = lookupCache ( of: atom, for: key)
105
105
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
107
107
108
108
// Add an `Edge` from the upstream to downstream.
109
109
store. graph. dependencies [ transaction. key, default: [ ] ] . insert ( key)
110
110
111
- if isInserted || cache == nil {
111
+ if isNew || cache == nil {
112
112
notifyUpdateToObservers ( )
113
113
}
114
114
@@ -132,15 +132,14 @@ internal struct StoreContext {
132
132
requiresObjectUpdate: requiresObjectUpdate,
133
133
notifyUpdate: notifyUpdate
134
134
)
135
- let isInserted = store. state. subscriptions [ key, default: [ : ] ] . updateValue ( subscription, forKey: container. key) == nil
136
135
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)
139
137
container. unsubscribe = { keys in
140
138
unsubscribe ( keys, for: container. key)
141
139
}
140
+ let isNew = container. subscribingKeys. insert ( key) . inserted
142
141
143
- if isInserted || cache == nil {
142
+ if isNew || cache == nil {
144
143
notifyUpdateToObservers ( )
145
144
}
146
145
@@ -201,7 +200,7 @@ internal struct StoreContext {
201
200
let override = lookupOverride ( of: atom)
202
201
let key = AtomKey ( atom, overrideScopeKey: override? . scopeKey)
203
202
204
- container. subscriptions . removeValue ( forKey : key)
203
+ container. subscribingKeys . remove ( key)
205
204
unsubscribe ( [ key] , for: container. key)
206
205
}
207
206
@@ -380,10 +379,10 @@ private extension StoreContext {
380
379
}
381
380
}
382
381
383
- func unsubscribe( _ keys: [ AtomKey ] , for subscriptionKey: SubscriptionKey ) {
382
+ func unsubscribe< Keys : Sequence < AtomKey > > ( _ keys: Keys , for subscriptionKey: SubscriptionKey ) {
384
383
let store = getStore ( )
385
384
386
- for key in keys {
385
+ for key in ContiguousArray ( keys) {
387
386
store. state. subscriptions [ key] ? . removeValue ( forKey: subscriptionKey)
388
387
checkRelease ( for: key)
389
388
}
0 commit comments