ProgressTracker
Hierarchy
- EventTarget
- ProgressTracker
Index
Constructors
constructor
Parameters
__namedParameters: ProgressTrackerOptions = {}
Returns ProgressTracker
Accessors
caption
Returns string
done
Returns boolean
loadingListener
Returns Listener<LoadingEvent>
observer
Returns ProgressObserver
progress
Returns number
weight
Returns number
Methods
addEventListener
Parameters
type: string
listener: TSCompatibleListener<ProgressTrackerEvent>
Returns void
fillSlowly
Fills the progress bar slowly over time, simulating progress.
The progress bar is filled in a 100 steps, and each step, the progress is increased by 1. If
stopBeforeFinishing
is true, the progress bar will stop filling when it reaches 99% so that you can callfinish()
explicitly.If the progress bar is filling or already filled, this method does nothing.
Parameters
options: { stopBeforeFinishing: undefined | boolean } = {}
Optional options.
Returns void
finish
Returns void
pipe
Parameters
receiver: ProgressReceiver
Returns void
removeEventListener
Parameters
type: string
listener: TSCompatibleListener<ProgressTrackerEvent>
Returns void
set
Parameters
value: number
Returns void
setCaption
Parameters
caption: string
Returns void
stage
Creates a new sub-tracker with a specific weight.
The weight determines what percentage of the overall progress the sub-tracker represents. For example, if the main tracker is monitoring a process that has two stages, and the first stage is expected to take twice as long as the second stage, you could create the first sub-tracker with a weight of 0.67 and the second sub-tracker with a weight of 0.33.
The caption is an optional string that describes the current stage of the operation. If provided, it will be used as the progress caption for the sub-tracker. If not provided, the main tracker will look for the next sub-tracker with a non-empty caption and use that as the progress caption instead.
Returns the newly-created sub-tracker.
Parameters
optionalweight: number
The weight of the new stage, as a decimal value between 0 and 1.
caption: string = ''
The caption for the new stage, which will be used as the progress caption for the sub-tracker.
Returns ProgressTracker
The ProgressTracker class is a tool for tracking progress in an operation that is divided into multiple stages. It allows you to create sub-trackers for each stage, with individual weights and captions. The main tracker automatically calculates the progress based on the weighted sum of each sub-tracker’s progress. This makes it easy to keep track of a complex, multi-stage process and report progress in a user-friendly way.
After creating the sub-trackers, you can call the set() method to update the progress of the current stage. You can also call the finish() method to mark the current stage as complete and move on to the next one. Alternatively, you can call the fillSlowly() method to simulate progress filling up slowly to 100% before calling finish().