diff --git a/src/Stack.ts b/src/Stack.ts index 3d328a4..5f792fe 100644 --- a/src/Stack.ts +++ b/src/Stack.ts @@ -1,7 +1,7 @@ import {EmittenCommon} from 'emitten'; import {getErrorMessage, fetchAudioBuffer, scratchBuffer} from './helpers'; -import {clamp, msToSec, secToMs} from './utilities'; +import {arrayShallowEquals, clamp, msToSec, secToMs} from './utilities'; import {tokens} from './tokens'; import type { @@ -211,8 +211,16 @@ export class Stack extends EmittenCommon { } #setQueue(value: Sound[]) { + const oldKeys = this._keys; + const newKeys = value.map(({id}) => id); + const identicalKeys = arrayShallowEquals(oldKeys, newKeys); + this.#queue = value; - this._keys = value.map(({id}) => id); + this._keys = newKeys; + + if (!identicalKeys) { + this.emit('queue', newKeys, oldKeys); + } } #setState(value: StackState) { diff --git a/src/types.ts b/src/types.ts index 2765807..8329955 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,6 +51,7 @@ export interface StackError { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type StackEventMap = { state: (current: StackState) => void; + queue: (newKeys: SoundId[], oldKeys: SoundId[]) => void; volume: (level: number) => void; mute: (muted: boolean) => void; error: (message: StackError) => void;