mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-22 02:24:21 +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';
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user