Skip to content

Commit 7f3b00c

Browse files
committed
wip refactor
1 parent 4375cf4 commit 7f3b00c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/howl.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,9 @@ class Howl {
762762
/**
763763
* Pause playback and save current position.
764764
* @param id The sound ID (empty to pause all in group).
765+
* @param skipEmit If true, the `pause` event won't be emitted.
765766
*/
766-
pause(id: number) {
767+
pause(id: number, skipEmit?: boolean) {
767768
// If the sound hasn't loaded or a play() promise is pending, add it to the load queue to pause when capable.
768769
if (this._state !== 'loaded' || this._playLock) {
769770
this._queue.push({
@@ -832,8 +833,8 @@ class Howl {
832833
}
833834
}
834835

835-
// Fire the pause event, unless `true` is passed as the 2nd argument.
836-
if (!arguments[1]) {
836+
// Fire the pause event, unless skipEmit is `true`
837+
if (!skipEmit) {
837838
this._emit('pause', sound ? sound._id : null);
838839
}
839840
}
@@ -1298,11 +1299,10 @@ class Howl {
12981299
* rate(id) -> Returns the sound id's current playback rate.
12991300
* rate(rate) -> Sets the playback rate of all sounds in this Howl group.
13001301
* rate(rate, id) -> Sets the playback rate of passed sound id.
1301-
* @return {Howl/Number} Returns this or the current playback rate.
1302+
* @return Returns this or the current playback rate.
13021303
*/
1303-
rate() {
1304-
var args = arguments;
1305-
var rate, id;
1304+
rate(...args) {
1305+
let rate, id;
13061306

13071307
// Determine the values based on arguments.
13081308
if (args.length === 0) {
@@ -1323,7 +1323,7 @@ class Howl {
13231323
}
13241324

13251325
// Update the playback rate or return the current value.
1326-
var sound;
1326+
let sound;
13271327
if (typeof rate === 'number') {
13281328
// If the sound hasn't loaded, add it to the load queue to change playback rate when capable.
13291329
if (this._state !== 'loaded' || this._playLock) {
@@ -1370,12 +1370,12 @@ class Howl {
13701370
}
13711371

13721372
// Reset the timers.
1373-
var seek = this.seek(id[i]);
1374-
var duration =
1373+
const seek = this.seek(id[i]) as number;
1374+
const duration =
13751375
(this._sprite[sound._sprite][0] + this._sprite[sound._sprite][1]) /
13761376
1000 -
13771377
seek;
1378-
var timeout = (duration * 1000) / Math.abs(sound._rate);
1378+
const timeout = (duration * 1000) / Math.abs(sound._rate);
13791379

13801380
// Start a new end timer if sound is already playing.
13811381
if (this._endTimers[id[i]] || !sound._paused) {
@@ -1406,8 +1406,7 @@ class Howl {
14061406
* @return Returns this or the current seek position.
14071407
*/
14081408
seek(...args) {
1409-
let seek: number | undefined = undefined,
1410-
id: number | undefined = undefined;
1409+
let seek, id;
14111410

14121411
// Determine the values based on arguments.
14131412
if (args.length === 0) {

0 commit comments

Comments
 (0)