chore: minor fixes after refactor

This commit is contained in:
Roman Hotsiy 2018-08-17 15:01:18 +03:00
parent 43a22f5531
commit b9c1b49810
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 9 additions and 5 deletions

View File

@ -4,10 +4,6 @@ import { IS_BROWSER } from '../utils/';
const EVENT = 'hashchange'; const EVENT = 'hashchange';
function isSameHash(a: string, b: string): boolean {
return a === b || '#' + a === b || a === '#' + b;
}
export class HistoryService { export class HistoryService {
private _emiter; private _emiter;
@ -21,6 +17,9 @@ export class HistoryService {
} }
linkForId(id: string) { linkForId(id: string) {
if (!id) {
return '';
}
return '#' + id; return '#' + id;
} }
@ -52,7 +51,7 @@ export class HistoryService {
return; return;
} }
if (id == null || isSameHash(id, this.currentId)) { if (id == null || id === this.currentId) {
return; return;
} }
if (rewriteHistory) { if (rewriteHistory) {
@ -65,6 +64,7 @@ export class HistoryService {
return; return;
} }
window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id)); window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id));
this.emit();
} }
} }

View File

@ -31,4 +31,8 @@ describe('History service', () => {
test('should return correct link for id', () => { test('should return correct link for id', () => {
expect(history.linkForId('testid')).toEqual('#testid'); expect(history.linkForId('testid')).toEqual('#testid');
}); });
test('should return empty link for empty id', () => {
expect(history.linkForId('')).toEqual('');
});
}); });