Skip to content

Commit eb05954

Browse files
committed
chore: simplify api, use smoothing func to increment
1 parent 8f8f499 commit eb05954

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/HolyProgress.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,11 @@ export class HolyProgress {
215215
};
216216

217217
/**
218-
* Completes the progress, moving it to 100% and then hiding it.
219-
* Optionally, it can force completion even if the bar hasn't started.
218+
* Completes the progress, moving it to 100%
220219
* @public
221-
* @param {boolean} [force] - Force completion even if the bar hasn't started.
222220
* @returns {HolyProgress} The current instance for chaining methods.
223221
*/
224-
public done = (force?: boolean): HolyProgress => {
225-
if (force === false && this.status === null) return this;
226-
227-
return this.increment(0.3 + 0.5 * Math.random()).setTo(1);
228-
};
222+
public complete = (): HolyProgress => this.setTo(1);
229223

230224
/**
231225
* Calculates an increment value based on the current status of the progress.
@@ -235,11 +229,9 @@ export class HolyProgress {
235229
* @returns {number} The calculated increment value.
236230
*/
237231
private readonly calculateIncrement = (status: number): number => {
238-
if (status < 0.2) return 0.1;
239-
if (status < 0.5) return 0.04;
240-
if (status < 0.8) return 0.02;
241-
if (status < 0.99) return 0.005;
242-
return 0;
232+
const base = 0.1;
233+
const scale = 5;
234+
return base * Math.exp(-scale * status);
243235
};
244236

245237
/**

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const HolyLoader = ({
124124

125125
const stopProgress = (): void => {
126126
try {
127-
holyProgress.done();
127+
holyProgress.complete();
128128
} catch (error) {}
129129
};
130130

0 commit comments

Comments
 (0)