perf(ui): decouple book browser rendering pipeline (#341)
* perf(ui): deferred processing for book browser * perf(ui): Further optimisation + toolbar tweaks * perf(ui): layered pipeline, toolbar and error-state fixes - Layered computed signals for memoized pipeline stages - bookIndexById map replaces O(n) indexOf in template - Remove BookFilterOrchestrationService - Filter sidebar icon: pi-filter / pi-filter-fill - View toggle moved into display settings popover - Toolbar alignment fix - Error state no longer stuck on skeleton * perf(ui): split cache pathways + added specs * perf(ui): final spec updates * perf(ui): revert view toggle change * perf(ui): review followup * perf(ui): make spec loading state explicit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import {computed, signal} from '@angular/core';
|
||||
|
||||
export type DeferredRenderMode = 'reset' | 'refresh';
|
||||
|
||||
export class DeferredRenderState<T> {
|
||||
private readonly _value = signal<T | undefined>(undefined);
|
||||
readonly value = this._value.asReadonly();
|
||||
|
||||
private readonly _isRefreshing = signal(false);
|
||||
readonly isRefreshing = this._isRefreshing.asReadonly();
|
||||
|
||||
readonly hasValue = computed(() => this._value() !== undefined);
|
||||
|
||||
private activeRequestId = 0;
|
||||
|
||||
begin(mode: DeferredRenderMode): number {
|
||||
this.activeRequestId += 1;
|
||||
|
||||
if (mode === 'reset') {
|
||||
this._value.set(undefined);
|
||||
this._isRefreshing.set(false);
|
||||
} else {
|
||||
this._isRefreshing.set(this._value() !== undefined);
|
||||
}
|
||||
|
||||
return this.activeRequestId;
|
||||
}
|
||||
|
||||
commit(requestId: number, value: T): boolean {
|
||||
if (requestId !== this.activeRequestId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._value.set(value);
|
||||
this._isRefreshing.set(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
cancel(requestId: number): void {
|
||||
if (requestId !== this.activeRequestId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isRefreshing.set(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user