@@ -24,7 +24,7 @@ describe('Static props prevents selectors recall (#100)', () => {
24
24
} ,
25
25
} ;
26
26
27
- const selectAllBooks = memoize ( ( state : State ) => Object . values ( state ) ) ;
27
+ const selectBook1 = memoize ( ( state : State ) => state . book1 ) ;
28
28
29
29
const selectPriceString = memoize (
30
30
( state : State ) => state . book1 . priceString ,
@@ -36,7 +36,52 @@ describe('Static props prevents selectors recall (#100)', () => {
36
36
return priceString ;
37
37
} ) ;
38
38
39
- selectAllBooks ( state1 ) ;
39
+ selectBook1 ( state1 ) ;
40
+
41
+ expect ( selectAdjustedPriceString ( state1 ) ) . toBe ( '10' ) ;
42
+ expect ( selectAdjustedPriceString ( state2 ) ) . toBe ( '20' ) ;
43
+ } ) ;
44
+
45
+ it ( 'case 2' , ( ) => {
46
+ type State = {
47
+ book1 : {
48
+ staticProp : string ;
49
+ priceString : string ;
50
+ } ;
51
+ } ;
52
+
53
+ const state1 : State = {
54
+ book1 : {
55
+ staticProp : '5' ,
56
+ priceString : '10' ,
57
+ } ,
58
+ } ;
59
+
60
+ const state2 : State = {
61
+ book1 : {
62
+ staticProp : '5' ,
63
+ priceString : '20' ,
64
+ } ,
65
+ } ;
66
+
67
+ const selectBook1 = memoize ( ( state : State ) => state . book1 ) ;
68
+
69
+ const selectPriceString = memoize (
70
+ ( state : State ) => state . book1 . priceString ,
71
+ ) ;
72
+
73
+ const selectAdjustedPriceString = memoize ( ( state : State ) => {
74
+ const priceString = selectPriceString ( state ) ;
75
+ state . book1 . staticProp ; // touch the prop
76
+ return priceString ;
77
+ } ) ;
78
+
79
+ const selectMemoizedPriceString = memoize ( ( state : State ) =>
80
+ selectPriceString ( state ) ,
81
+ ) ;
82
+
83
+ selectBook1 ( state1 ) ;
84
+ selectMemoizedPriceString ( state1 ) ;
40
85
41
86
expect ( selectAdjustedPriceString ( state1 ) ) . toBe ( '10' ) ;
42
87
expect ( selectAdjustedPriceString ( state2 ) ) . toBe ( '20' ) ;
0 commit comments