diff --git a/package.json b/package.json index 6af3fa1..ad80c0b 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "coveralls": "^3.0.9", "eslint-config-xo-overrides": "^1.4.0", "husky": "^7.0.4", + "mem": "^8", "nyc": "^15.0.0", "xo": "^0.47.0" }, diff --git a/src/index.test.ts b/src/index.test.ts index 105bc5f..3923dc2 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -5,6 +5,7 @@ import v8 from 'v8'; import type { ExecutionContext, Macro } from 'ava'; import test from 'ava'; +import mem from 'mem'; import DeepWeakMap from '.'; const iterations = 2 ** 21; @@ -182,3 +183,26 @@ test.serial('DeepWeakMap types', t => { name: 'TypeError', }); }); + +test.serial('Integration with mem', t => { + type A = { a: number }; + type B = { b: number }; + + type Value = { value: number }; + + let callCount = 0; + const f = mem((a: A, b: B): Value => ({ + value: a.a + b.b + callCount++, + }), { + cacheKey: arguments_ => arguments_, + cache: new DeepWeakMap(), + }); + + const a0 = { a: 0 }; + const b0 = { b: 0 }; + + t.is(f(a0, b0).value, 0); + t.is(f(a0, b0).value, 0); + + t.is(callCount, 1); +}); diff --git a/yarn.lock b/yarn.lock index a394c3f..4fe054f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2905,7 +2905,7 @@ md5-hex@^3.0.1: dependencies: blueimp-md5 "^2.10.0" -mem@^8.0.0: +mem@^8, mem@^8.0.0: version "8.1.1" resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.1.tgz#cf118b357c65ab7b7e0817bdf00c8062297c0122" integrity sha512-qFCFUDs7U3b8mBDPyz5EToEKoAkgCzqquIgi9nkkR9bixxOVOre+09lbuH7+9Kn2NFpm56M3GUWVbU2hQgdACA==