Skip to content

Commit

Permalink
refactor(portable-text-editor): simplify equality test
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Aug 17, 2022
1 parent 6a5c972 commit 9565cbd
Showing 1 changed file with 7 additions and 19 deletions.
Expand Up @@ -329,25 +329,13 @@ export class PortableTextEditor extends React.Component<
}

const isEqualToValue = !(this.props.value || []).some((blk, index) => {
if (this.slateInstance.isTextBlock(blk)) {
const compareBlock = toSlateValue(
[blk],
{portableTextFeatures: this.portableTextFeatures},
KEY_TO_SLATE_ELEMENT.get(this.slateInstance)
)[0]
if (!isEqual(compareBlock, this.slateInstance.children[index])) {
return true
}
} else {
const slateBlock = this.slateInstance.children[index]
if (
!slateBlock ||
(slateBlock &&
'value' in slateBlock &&
!isEqual(blk, {_key: slateBlock._key, _type: slateBlock._type, ...slateBlock.value}))
) {
return true
}
const compareBlock = toSlateValue(
[blk],
{portableTextFeatures: this.portableTextFeatures},
KEY_TO_SLATE_ELEMENT.get(this.slateInstance)
)[0]
if (!isEqual(compareBlock, this.slateInstance.children[index])) {
return true
}
return false
})
Expand Down

0 comments on commit 9565cbd

Please sign in to comment.