@@ -35,13 +35,40 @@ describe('memoize-proxy', () => {
35
35
36
36
const result1 = mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ;
37
37
const result2 = mm ( { a : '!' , b : 2 } , { extract : 'b' , stuff : '!' } ) ;
38
- expect ( result1 ) . not . to . be . equal ( result2 ) ;
39
- expect ( result1 ) . to . be . deep . equal ( result2 ) ;
38
+ expect ( result1 ) . to . be . equal ( result2 ) ;
40
39
expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . to . be . equal ( mm ( { a : '!' , b : 2 } , { extract : 'b' , stuff : '!' } ) ) ;
41
40
expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . to . be . equal ( mm ( { a : '!' , b : 2 } , { extract : 'b' , stuff : '!' } ) ) ;
42
41
43
- expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . not . to . be . deep . equal ( mm ( { a : '!' , b : 3 } , { extract : 'b' , stuff : '!' } ) ) ;
44
- expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . not . to . be . deep . equal ( mm ( { a : '!' , b : 3 } , { extract : 'a' , stuff : '!' } ) ) ;
42
+ expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . not . to . be . deep . equal ( mm ( { a : '!' , b : 3 } , {
43
+ extract : 'b' ,
44
+ stuff : '!'
45
+ } ) ) ;
46
+ expect ( mm ( { a : 1 , b : 2 } , { extract : 'b' , stuff : 1 } ) ) . not . to . be . deep . equal ( mm ( { a : '!' , b : 3 } , {
47
+ extract : 'a' ,
48
+ stuff : '!'
49
+ } ) ) ;
50
+ } ) ;
51
+
52
+ it ( 'nested memoization returning value' , ( ) => {
53
+ let callCount = 0 ;
54
+ const mapStateToProps = ( state ) => ( {
55
+ a : state . a ,
56
+ state : state ,
57
+ callCount : callCount ++
58
+ } ) ;
59
+
60
+ const mm = memoize ( memoize ( mapStateToProps ) ) ;
61
+ const state1 = { a : 1 } ;
62
+ expect ( mm ( state1 ) ) . to . be . deep . equal ( { a : 1 , state : state1 , callCount : 0 } )
63
+ expect ( mm ( state1 ) ) . to . be . deep . equal ( { a : 1 , state : state1 , callCount : 0 } )
64
+ const state2 = { a : 2 }
65
+ expect ( mm ( state2 ) ) . to . be . deep . equal ( { a : 2 , state : state2 , callCount : 1 } )
66
+ expect ( mm ( state2 ) ) . to . be . deep . equal ( { a : 2 , state : state2 , callCount : 1 } )
67
+ const state3 = { a : 2 , b : 3 } ;
68
+ expect ( mm ( state3 ) ) . to . be . deep . equal ( { a : 2 , state : state2 , callCount : 1 } )
69
+ expect ( mm ( state2 ) ) . to . be . deep . equal ( { a : 2 , state : state2 , callCount : 1 } )
70
+
71
+ expect ( mm ( state1 ) ) . to . be . deep . equal ( { a : 1 , state : state1 , callCount : 2 } )
45
72
} ) ;
46
73
47
74
it ( 'memoize twice' , ( ) => {
@@ -133,11 +160,15 @@ describe('memoize-proxy', () => {
133
160
134
161
it ( 'should pass name and content' , ( ) => {
135
162
const fn = a => a ;
136
- function func ( a ) { return a ; }
163
+
164
+ function func ( a ) {
165
+ return a ;
166
+ }
167
+
137
168
expect ( memoize ( fn ) . name ) . to . equal ( 'fn' ) ;
138
169
expect ( memoize ( a => a ) . name ) . to . equal ( '' ) ;
139
170
expect ( memoize ( func ) . name ) . to . equal ( 'func' ) ;
140
- expect ( String ( memoize ( func ) ) ) . to . equal ( '/* memoized by memoize-state */\n' + func ) ;
171
+ expect ( String ( memoize ( func ) ) ) . to . equal ( '/* memoized by memoize-state */\n' + func ) ;
141
172
} ) ;
142
173
143
174
it ( 'should detect argument as result' , ( ) => {
@@ -156,22 +187,22 @@ describe('memoize-proxy', () => {
156
187
const A = {
157
188
data : 42
158
189
} ;
159
- const B = { A } ;
160
- const C = { A } ;
190
+ const B = { A } ;
191
+ const C = { A } ;
161
192
162
193
let cache1 , cache2 ;
163
194
164
195
const fn1 = ( { A} ) => {
165
- if ( ! cache1 ) {
166
- cache1 = A ;
196
+ if ( ! cache1 ) {
197
+ cache1 = A ;
167
198
} else {
168
199
expect ( cache1 ) . to . be . equal ( A ) ;
169
200
}
170
201
} ;
171
202
172
203
const fn2 = ( { A} ) => {
173
- if ( ! cache2 ) {
174
- cache2 = A ;
204
+ if ( ! cache2 ) {
205
+ cache2 = A ;
175
206
} else {
176
207
expect ( cache2 ) . not . to . be . equal ( A ) ;
177
208
}
@@ -181,15 +212,15 @@ describe('memoize-proxy', () => {
181
212
mfn1 ( B ) ;
182
213
mfn1 ( C ) ;
183
214
184
- const mfn2 = memoize ( fn2 , { nestedEquality : false } ) ;
215
+ const mfn2 = memoize ( fn2 , { nestedEquality : false } ) ;
185
216
mfn2 ( B ) ;
186
217
mfn2 ( C ) ;
187
218
} ) ;
188
219
189
220
it ( 'smoke args memoization' , ( ) => {
190
221
const o1 = { a : 1 } ;
191
222
const o2 = { a : 1 } ;
192
- const f1 = memoize ( obj => Object . assign ( { } , obj ) , { strictArity : true } ) ;
223
+ const f1 = memoize ( obj => Object . assign ( { } , obj ) , { strictArity : true } ) ;
193
224
const f2 = memoize ( obj => Object . assign ( { } , obj ) ) ;
194
225
195
226
const result11 = f1 ( o1 , 1 , o1 ) ;
0 commit comments