Skip to content

Commit 732c4ac

Browse files
committed
add scheme primitive representation to cse machine
1 parent 4946e19 commit 732c4ac

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/features/cseMachine/CseMachineUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
Primitive,
4646
ReferenceType
4747
} from './CseMachineTypes';
48+
import { isCustomPrimitive } from './utils/altLangs';
4849

4950
// TODO: can make use of lodash
5051
/** Returns `true` if `x` is an object */
@@ -142,7 +143,14 @@ export function isBoolean(data: Data): data is boolean {
142143

143144
/** Returns `true` if `data` is a primitive, defined as a null | data | number */
144145
export function isPrimitiveData(data: Data): data is Primitive {
145-
return isUndefined(data) || isNull(data) || isString(data) || isNumber(data) || isBoolean(data);
146+
return (
147+
isUndefined(data) ||
148+
isNull(data) ||
149+
isString(data) ||
150+
isNumber(data) ||
151+
isBoolean(data) ||
152+
isCustomPrimitive(data)
153+
);
146154
}
147155

148156
// TODO: remove this in the future once ES typings are updated to contain the new set functions

src/features/cseMachine/components/Text.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Config, ShapeDefaultProps } from '../CseMachineConfig';
66
import { Layout } from '../CseMachineLayout';
77
import { Data, IHoverable } from '../CseMachineTypes';
88
import { getTextWidth, setHoveredCursor, setUnhoveredCursor } from '../CseMachineUtils';
9+
import { isCustomPrimitive } from '../utils/altLangs';
910
import { Visible } from './Visible';
1011

1112
export interface TextOptions {
@@ -48,9 +49,13 @@ export class Text extends Visible implements IHoverable {
4849

4950
const { fontSize, fontStyle, fontFamily, maxWidth, isStringIdentifiable } = this.options;
5051

51-
this.fullStr = this.partialStr = isStringIdentifiable
52-
? JSON.stringify(data) || String(data)
53-
: String(data);
52+
this.fullStr = this.partialStr =
53+
// if the data is a custom primitive, use its toString method
54+
isCustomPrimitive(data)
55+
? String(data)
56+
: isStringIdentifiable
57+
? JSON.stringify(data) || String(data)
58+
: String(data);
5459
this._height = fontSize;
5560
const widthOf = (s: string) => getTextWidth(s, `${fontStyle} ${fontSize}px ${fontFamily}`);
5661
if (widthOf(this.partialStr) > maxWidth) {

0 commit comments

Comments
 (0)