Skip to content

Commit 78029b3

Browse files
committed
Use stepType rather than classnames for recognising steps
1 parent 00b4cc5 commit 78029b3

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

src/pmToAm.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export default function (
3131

3232
for (const step of steps) {
3333
//console.log(step)
34-
if (isAddMarkStep(step)) {
35-
unappliedMarks.push(step)
34+
const stepId = step.toJSON()["stepType"]
35+
if (stepId === "addMark") {
36+
unappliedMarks.push(step as AddMarkStep)
3637
continue
3738
} else {
3839
flushMarks()
3940
}
40-
oneStep(spans, step, doc, pmDoc, path)
41+
oneStep(spans, stepId, step, doc, pmDoc, path)
4142
const nextDoc = step.apply(pmDoc).doc
4243
if (nextDoc == null) {
4344
throw new Error("Could not apply step to document")
@@ -50,41 +51,22 @@ export default function (
5051

5152
function oneStep(
5253
spans: am.Span[],
54+
stepId: string,
5355
step: Step,
5456
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5557
doc: any,
5658
pmDoc: Node,
5759
path: Prop[],
5860
) {
59-
// This shenanigans with the constructor name is necessary for reasons I
60-
// don't really understand. I _think_ that the `*Step` classs we get
61-
// passed here can be slightly different to the classes we've imported if the
62-
// dependencies are messed up
63-
if (
64-
step.constructor.name === "ReplaceStep" ||
65-
step.constructor.name === "_ReplaceStep"
66-
) {
61+
if (stepId === "replace") {
6762
replaceStep(spans, step as ReplaceStep, doc, path, pmDoc)
68-
} else if (
69-
step.constructor.name === "ReplaceAroundStep" ||
70-
step.constructor.name === "_ReplaceAroundStep"
71-
) {
63+
} else if (stepId === "replaceAround") {
7264
replaceAroundStep(step as ReplaceAroundStep, doc, pmDoc, path)
73-
} else if (
74-
step.constructor.name === "RemoveMarkStep" ||
75-
step.constructor.name === "_RemoveMarkStep"
76-
) {
65+
} else if (stepId === "removeMark") {
7766
removeMarkStep(spans, step as RemoveMarkStep, doc, path)
7867
}
7968
}
8069

81-
function isAddMarkStep(step: Step): step is AddMarkStep {
82-
return (
83-
step.constructor.name === "AddMarkStep" ||
84-
step.constructor.name === "_AddMarkStep"
85-
)
86-
}
87-
8870
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8971
function replaceStep(
9072
spans: am.Span[],

0 commit comments

Comments
 (0)