From e4f53880761b4c091fdae620d076a3aaf3bf4a8b Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 9 Mar 2017 23:04:15 +0200 Subject: [PATCH] fix: do not hang when swagger doesn't contain any paths closes #216 --- lib/services/menu.service.ts | 2 +- lib/shared/components/LazyFor/lazy-for.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts index d0f95144..f3248c4d 100644 --- a/lib/services/menu.service.ts +++ b/lib/services/menu.service.ts @@ -141,7 +141,7 @@ export class MenuService { onHashChange(hash?: string) { if (hash == undefined) return; let activated = this.activateByHash(hash); - if (!this.tasks.empty) { + if (!this.tasks.processed) { this.tasks.start(this.activeIdx, this); this.scrollService.setStickElement(this.getCurrentEl()); if (activated) this.scrollToActive(); diff --git a/lib/shared/components/LazyFor/lazy-for.ts b/lib/shared/components/LazyFor/lazy-for.ts index 94019cf8..772ba8ca 100644 --- a/lib/shared/components/LazyFor/lazy-for.ts +++ b/lib/shared/components/LazyFor/lazy-for.ts @@ -31,6 +31,7 @@ export class LazyTasksService { private _tasks = []; private _current: number = 0; private _syncCount: number = 0; + private _emptyProcessed = false; private menuService; public loadProgress = new BehaviorSubject(0); @@ -38,8 +39,10 @@ export class LazyTasksService { constructor(public optionsService: OptionsService) { } - get empty() { - return this._current === this._tasks.length; + get processed() { + let res = this._tasks.length && (this._current >= this._tasks.length) || this._emptyProcessed; + if (!this._tasks.length) this._emptyProcessed = true; + return res; } set syncCount(n: number) { @@ -97,10 +100,17 @@ export class LazyTasksService { } else { this.sortTasks(idx); } + syncCount = Math.min(syncCount, this._tasks.length); if (this.allSync) syncCount = this._tasks.length; for (var i = this._current; i < syncCount; i++) { this.nextTaskSync(); } + + if (!this._tasks.length) { + this.loadProgress.next(100); + return; + } + this.nextTask(); } }