Skip to content

Commit

Permalink
wip Stack queue event
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Dec 22, 2023
1 parent a81a5b0 commit f509ee9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Stack.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -211,8 +211,16 @@ export class Stack extends EmittenCommon<StackEventMap> {
}

#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) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f509ee9

Please sign in to comment.