Skip to content

Commit

Permalink
fix(core): 🐛 fix cache management with ignore option
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymichel committed Dec 9, 2019
1 parent 10bfb2a commit d801813
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
9 changes: 8 additions & 1 deletion packages/core/__tests__/modules/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ it('deletes ', () => {

it('checks url ', () => {
cache.checkHref = jest.fn();
cache.set(key, request, action);
cache.has(key);

expect(cache.checkHref).toHaveBeenCalled();
});

it('uses cacheIgnore ', () => {
cache.checkHref = jest.fn().mockImplementation(() => true);
const res = cache.has(key);

expect(res).toBeFalsy();
});
10 changes: 0 additions & 10 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,6 @@ export class Core {
return;
}

// if (e) {
// // No history, force page reload
// const { state } = e as PopStateEvent;
// if (trigger === 'popstate' && state === null) {
// this.force(href);

// return;
// }
// }

let self = false;

// Check prevent sameURL against current history
Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/modules/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ export class Cache extends Ignore {
request: CacheRequest,
action: CacheAction
): ICacheData {
/* istanbul ignore else */
if (!this.checkHref(href)) {
this._state.set(href, {
action,
request,
});
}
this._state.set(href, {
action,
request,
});

return {
action,
Expand Down Expand Up @@ -68,6 +65,10 @@ export class Cache extends Ignore {
* Check if value exists into cache
*/
public has(href: string): boolean {
/* istanbul ignore else */
if (this.checkHref(href)) {
return false;
}
return this._state.has(href);
}

Expand Down

0 comments on commit d801813

Please sign in to comment.