Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom compare node props #4889

Merged
merged 2 commits into from
Mar 14, 2022

Conversation

zhugexinxin
Copy link
Contributor

Description
add custom compare node props

Example
node = { type: 'p', attributes: { hidden: true } }

Context
If you don't do it, you may create an infinite loop when setting properties

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2022

⚠️ No Changeset found

Latest commit: ec93a84

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zhugexinxin could you please add a test showing what is failing currently that passes after this PR lands? Thanks!

@zhugexinxin
Copy link
Contributor Author

zhugexinxin commented Mar 13, 2022

Hi @zhugexinxin could you please add a test showing what is failing currently that passes after this PR lands? Thanks!

I'm not very good at testing, but I'm willing to try.
For the infinite loop test, I don't know how to write it, maybe I have to understand the jest api.

this is demo url https://codesandbox.io/s/xenodochial-gould-j35v1o?file=/src/App.js

let hasChanges = false

for (const k in props) {
  if (k === 'children' || k === 'text') {
    continue
  }

  if (props[k] !== node[k]) {
    hasChanges = true
    // Omit new properties from the old properties list
    if (node.hasOwnProperty(k)) properties[k] = node[k]
    // Omit properties that have been removed from the new properties list
    if (props[k] != null) newProperties[k] = props[k]
  }
}

if (hasChanges) {
  editor.apply({
    type: 'set_node',
    path,
    properties,
    newProperties,
  })
}

hasChanges always true

@zhugexinxin zhugexinxin force-pushed the add_custom_compare branch 5 times, most recently from dc6f83b to 8f3f26f Compare March 14, 2022 00:17
@zhugexinxin
Copy link
Contributor Author

zhugexinxin commented Mar 14, 2022

I don't know where is the problem at the moment and may need help and hints
I seem to be missing something, I'll fix this when I have time

@zhugexinxin
Copy link
Contributor Author

tests have been added

@zhugexinxin zhugexinxin requested a review from dylans March 14, 2022 15:19
@dylans dylans merged commit 970523f into ianstormtaylor:main Mar 14, 2022
@zhugexinxin
Copy link
Contributor Author

zhugexinxin commented Mar 15, 2022

@dylans
test:integration fail, but it succeeded on the local machine.
I really need this new version, what help do I need.

image

@dylans
Copy link
Collaborator

dylans commented Mar 15, 2022

@dylans test:integration fail, but it succeeded on the local machine. I really need this new version, what help do I need.

image

Integration tests are somewhat flaky on GitHub Actions and timeout prematurely. I'll push an updated release now.

dylans added a commit to dylans/slate that referenced this pull request Mar 15, 2022
dylans added a commit that referenced this pull request Mar 15, 2022
@github-actions github-actions bot mentioned this pull request Mar 15, 2022
@zhugexinxin
Copy link
Contributor Author

zhugexinxin commented Mar 15, 2022

@dylans test:integration fail, but it succeeded on the local machine. I really need this new version, what help do I need.
image

Integration tests are somewhat flaky on GitHub Actions and timeout prematurely. I'll push an updated release now.

thank you!

@BitPhinix
Copy link
Contributor

BitPhinix commented Mar 16, 2022

I'm not sure I get why compare is needed here. I don't really get the problem it solves. Couldn't the normalizeNode simply be written in a slightly different way to avoid an infinite loop?

DougReeder pushed a commit to DougReeder/slate that referenced this pull request Apr 3, 2022
* feat: add custom compare props

* chore: add test for custom compare props
DougReeder pushed a commit to DougReeder/slate that referenced this pull request Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants