Skip to main content
cngx-src documentation

resolveLoadingTreatment

Functioncore/utilsv0.1.0

projects/core/utils/loading-config.ts

Description#

Pick a spinner or a skeleton from an observed busy-envelope duration.

Completes the latency-aware set: createLatencyProbe measures, CngxLoadingConfig.spinnerVsSkeletonCutoff sets the threshold, and this turns the pair into a treatment. Pure, so a surface can call it inside a computed() without a side effect.

Before any window has closed lastDuration is undefined and the answer is 'skeleton': a first load is the one with nothing cached and no measurement to argue otherwise, and a skeleton that resolves quickly reads better than a spinner that outstays a layout shift.

Signature#

resolveLoadingTreatment(requested: CngxLoadingTreatment, lastDuration, cutoff: number)

Parameters#

@paramrequestedCngxLoadingTreatment

The surface's loadingTreatment; anything but 'auto' wins verbatim.

@paramlastDuration

createLatencyProbe().lastDuration() - ms of the last completed window.

@paramcutoffnumber

injectLoadingConfig().spinnerVsSkeletonCutoff.

Returns#

Exclude