Skip to content

Text.equals extension/change #5733

Open
@work-in-progress-danny

Description

@work-in-progress-danny

Problem
When comparing two text nodes with Text.equals() , currently only text is omitted from the object when loose: true is provided. I want to compare two text nodes that will always have unique ids.

type TextNode = {
	id: string
	text: string
	bold?: boolean
	italic?: boolean
	underline?: boolean
}

Solution
I'm thinking of two possible solutions depending on the appetite of everyone.

  1. expose the isDeepEqual function from utils underlying the Text.equals check and let me roll my own equality function

or

  1. add an additional prop to the Text.equals function allowing me to pass in my own omission function something like
const omitTextAndIds = (obj: TextNode) => {
	const { text, id, ...rest } = obj
	return rest
}

Text.equals(nodeA, nodeB, {loose: true, omitFunc: omitTextAndIds})

Alternatives
I just run my own omit function on the nodes before I pass them into the equals function 🤔

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions