Skip to content

Commit 7ec0ee9

Browse files
committed
[PR feedback] Abstract classes!!! 🧙
1 parent cfcb1ad commit 7ec0ee9

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

src/components/text_truncate/utils.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ type CanvasParams = SharedParams &
3535
* which works by building up from an empty string / by adding characters
3636
* instead of removing them.
3737
*/
38-
class _TruncationUtils {
39-
fullText: SharedParams['fullText'];
40-
ellipsis: SharedParams['ellipsis'];
41-
availableWidth: SharedParams['availableWidth'];
38+
abstract class _TruncationUtils {
39+
protected fullText: SharedParams['fullText'];
40+
protected ellipsis: SharedParams['ellipsis'];
41+
protected availableWidth: SharedParams['availableWidth'];
4242

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

61-
/* istanbul ignore next */
62-
get textWidth(): number {
63-
throw new Error('This function must be superseded by a DOM or Canvas util');
64-
}
65-
66-
/* istanbul ignore next */
67-
setTextToCheck = (_: string): void => {
68-
throw new Error('This function must be superseded by a DOM or Canvas util');
69-
};
54+
abstract textWidth: number;
55+
abstract setTextToCheck: (text: string) => void;
7056

7157
/**
7258
* Early return checks

0 commit comments

Comments
 (0)