diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-31 04:27:28 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-31 04:27:28 +0800 |
commit | 05b74ba1c8b10c356d396ce9a4834d053cd791b1 (patch) | |
tree | 5cb88a3fb9eddb5783fd22501b14bae5b7d6ea6d /packages/instant/src/util | |
parent | 12dad41143c50d858edbb665d4795142a6339dd7 (diff) | |
download | dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar.gz dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar.bz2 dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar.lz dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar.xz dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.tar.zst dexon-sol-tools-05b74ba1c8b10c356d396ce9a4834d053cd791b1.zip |
Dispatching progress
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r-- | packages/instant/src/util/progress.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/packages/instant/src/util/progress.ts b/packages/instant/src/util/progress.ts index 5cb6a6de9..08b813e3d 100644 --- a/packages/instant/src/util/progress.ts +++ b/packages/instant/src/util/progress.ts @@ -1,3 +1,4 @@ +// TODO: change filename? import * as _ from 'lodash'; import { Dispatch } from 'redux'; @@ -26,19 +27,21 @@ interface TickingFinishingStatus { type TickingStatus = TickingNoneState | TickingRunningStatus | TickingFinishingStatus; const TICKS_PER_SECOND = 1000 / PROGRESS_TICK_INTERVAL_MS; -export class Progress { +class Progress { private _startTimeUnix?: number; private _expectedTimeMs?: number; private _intervalId?: number; private _percentageDone: number; private _tickingStatus: TickingStatus; + private _dispatcher: Dispatch<Action>; - constructor() { + constructor(dispatcher: Dispatch<Action>) { this._startTimeUnix = undefined; this._expectedTimeMs = undefined; this._percentageDone = 0; this._intervalId = undefined; this._tickingStatus = { state: TickingState.None }; + this._dispatcher = dispatcher; } public beginRunning(expectedTimeMs: number): void { @@ -66,8 +69,9 @@ export class Progress { : this._getNewPercentageNormal(); const maxPercentage = this._tickingStatus.state === TickingState.Finishing ? 100 : PROGRESS_STALL_AT_PERCENTAGE; - const percentageDone = Math.min(rawPercentageDone, maxPercentage); + const percentageDone = Math.floor(Math.min(rawPercentageDone, maxPercentage)); this._percentageDone = percentageDone; + this._dispatcher(actions.updateOrderProgressPercentage(this._percentageDone)); console.log('percentageDone', this._percentageDone); if (percentageDone >= 100) { this._clearTimer(); @@ -96,3 +100,9 @@ export class Progress { return this._percentageDone + finishingState.increasePercentageEveryTick; } } + +let _currentProgress: Progress | undefined; +export const progress = (dispatcher: Dispatch<Action>): Progress => { + _currentProgress = _currentProgress || new Progress(dispatcher); + return _currentProgress; +}; |