File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 3232 "coveralls" : " ^3.0.9" ,
3333 "eslint-config-xo-overrides" : " ^1.4.0" ,
3434 "husky" : " ^7.0.4" ,
35+ "mem" : " ^8" ,
3536 "nyc" : " ^15.0.0" ,
3637 "xo" : " ^0.47.0"
3738 },
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import v8 from 'v8';
55import type { ExecutionContext , Macro } from 'ava' ;
66import test from 'ava' ;
77
8+ import mem from 'mem' ;
89import DeepWeakMap from '.' ;
910
1011const iterations = 2 ** 21 ;
@@ -182,3 +183,26 @@ test.serial('DeepWeakMap types', t => {
182183 name : 'TypeError' ,
183184 } ) ;
184185} ) ;
186+
187+ test . serial ( 'Integration with mem' , t => {
188+ type A = { a : number } ;
189+ type B = { b : number } ;
190+
191+ type Value = { value : number } ;
192+
193+ let callCount = 0 ;
194+ const f = mem ( ( a : A , b : B ) : Value => ( {
195+ value : a . a + b . b + callCount ++ ,
196+ } ) , {
197+ cacheKey : arguments_ => arguments_ ,
198+ cache : new DeepWeakMap ( ) ,
199+ } ) ;
200+
201+ const a0 = { a : 0 } ;
202+ const b0 = { b : 0 } ;
203+
204+ t . is ( f ( a0 , b0 ) . value , 0 ) ;
205+ t . is ( f ( a0 , b0 ) . value , 0 ) ;
206+
207+ t . is ( callCount , 1 ) ;
208+ } ) ;
Original file line number Diff line number Diff line change @@ -2905,7 +2905,7 @@ md5-hex@^3.0.1:
29052905 dependencies :
29062906 blueimp-md5 "^2.10.0"
29072907
2908- mem@^8.0.0 :
2908+ mem@^8, mem@^8 .0.0 :
29092909 version "8.1.1"
29102910 resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.1.tgz#cf118b357c65ab7b7e0817bdf00c8062297c0122"
29112911 integrity sha512-qFCFUDs7U3b8mBDPyz5EToEKoAkgCzqquIgi9nkkR9bixxOVOre+09lbuH7+9Kn2NFpm56M3GUWVbU2hQgdACA==
You can’t perform that action at this time.
0 commit comments