mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-21 18:14:17 +03:00
chore: minor fixes after refactor
This commit is contained in:
parent
43a22f5531
commit
b9c1b49810
|
@ -4,10 +4,6 @@ import { IS_BROWSER } from '../utils/';
|
|||
|
||||
const EVENT = 'hashchange';
|
||||
|
||||
function isSameHash(a: string, b: string): boolean {
|
||||
return a === b || '#' + a === b || a === '#' + b;
|
||||
}
|
||||
|
||||
export class HistoryService {
|
||||
private _emiter;
|
||||
|
||||
|
@ -21,6 +17,9 @@ export class HistoryService {
|
|||
}
|
||||
|
||||
linkForId(id: string) {
|
||||
if (!id) {
|
||||
return '';
|
||||
}
|
||||
return '#' + id;
|
||||
}
|
||||
|
||||
|
@ -52,7 +51,7 @@ export class HistoryService {
|
|||
return;
|
||||
}
|
||||
|
||||
if (id == null || isSameHash(id, this.currentId)) {
|
||||
if (id == null || id === this.currentId) {
|
||||
return;
|
||||
}
|
||||
if (rewriteHistory) {
|
||||
|
@ -65,6 +64,7 @@ export class HistoryService {
|
|||
return;
|
||||
}
|
||||
window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id));
|
||||
this.emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,4 +31,8 @@ describe('History service', () => {
|
|||
test('should return correct link for id', () => {
|
||||
expect(history.linkForId('testid')).toEqual('#testid');
|
||||
});
|
||||
|
||||
test('should return empty link for empty id', () => {
|
||||
expect(history.linkForId('')).toEqual('');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user