Skip to content

Commit

Permalink
chore: prefer direct initialization instead of constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ascpixi committed Dec 24, 2024
1 parent 649cfa3 commit 78a59f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 48 deletions.
8 changes: 3 additions & 5 deletions src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ export function toAugmented<T>(array: T[]): ArrayProcessor<T> {
* Allows for extended functionality when modifying arrays.
*/
export class ArrayProcessor<T> {
array: T[];

constructor (arr: T[]) {
this.array = arr;
}
constructor (
private array: T[]
) {}

collect() { return this.array; }

Expand Down
30 changes: 6 additions & 24 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ export type BaseNodeData = Record<string, unknown> & {
export abstract class NoteGeneratorNodeData<TParamType extends string = string> implements BaseNodeData {
[x: string]: unknown;

nodeType: "NOTES";
nodeType = "NOTES" as const;
abstract generator: PlainNoteGenerator | ParametricNoteGenerator<TParamType>;

constructor () {
this.nodeType = "NOTES";
}
}

/**
Expand All @@ -58,15 +54,10 @@ export abstract class NoteGeneratorNodeData<TParamType extends string = string>
export abstract class InstrumentNodeData implements BaseNodeData {
[x: string]: unknown;

nodeType: "INSTRUMENT";
parameters: { [handleName: string]: Automatable };
nodeType = "INSTRUMENT" as const;
parameters: { [handleName: string]: Automatable } = {};

abstract generator: AudioGenerator;

constructor () {
this.nodeType = "INSTRUMENT";
this.parameters = {};
}
};

/**
Expand All @@ -75,15 +66,10 @@ export abstract class InstrumentNodeData implements BaseNodeData {
export abstract class EffectNodeData implements BaseNodeData {
[x: string]: unknown;

nodeType: "EFFECT";
parameters: { [handleName: string]: Automatable };
nodeType = "EFFECT" as const;
parameters: { [handleName: string]: Automatable } = {};

abstract effect: AudioEffect;

constructor () {
this.nodeType = "EFFECT";
this.parameters = {};
}
}

/**
Expand All @@ -93,12 +79,8 @@ export abstract class EffectNodeData implements BaseNodeData {
export abstract class ValueNodeData implements BaseNodeData {
[x: string]: unknown;

nodeType: "VALUE";
nodeType = "VALUE" as const;
abstract generator: ValueGenerator;

constructor () {
this.nodeType = "VALUE";
}
}

export type NoInputs<T> = { [paramName in keyof never]: T };
Expand Down
8 changes: 1 addition & 7 deletions src/nodes/LfoNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ function biToUni(x: number) {
}

export class LfoNodeData extends ValueNodeData {
generator: LfoValueGenerator;

constructor () {
super();

this.generator = new LfoValueGenerator();
}
generator = new LfoValueGenerator();
};

export class LfoValueGenerator implements ValueGenerator {
Expand Down
7 changes: 1 addition & 6 deletions src/nodes/PentatonicChordsNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ export class PentatonicChordsGenerator implements PlainNoteGenerator {
}

export class PentatonicChordsNodeData extends NoteGeneratorNodeData {
generator: PentatonicChordsGenerator;

constructor () {
super();
this.generator = new PentatonicChordsGenerator();
}
generator = new PentatonicChordsGenerator();
};

export class PentatonicChordsNodeSerializer implements NodeDataSerializer<PentatonicChordsNodeData> {
Expand Down
7 changes: 1 addition & 6 deletions src/nodes/PentatonicMelodyNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ export class PentatonicMelodyGenerator implements PlainNoteGenerator {
}

export class PentatonicMelodyNodeData extends NoteGeneratorNodeData {
generator: PentatonicMelodyGenerator;

constructor () {
super();
this.generator = new PentatonicMelodyGenerator();
}
generator = new PentatonicMelodyGenerator();
};

export class PentatonicMelodyNodeSerializer implements NodeDataSerializer<PentatonicMelodyNodeData> {
Expand Down

0 comments on commit 78a59f3

Please sign in to comment.