@@ -157,17 +157,27 @@ final class StoreContextTests: XCTestCase {
157
157
)
158
158
159
159
XCTAssertEqual ( context. watch ( dependency0, in: transactionState) , 0 )
160
- XCTAssertEqual ( store. graph. dependencies, [ key: [ dependency0Key] ] )
161
- XCTAssertEqual ( store. graph. children, [ dependency0Key: [ key] ] )
160
+ XCTAssertEqual (
161
+ store. graph,
162
+ Graph (
163
+ dependencies: [ key: [ dependency0Key] ] ,
164
+ children: [ dependency0Key: [ key] ]
165
+ )
166
+ )
162
167
XCTAssertEqual ( ( store. state. caches [ dependency0Key] as? AtomCache < TestStateAtom < Int > > ) ? . value, 0 )
163
168
XCTAssertNotNil ( store. state. states [ dependency0Key] )
164
169
XCTAssertTrue ( snapshots. flatMap ( \. caches) . isEmpty)
165
170
166
171
transactionState. terminate ( )
167
172
168
173
XCTAssertEqual ( context. watch ( dependency1, in: transactionState) , 1 )
169
- XCTAssertEqual ( store. graph. dependencies, [ key: [ dependency0Key] ] )
170
- XCTAssertEqual ( store. graph. children, [ dependency0Key: [ key] ] )
174
+ XCTAssertEqual (
175
+ store. graph,
176
+ Graph (
177
+ dependencies: [ key: [ dependency0Key] ] ,
178
+ children: [ dependency0Key: [ key] ]
179
+ )
180
+ )
171
181
XCTAssertNil ( store. state. caches [ dependency1Key] )
172
182
XCTAssertNil ( store. state. states [ dependency1Key] )
173
183
XCTAssertTrue ( snapshots. isEmpty)
@@ -214,7 +224,7 @@ final class StoreContextTests: XCTestCase {
214
224
)
215
225
216
226
XCTAssertEqual ( initialValue, 0 )
217
- XCTAssertTrue ( subscriber. subscribing . contains ( key) )
227
+ XCTAssertTrue ( store . graph . subscribed [ subscriber. key ] ? . contains ( key) ?? false )
218
228
XCTAssertNotNil ( store. state. subscriptions [ key] ? [ subscriber. key] )
219
229
XCTAssertEqual ( ( store. state. caches [ key] as? AtomCache < TestAtom > ) ? . value, 0 )
220
230
XCTAssertEqual ( ( store. state. caches [ dependencyKey] as? AtomCache < DependencyAtom > ) ? . value, 0 )
@@ -226,11 +236,15 @@ final class StoreContextTests: XCTestCase {
226
236
snapshots. removeAll ( )
227
237
store. state. subscriptions [ key] ? [ subscriber. key] ? . update ( )
228
238
subscriberState = nil
239
+
229
240
XCTAssertEqual ( updateCount, 1 )
241
+ XCTAssertNil ( store. graph. subscribed [ subscriber. key] )
230
242
XCTAssertNil ( store. state. caches [ key] )
231
243
XCTAssertNil ( store. state. states [ key] )
244
+ XCTAssertNil ( store. state. subscriptions [ key] )
232
245
XCTAssertNil ( store. state. caches [ dependencyKey] )
233
246
XCTAssertNil ( store. state. states [ dependencyKey] )
247
+ XCTAssertNil ( store. state. subscriptions [ dependencyKey] )
234
248
XCTAssertEqual (
235
249
snapshots. map { $0. caches. mapValues { $0. value as? Int } } ,
236
250
[ [ : ] ]
@@ -372,11 +386,21 @@ final class StoreContextTests: XCTestCase {
372
386
)
373
387
374
388
_ = context. watch ( atom, subscriber: subscriber, subscription: Subscription ( ) )
375
- snapshots. removeAll ( )
376
389
context. unwatch ( atom, subscriber: subscriber)
390
+
377
391
XCTAssertEqual (
378
392
snapshots. map { $0. caches. mapValues { $0. value as? Int } } ,
379
- [ [ : ] ]
393
+ [
394
+ [ AtomKey ( atom) : 0 ] ,
395
+ [ : ] ,
396
+ ]
397
+ )
398
+ XCTAssertEqual (
399
+ snapshots. map ( \. graph) ,
400
+ [
401
+ Graph ( subscribed: [ subscriber. key: [ AtomKey ( atom) ] ] ) ,
402
+ Graph ( subscribed: [ subscriber. key: [ ] ] ) ,
403
+ ]
380
404
)
381
405
}
382
406
@@ -568,7 +592,7 @@ final class StoreContextTests: XCTestCase {
568
592
context. unwatch ( dependency1Atom, subscriber: subscriber)
569
593
context. unwatch ( dependency2Atom, subscriber: subscriber)
570
594
scoped1Context. unwatch ( dependency1Atom, subscriber: subscriber)
571
- scoped2Context. unwatch ( dependency1Atom , subscriber: subscriber)
595
+ scoped2Context. unwatch ( dependency2Atom , subscriber: subscriber)
572
596
573
597
// Override for `scoped1Context` shouldn't inherited to `scoped2Context`.
574
598
XCTAssertEqual ( scoped2Context. watch ( atom, subscriber: subscriber, subscription: Subscription ( ) ) , 21 )
@@ -644,6 +668,12 @@ final class StoreContextTests: XCTestCase {
644
668
AtomKey ( atom) ,
645
669
AtomKey ( publisherAtom) ,
646
670
] ,
671
+ ] ,
672
+ subscribed: [
673
+ subscriber. key: [
674
+ AtomKey ( ( atom) ) ,
675
+ AtomKey ( ( publisherAtom) ) ,
676
+ ]
647
677
]
648
678
)
649
679
)
@@ -1014,6 +1044,11 @@ final class StoreContextTests: XCTestCase {
1014
1044
AtomKey ( TestDependency1Atom ( ) ) : [ AtomKey ( TestAtom ( ) ) ] ,
1015
1045
AtomKey ( TestDependency2Atom ( ) ) : [ AtomKey ( TestAtom ( ) ) ] ,
1016
1046
AtomKey ( TestDependency3Atom ( ) , scopeKey: scopeToken. key) : [ AtomKey ( TestAtom ( ) ) ] ,
1047
+ ] ,
1048
+ subscribed: [
1049
+ subscriber. key: [
1050
+ AtomKey ( atom)
1051
+ ]
1017
1052
]
1018
1053
)
1019
1054
0 commit comments