Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "memily", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Javascript function memoization library.", | ||
@@ -13,8 +13,14 @@ "main": "dist/main.js", | ||
"@babel/preset-es2015": "^7.0.0-beta.37", | ||
"@babel/preset-flow": "^7.0.0-beta.37" | ||
"@babel/preset-flow": "^7.0.0-beta.37", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-jest": "^22.0.6", | ||
"consecutive": "^5.0.4", | ||
"flow-bin": "^0.63.1", | ||
"jest": "^22.0.6" | ||
}, | ||
"scripts": { | ||
"build": "babel src/memily.js --out-dir dist", | ||
"prepublish": "yarn build" | ||
"test": "jest", | ||
"build": "babel src/memily.js --out-dir dist", | ||
"prepublish": "yarn flow && yarn test && yarn build" | ||
} | ||
} |
@@ -15,6 +15,3 @@ // @flow | ||
export default function mem<Fn: Function>( | ||
fn: Fn, | ||
{ cacheKey, maxAge }: Options = {}, | ||
): Fn { | ||
export default function mem(fn: Function, { cacheKey, maxAge }: Options = {}) { | ||
if (!storeCache.has(fn)) { | ||
@@ -24,3 +21,3 @@ storeCache.set(fn, new Map()); | ||
function memoizedFn(args: any, ...rest: Array<any>): $Call<Fn> { | ||
function memoizedFn(args: any, ...rest: Array<any>) { | ||
if (rest.length > 0) { | ||
@@ -27,0 +24,0 @@ throw new Error('Cannot memoize functions with multiple arguments'); |
// @flow | ||
import consecutive from 'consecutive'; | ||
import mem, { flush } from './mem'; | ||
import memily, { flush } from './memily'; | ||
describe('mem', () => { | ||
describe('memily', () => { | ||
it('succesfully caches results of function calls', async () => { | ||
const memoized = mem(consecutive()); | ||
const memoized = memily(consecutive()); | ||
@@ -16,3 +16,3 @@ expect(memoized()).toEqual(0); | ||
const fn = jest.fn(); | ||
const memoized = mem(fn, { cacheKey: () => 'key', maxAge: 200 }); | ||
const memoized = memily(fn, { cacheKey: () => 'key', maxAge: 200 }); | ||
@@ -27,3 +27,3 @@ expect(fn.mock.calls.length).toEqual(0); | ||
it('expires results after maxAge', async () => { | ||
const memoized = mem(consecutive(), { | ||
const memoized = memily(consecutive(), { | ||
maxAge: 100, | ||
@@ -38,3 +38,3 @@ }); | ||
it('caches forever if maxAge not passed', async () => { | ||
const memoized = mem(consecutive()); | ||
const memoized = memily(consecutive()); | ||
@@ -47,3 +47,3 @@ expect(memoized()).toEqual(0); | ||
it('Caches by the argument passed to the memoized function', async () => { | ||
const memoized = mem(consecutive()); | ||
const memoized = memily(consecutive()); | ||
@@ -57,3 +57,3 @@ expect(memoized('foo')).toEqual(0); | ||
it('Caches by the argument passed to the memoized function using the cacheKey callback', async () => { | ||
const memoized = mem(consecutive(), { | ||
const memoized = memily(consecutive(), { | ||
cacheKey: (args: Object) => (args.cacheByThis: string), | ||
@@ -69,3 +69,3 @@ }); | ||
it('throws an error when you try to invoke a memoized function with mulitple arguments', async () => { | ||
const memoized = mem(jest.fn()); | ||
const memoized = memily(jest.fn()); | ||
expect(() => memoized('foo', 'bar')).toThrow(); | ||
@@ -75,3 +75,3 @@ }); | ||
it('flushes the cache when "flush" invoked', async () => { | ||
const memoized = mem(consecutive()); | ||
const memoized = memily(consecutive()); | ||
@@ -85,3 +85,3 @@ expect(memoized()).toEqual(0); | ||
const next = consecutive(); | ||
const memoized = mem(() => Promise.resolve(next())); | ||
const memoized = memily(() => Promise.resolve(next())); | ||
@@ -88,0 +88,0 @@ expect(await memoized()).toEqual(0); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25551
9
742
9
1