Skip to content

Commit

Permalink
🎨 [Format] All earwurm folder files
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Jul 30, 2024
1 parent d816f74 commit 75f522a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 39 deletions.
22 changes: 12 additions & 10 deletions pkg/earwurm/src/Earwurm.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {arrayShallowEquals, clamp, getErrorMessage} from 'beeftools';
import {arrayEquals, clamp, getErrorMessage} from 'beeftools';
import {EmittenCommon} from 'emitten';
import {linearRamp, unlockAudioContext} from '@earwurm/helpers';

import {Stack} from './Stack';
import {tokens} from './tokens';
import type {
ManagerState,
ManagerEventMap,
ManagerConfig,
LibraryEntry,
StackId,
ManagerConfig,
ManagerEventMap,
ManagerState,
StackEventMap,
StackId,
} from './types';

export class Earwurm extends EmittenCommon<ManagerEventMap> {
Expand Down Expand Up @@ -197,9 +197,9 @@ export class Earwurm extends EmittenCommon<ManagerEventMap> {

suspend() {
if (
this._state === 'closed' ||
this._state === 'suspended' ||
this._state === 'suspending'
this._state === 'closed'
|| this._state === 'suspended'
|| this._state === 'suspending'
) {
return this;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export class Earwurm extends EmittenCommon<ManagerEventMap> {
#setLibrary(library: Stack[]) {
const oldKeys = [...this._keys];
const newKeys = library.map(({id}) => id);
const identicalKeys = arrayShallowEquals(oldKeys, newKeys);
const identicalKeys = arrayEquals(oldKeys, newKeys);

this.#library = library;
this._keys = newKeys;
Expand All @@ -275,7 +275,9 @@ export class Earwurm extends EmittenCommon<ManagerEventMap> {

if (value === 'running') {
this._unlocked = true;
} else if (value === 'closed') {
}
// TODO: This should not be broken onto a separate line.
else if (value === 'closed') {
this._unlocked = false;
}

Expand Down
24 changes: 13 additions & 11 deletions pkg/earwurm/src/Sound.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {clamp, calcProgress} from 'beeftools';
import {calcProgress, clamp} from 'beeftools';
import {EmittenCommon} from 'emitten';
import {linearRamp} from '@earwurm/helpers';

import {tokens} from './tokens';
import type {
SoundId,
SoundState,
SoundConfig,
SoundEventMap,
SoundId,
SoundProgressEvent,
SoundConfig,
SoundState,
} from './types';

export class Sound extends EmittenCommon<SoundEventMap> {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Sound extends EmittenCommon<SoundEventMap> {
}

private get hasProgressSub() {
return this.activeEvents.some((event) => event === 'progress');
return this.activeEvents.includes('progress');
}

private get transDuration() {
Expand Down Expand Up @@ -177,8 +177,8 @@ export class Sound extends EmittenCommon<SoundEventMap> {
// Not yet sure how to resolve this.
this.#incrementLoop();

const timeSince =
Math.max(this.context.currentTime - this.#timestamp, 0) * this.speed;
const timeSince
= Math.max(this.context.currentTime - this.#timestamp, 0) * this.speed;

this.#progress.elapsed = clamp(
0,
Expand Down Expand Up @@ -258,7 +258,9 @@ export class Sound extends EmittenCommon<SoundEventMap> {
this.#intervalId = this.hasProgressSub
? requestAnimationFrame(this.#handleInterval)
: 0;
} else {
}
// TODO: This should not be broken onto a separate line.
else {
cancelAnimationFrame(this.#intervalId);
this.#intervalId = 0;

Expand All @@ -273,9 +275,9 @@ export class Sound extends EmittenCommon<SoundEventMap> {
if (!this.loop) return;

if (
this.#progress.elapsed === this.duration ||
this.#progress.remaining === 0 ||
this.#progress.percentage === 100
this.#progress.elapsed === this.duration
|| this.#progress.remaining === 0
|| this.#progress.percentage === 100
) {
this.#progress.elapsed = 0;
this.#progress.remaining = this.duration;
Expand Down
14 changes: 7 additions & 7 deletions pkg/earwurm/src/Stack.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {arrayShallowEquals, clamp, getErrorMessage} from 'beeftools';
import {arrayEquals, clamp, getErrorMessage} from 'beeftools';
import {EmittenCommon} from 'emitten';
import {fetchAudioBuffer, linearRamp, scratchBuffer} from '@earwurm/helpers';

import {Sound} from './Sound';
import {tokens} from './tokens';
import type {
StackId,
StackState,
SoundEventMap,
SoundId,
StackConfig,
StackError,
StackEventMap,
StackConfig,
SoundId,
SoundEventMap,
StackId,
StackState,
} from './types';

export class Stack extends EmittenCommon<StackEventMap> {
Expand Down Expand Up @@ -212,7 +212,7 @@ export class Stack extends EmittenCommon<StackEventMap> {
#setQueue(value: Sound[]) {
const oldKeys = [...this._keys];
const newKeys = value.map(({id}) => id);
const identicalKeys = arrayShallowEquals(oldKeys, newKeys);
const identicalKeys = arrayEquals(oldKeys, newKeys);

this.#queue = value;
this._keys = newKeys;
Expand Down
2 changes: 1 addition & 1 deletion pkg/earwurm/src/tests/Abstract.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {afterEach, describe, it, expect, vi} from 'vitest';
import {afterEach, describe, expect, it, vi} from 'vitest';

import {Sound} from '../Sound';
import {tokens} from '../tokens';
Expand Down
6 changes: 3 additions & 3 deletions pkg/earwurm/src/tests/Earwurm.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {afterEach, describe, it, expect, vi} from 'vitest';
import {afterEach, describe, expect, it, vi} from 'vitest';
import {mockData} from '@earwurm/mocks';

import {Earwurm} from '../Earwurm';
import {Stack} from '../Stack';
import type {Sound} from '../Sound';

import type {
ManagerEventMap,
ManagerConfig,
LibraryEntry,
ManagerConfig,
ManagerEventMap,
StackId,
} from '../types';

Expand Down
6 changes: 4 additions & 2 deletions pkg/earwurm/src/tests/Sound.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {afterEach, describe, it, expect, vi} from 'vitest';
import {afterEach, describe, expect, it, vi} from 'vitest';

import {Sound} from '../Sound';
import {tokens} from '../tokens';
import type {SoundState, SoundEventMap} from '../types';
import type {SoundEventMap, SoundState} from '../types';

type SoundConstructor = ConstructorParameters<typeof Sound>;

Expand Down Expand Up @@ -459,6 +459,7 @@ describe('Sound component', () => {

expect(spyEnded).toBeCalledWith({
id: testSound.id,
// eslint-disable-next-line ts/no-unsafe-assignment
source: expect.any(AudioBufferSourceNode),
neverStarted: false,
});
Expand All @@ -477,6 +478,7 @@ describe('Sound component', () => {

expect(spyEnded).toBeCalledWith({
id: testSound.id,
// eslint-disable-next-line ts/no-unsafe-assignment
source: expect.any(AudioBufferSourceNode),
neverStarted: true,
});
Expand Down
6 changes: 4 additions & 2 deletions pkg/earwurm/src/tests/Stack.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {afterEach, describe, it, expect, vi} from 'vitest';
import {afterEach, describe, expect, it, vi} from 'vitest';
import {arrayOfLength} from 'beeftools';
import {mockData} from '@earwurm/mocks';

import {Stack} from '../Stack';
import {Sound} from '../Sound';
import {tokens} from '../tokens';
import type {StackEventMap, SoundEventMap} from '../types';
import type {SoundEventMap, StackEventMap} from '../types';

type StackConstructor = ConstructorParameters<typeof Stack>;

Expand Down Expand Up @@ -504,6 +504,7 @@ describe('Stack component', () => {

// Fill the `queue` up with the exact max number of Sounds.
const pendingSounds = arrayOfLength(tokens.maxStackSize).map(
// eslint-disable-next-line ts/return-await
async (_index) => await testStack.prepare(),
);

Expand Down Expand Up @@ -533,6 +534,7 @@ describe('Stack component', () => {

// Add more sounds before any current Sound has finished playing.
const additionalSounds = arrayOfLength(additionalSoundsCount).map(
// eslint-disable-next-line ts/return-await
async (_index) => await testStack.prepare(),
);

Expand Down
6 changes: 3 additions & 3 deletions pkg/earwurm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {CombinedErrorMessage} from '@earwurm/types';

export type ManagerState = AudioContextState | 'suspending' | 'interrupted';

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
// eslint-disable-next-line ts/consistent-type-definitions
export type ManagerEventMap = {
state: (current: ManagerState) => void;
play: (active: boolean) => void;
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface StackError {
message: CombinedErrorMessage;
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
// eslint-disable-next-line ts/consistent-type-definitions
export type StackEventMap = {
state: (current: StackState) => void;
queue: (newKeys: SoundId[], oldKeys: SoundId[]) => void;
Expand Down Expand Up @@ -75,7 +75,7 @@ export interface SoundProgressEvent {
iterations: number;
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
// eslint-disable-next-line ts/consistent-type-definitions
export type SoundEventMap = {
state: (current: SoundState) => void;
ended: (event: SoundEndedEvent) => void;
Expand Down

0 comments on commit 75f522a

Please sign in to comment.