@@ -11,7 +11,7 @@ import {
11
11
DocumentNode ,
12
12
} from "../../../core" ;
13
13
import { Cache } from "../../../cache" ;
14
- import { InMemoryCache } from "../inMemoryCache" ;
14
+ import { $ , InMemoryCache } from "../inMemoryCache" ;
15
15
import { InMemoryCacheConfig } from "../types" ;
16
16
17
17
import { StoreReader } from "../readFromStore" ;
@@ -1498,13 +1498,15 @@ describe("Cache", () => {
1498
1498
}
1499
1499
` ;
1500
1500
1501
- const originalReader = cache [ "storeReader" ] ;
1501
+ const privates = $ ( cache ) ;
1502
+
1503
+ const originalReader = privates . storeReader ;
1502
1504
expect ( originalReader ) . toBeInstanceOf ( StoreReader ) ;
1503
1505
1504
- const originalWriter = cache [ " storeWriter" ] ;
1506
+ const originalWriter = privates . storeWriter ;
1505
1507
expect ( originalWriter ) . toBeInstanceOf ( StoreWriter ) ;
1506
1508
1507
- const originalMBW = cache [ " maybeBroadcastWatch" ] ;
1509
+ const originalMBW = privates . maybeBroadcastWatch ;
1508
1510
expect ( typeof originalMBW ) . toBe ( "function" ) ;
1509
1511
1510
1512
const originalCanon = originalReader . canon ;
@@ -1534,12 +1536,12 @@ describe("Cache", () => {
1534
1536
c : "see" ,
1535
1537
} ) ;
1536
1538
1537
- expect ( originalReader ) . not . toBe ( cache [ " storeReader" ] ) ;
1538
- expect ( originalWriter ) . not . toBe ( cache [ " storeWriter" ] ) ;
1539
- expect ( originalMBW ) . not . toBe ( cache [ " maybeBroadcastWatch" ] ) ;
1539
+ expect ( originalReader ) . not . toBe ( privates . storeReader ) ;
1540
+ expect ( originalWriter ) . not . toBe ( privates . storeWriter ) ;
1541
+ expect ( originalMBW ) . not . toBe ( privates . maybeBroadcastWatch ) ;
1540
1542
// The cache.storeReader.canon is preserved by default, but can be dropped
1541
1543
// by passing resetResultIdentities:true to cache.gc.
1542
- expect ( originalCanon ) . toBe ( cache [ " storeReader" ] . canon ) ;
1544
+ expect ( originalCanon ) . toBe ( privates . storeReader . canon ) ;
1543
1545
} ) ;
1544
1546
} ) ;
1545
1547
@@ -2122,10 +2124,11 @@ describe("Cache", () => {
2122
2124
describe ( "resultCacheMaxSize" , ( ) => {
2123
2125
it ( "uses default max size on caches if resultCacheMaxSize is not configured" , ( ) => {
2124
2126
const cache = new InMemoryCache ( ) ;
2125
- expect ( cache [ "maybeBroadcastWatch" ] . options . max ) . toBe (
2127
+ const privates = $ ( cache ) ;
2128
+ expect ( privates . maybeBroadcastWatch . options . max ) . toBe (
2126
2129
defaultCacheSizes [ "inMemoryCache.maybeBroadcastWatch" ]
2127
2130
) ;
2128
- expect ( cache [ " storeReader" ] [ "executeSelectionSet" ] . options . max ) . toBe (
2131
+ expect ( privates . storeReader [ "executeSelectionSet" ] . options . max ) . toBe (
2129
2132
defaultCacheSizes [ "inMemoryCache.executeSelectionSet" ]
2130
2133
) ;
2131
2134
expect ( cache [ "getFragmentDoc" ] . options . max ) . toBe (
@@ -2136,8 +2139,9 @@ describe("resultCacheMaxSize", () => {
2136
2139
it ( "configures max size on caches when resultCacheMaxSize is set" , ( ) => {
2137
2140
const resultCacheMaxSize = 12345 ;
2138
2141
const cache = new InMemoryCache ( { resultCacheMaxSize } ) ;
2139
- expect ( cache [ "maybeBroadcastWatch" ] . options . max ) . toBe ( resultCacheMaxSize ) ;
2140
- expect ( cache [ "storeReader" ] [ "executeSelectionSet" ] . options . max ) . toBe (
2142
+ const privates = $ ( cache ) ;
2143
+ expect ( privates . maybeBroadcastWatch . options . max ) . toBe ( resultCacheMaxSize ) ;
2144
+ expect ( privates . storeReader [ "executeSelectionSet" ] . options . max ) . toBe (
2141
2145
resultCacheMaxSize
2142
2146
) ;
2143
2147
expect ( cache [ "getFragmentDoc" ] . options . max ) . toBe (
@@ -2400,7 +2404,7 @@ describe("InMemoryCache#broadcastWatches", function () {
2400
2404
[ canonicalCache , nonCanonicalCache ] . forEach ( ( cache ) => {
2401
2405
// Hack: delete every watch.lastDiff, so subsequent results will be
2402
2406
// broadcast, even though they are deeply equal to the previous results.
2403
- cache [ "watches" ] . forEach ( ( watch ) => {
2407
+ $ ( cache ) [ "watches" ] . forEach ( ( watch ) => {
2404
2408
delete watch . lastDiff ;
2405
2409
} ) ;
2406
2410
} ) ;
@@ -3813,19 +3817,20 @@ describe("ReactiveVar and makeVar", () => {
3813
3817
3814
3818
expect ( diffs . length ) . toBe ( 5 ) ;
3815
3819
3816
- expect ( cache [ "watches" ] . size ) . toBe ( 5 ) ;
3820
+ const watches = $ ( cache ) [ "watches" ] ;
3821
+ expect ( watches . size ) . toBe ( 5 ) ;
3817
3822
expect ( spy ) . not . toBeCalled ( ) ;
3818
3823
3819
3824
unwatchers . pop ( ) ! ( ) ;
3820
- expect ( cache [ " watches" ] . size ) . toBe ( 4 ) ;
3825
+ expect ( watches . size ) . toBe ( 4 ) ;
3821
3826
expect ( spy ) . not . toBeCalled ( ) ;
3822
3827
3823
3828
unwatchers . shift ( ) ! ( ) ;
3824
- expect ( cache [ " watches" ] . size ) . toBe ( 3 ) ;
3829
+ expect ( watches . size ) . toBe ( 3 ) ;
3825
3830
expect ( spy ) . not . toBeCalled ( ) ;
3826
3831
3827
3832
unwatchers . pop ( ) ! ( ) ;
3828
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3833
+ expect ( watches . size ) . toBe ( 2 ) ;
3829
3834
expect ( spy ) . not . toBeCalled ( ) ;
3830
3835
3831
3836
expect ( diffs . length ) . toBe ( 5 ) ;
@@ -3835,7 +3840,7 @@ describe("ReactiveVar and makeVar", () => {
3835
3840
expect ( unwatchers . length ) . toBe ( 3 ) ;
3836
3841
unwatchers . forEach ( ( unwatch ) => unwatch ( ) ) ;
3837
3842
3838
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3843
+ expect ( watches . size ) . toBe ( 0 ) ;
3839
3844
expect ( spy ) . toBeCalledTimes ( 1 ) ;
3840
3845
expect ( spy ) . toBeCalledWith ( cache ) ;
3841
3846
} ) ;
@@ -3865,7 +3870,8 @@ describe("ReactiveVar and makeVar", () => {
3865
3870
watch ( "a" ) ;
3866
3871
watch ( "d" ) ;
3867
3872
3868
- expect ( cache [ "watches" ] . size ) . toBe ( 5 ) ;
3873
+ const watches = $ ( cache ) [ "watches" ] ;
3874
+ expect ( watches . size ) . toBe ( 5 ) ;
3869
3875
expect ( diffCounts ) . toEqual ( {
3870
3876
a : 2 ,
3871
3877
b : 1 ,
@@ -3875,7 +3881,7 @@ describe("ReactiveVar and makeVar", () => {
3875
3881
3876
3882
unwatchers . a . forEach ( ( unwatch ) => unwatch ( ) ) ;
3877
3883
unwatchers . a . length = 0 ;
3878
- expect ( cache [ " watches" ] . size ) . toBe ( 3 ) ;
3884
+ expect ( watches . size ) . toBe ( 3 ) ;
3879
3885
3880
3886
nameVar ( "Hugh" ) ;
3881
3887
expect ( diffCounts ) . toEqual ( {
@@ -3886,7 +3892,7 @@ describe("ReactiveVar and makeVar", () => {
3886
3892
} ) ;
3887
3893
3888
3894
cache . reset ( { discardWatches : true } ) ;
3889
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3895
+ expect ( watches . size ) . toBe ( 0 ) ;
3890
3896
3891
3897
expect ( diffCounts ) . toEqual ( {
3892
3898
a : 2 ,
@@ -3926,7 +3932,7 @@ describe("ReactiveVar and makeVar", () => {
3926
3932
} ) ;
3927
3933
3928
3934
nameVar ( "Trevor" ) ;
3929
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3935
+ expect ( watches . size ) . toBe ( 2 ) ;
3930
3936
expect ( diffCounts ) . toEqual ( {
3931
3937
a : 2 ,
3932
3938
b : 2 ,
@@ -3937,7 +3943,7 @@ describe("ReactiveVar and makeVar", () => {
3937
3943
} ) ;
3938
3944
3939
3945
cache . reset ( { discardWatches : true } ) ;
3940
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3946
+ expect ( watches . size ) . toBe ( 0 ) ;
3941
3947
3942
3948
nameVar ( "Danielle" ) ;
3943
3949
expect ( diffCounts ) . toEqual ( {
@@ -3949,7 +3955,7 @@ describe("ReactiveVar and makeVar", () => {
3949
3955
f : 2 ,
3950
3956
} ) ;
3951
3957
3952
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3958
+ expect ( watches . size ) . toBe ( 0 ) ;
3953
3959
} ) ;
3954
3960
3955
3961
it ( "should recall forgotten vars once cache has watches again" , ( ) => {
@@ -3974,22 +3980,23 @@ describe("ReactiveVar and makeVar", () => {
3974
3980
expect ( diffs . length ) . toBe ( 3 ) ;
3975
3981
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" ] ) ;
3976
3982
3977
- expect ( cache [ "watches" ] . size ) . toBe ( 3 ) ;
3983
+ const watches = $ ( cache ) [ "watches" ] ;
3984
+ expect ( watches . size ) . toBe ( 3 ) ;
3978
3985
expect ( spy ) . not . toBeCalled ( ) ;
3979
3986
3980
3987
unwatchers . pop ( ) ! ( ) ;
3981
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3988
+ expect ( watches . size ) . toBe ( 2 ) ;
3982
3989
expect ( spy ) . not . toBeCalled ( ) ;
3983
3990
3984
3991
unwatchers . shift ( ) ! ( ) ;
3985
- expect ( cache [ " watches" ] . size ) . toBe ( 1 ) ;
3992
+ expect ( watches . size ) . toBe ( 1 ) ;
3986
3993
expect ( spy ) . not . toBeCalled ( ) ;
3987
3994
3988
3995
nameVar ( "Hugh" ) ;
3989
3996
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" , "Hugh" ] ) ;
3990
3997
3991
3998
unwatchers . pop ( ) ! ( ) ;
3992
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3999
+ expect ( watches . size ) . toBe ( 0 ) ;
3993
4000
expect ( spy ) . toBeCalledTimes ( 1 ) ;
3994
4001
expect ( spy ) . toBeCalledWith ( cache ) ;
3995
4002
@@ -3999,7 +4006,7 @@ describe("ReactiveVar and makeVar", () => {
3999
4006
4000
4007
// Call watch(false) to avoid immediate delivery of the "ignored" name.
4001
4008
unwatchers . push ( watch ( false ) ) ;
4002
- expect ( cache [ " watches" ] . size ) . toBe ( 1 ) ;
4009
+ expect ( watches . size ) . toBe ( 1 ) ;
4003
4010
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" , "Hugh" ] ) ;
4004
4011
4005
4012
// This is the test that would fail if cache.watch did not call
0 commit comments