Skip to content

Commit

Permalink
fix(utils/cache, core): removes cache callback arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 2, 2019
1 parent a755d65 commit dfbd213
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const state: ICoreState = {
scopes: []
};

function cache<T extends Function>(fn: T): T {
function cache<T>(fn: () => T): () => T {
return _cache(() => options.id, fn);
}

Expand Down
9 changes: 3 additions & 6 deletions src/utils/cache.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { IOfType } from '~/types';

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

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

return (store[key] = fn(...args));
return (store[key] = fn());
} as any;
}

0 comments on commit dfbd213

Please sign in to comment.