Skip to content

Commit

Permalink
[PR feedback] Abstract classes!!! 🧙
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Aug 31, 2023
1 parent cfcb1ad commit 7ec0ee9
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/components/text_truncate/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type CanvasParams = SharedParams &
* which works by building up from an empty string / by adding characters
* instead of removing them.
*/
class _TruncationUtils {
fullText: SharedParams['fullText'];
ellipsis: SharedParams['ellipsis'];
availableWidth: SharedParams['availableWidth'];
abstract class _TruncationUtils {
protected fullText: SharedParams['fullText'];
protected ellipsis: SharedParams['ellipsis'];
protected availableWidth: SharedParams['availableWidth'];

constructor({ fullText, ellipsis, availableWidth }: SharedParams) {
this.fullText = fullText;
Expand All @@ -49,24 +49,10 @@ class _TruncationUtils {
/**
* Internal measurement utils which will be overridden depending on the
* rendering approach used (e.g. DOM vs Canvas).
*
* The thrown errors are there to ensure the base instance utils do not
* get called standalone in the future, if more extended classes are added
* someday (e.g. new shadow DOM tech, or Flash makes a surprise comeback).
*
* The istanbul code coverage ignores are there because this base class
* is not exported and in theory the code should never be reachable.
*/

/* istanbul ignore next */
get textWidth(): number {
throw new Error('This function must be superseded by a DOM or Canvas util');
}

/* istanbul ignore next */
setTextToCheck = (_: string): void => {
throw new Error('This function must be superseded by a DOM or Canvas util');
};
abstract textWidth: number;
abstract setTextToCheck: (text: string) => void;

/**
* Early return checks
Expand Down

0 comments on commit 7ec0ee9

Please sign in to comment.