Skip to content

Trigger transforms on siblings - #964

Merged
zurfyx merged 3 commits into
invariant-remove-childrenfrom
trigger-siblings
Dec 9, 2021
Merged

zurfyx merged 3 commits into
invariant-remove-childrenfrom
trigger-siblings

Conversation

@zurfyx

@zurfyx zurfyx commented Dec 7, 2021

Copy link
Copy Markdown
Member

To prevent subtrees triggering transforms in #953 we first have to trigger transforms on siblings.

I'll follow up on these:

  • Explore if we can introduce the IntentionallyMarkedAsDirty to prevent these from running on the reconciler
  • Dirty subtrees should no longer trigger on transforms

@zurfyx
zurfyx requested review from acywatson and trueadm December 7, 2021 12:23
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 7, 2021
@zurfyx
zurfyx changed the base branch from main to invariant-remove-children December 7, 2021 12:24
node.isAttached() &&
// You shouldn't be able to transform these types of
// nodes.
!node.isImmutable() &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trueadm - Transforms have to trigger on immutable nodes, otherwise they'll never be able to listen to changes. I.e. a DelightNode has to trigger when a sibling is removed

(isTextNode(previousSibling) &&
previousSibling.isSimpleText() &&
previousSibling.getTextContent().endsWith(' '));
const nextIsNullOrSpace =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could isNullOrSpace be separate function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@acywatson - Really good idea. I'll move it NodeHelpers and add the LineBreak check that we have on WWW since surprisingly this function can come useful on a few plugins.

init();
const executeTransform = jest.fn();
let hasBeenRemoved = false;
const listener = editor.addTransform(TextNode, (node) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: call it removeListener so it's more clear what's happening when you invoke it below.

removeTransform();
});

it('on remove', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: more descriptive descriptions might make these tests a bit easier to understand.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@acywatson - There's a describe above, this just complements it. So this reads like transforms on siblings > on remove

@zurfyx
zurfyx merged this pull request into invariant-remove-children Dec 9, 2021
@zurfyx
zurfyx deleted the trigger-siblings branch December 10, 2021 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants