Skip to content

Commit

Permalink
feat(utils): substitutes memoize w/ cache; cache now takes a getId fu…
Browse files Browse the repository at this point in the history
…nction to identify state
  • Loading branch information
rafamel committed Apr 25, 2019
1 parent 029cc30 commit d2cc870
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"@types/jest": "^24.0.11",
"@types/js-yaml": "^3.12.1",
"@types/lodash.mergewith": "^4.6.6",
"@types/object-hash": "^1.2.0",
"@types/pify": "^3.0.2",
"@types/signal-exit": "^3.0.0",
"@types/uuid": "^3.4.4",
Expand Down Expand Up @@ -126,7 +125,6 @@
"lodash.mergewith": "^4.6.1",
"loglevel": "^1.6.1",
"manage-path": "^2.0.0",
"object-hash": "^1.3.1",
"pify": "^4.0.1",
"promist": "^0.5.3",
"signal-exit": "^3.0.2",
Expand Down
15 changes: 15 additions & 0 deletions src/utils/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IOfType } from '~/types';

export default function cache<T extends Function>(
getId: () => string,
fn: T
): T {
const store: IOfType<any> = {};

return function(...args: any[]) {
const key = getId();
if (store.hasOwnProperty(key)) return store[key];

return (store[key] = fn(...args));
} as any;
}
14 changes: 0 additions & 14 deletions src/utils/memoize.ts

This file was deleted.

0 comments on commit d2cc870

Please sign in to comment.