Skip to content

Commit

Permalink
Abstract Base Classes
Browse files Browse the repository at this point in the history
Learning again why currently TS doesn't support a way to use `abstract static` unfortunately.

microsoft/TypeScript#34516

Eeps!
  • Loading branch information
Offroaders123 committed Feb 23, 2024
1 parent 29a9a98 commit 49cb810
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/ArrayFileReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ArrayFileReader extends MediaFileReader {
);
}

override init(callbacks: LoadCallbackType): void {
override _init(callbacks: LoadCallbackType): void {
setTimeout(callbacks.onSuccess, 0);
}

Expand Down
14 changes: 4 additions & 10 deletions src/MediaFileReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
CharsetType
} from './FlowTypes';

class MediaFileReader {
abstract class MediaFileReader {
_isInitialized: boolean;
_size: number;

Expand Down Expand Up @@ -50,17 +50,13 @@ class MediaFileReader {
}
}

_init(callbacks: LoadCallbackType): void {
throw new Error("Must implement init function");
}
abstract _init(callbacks: LoadCallbackType): void;

/**
* @param range The start and end indexes of the range to load.
* Ex: [0, 7] load bytes 0 to 7 inclusive.
*/
loadRange(range: [number, number], callbacks: LoadCallbackType): void {
throw new Error("Must implement loadRange function");
}
abstract loadRange(range: [number, number], callbacks: LoadCallbackType): void;

/**
* @return The size of the file in bytes.
Expand All @@ -73,9 +69,7 @@ class MediaFileReader {
return this._size;
}

getByteAt(offset: number): number {
throw new Error("Must implement getByteAt function");
}
abstract getByteAt(offset: number): number;

getBytesAt(offset: number, length: number): Array<number> {
var bytes = new Array(length);
Expand Down
12 changes: 4 additions & 8 deletions src/MediaTagReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
TagType
} from './FlowTypes';

class MediaTagReader {
abstract class MediaTagReader {
_mediaFileReader: MediaFileReader;
_tags: Array<string> | null;

Expand Down Expand Up @@ -80,19 +80,15 @@ class MediaTagReader {
/**
* Load the necessary bytes from the media file.
*/
_loadData(
abstract _loadData(
mediaFileReader: MediaFileReader,
callbacks: LoadCallbackType
): void {
throw new Error("Must implement _loadData function");
}
): void;

/**
* Parse the loaded data to read the media tags.
*/
_parseData(mediaFileReader: MediaFileReader, tags: Array<string> | null): TagType {
throw new Error("Must implement _parseData function");
}
abstract _parseData(mediaFileReader: MediaFileReader, tags: Array<string> | null): TagType;

_expandShortcutTags(tagsWithShortcuts: Array<string> | null): Array<string> | null {
if (!tagsWithShortcuts) {
Expand Down

0 comments on commit 49cb810

Please sign in to comment.