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!: allow blocks to receive their own delete events #6337

Merged
merged 18 commits into from
Aug 16, 2022

Conversation

BeksOmega
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

#6319

Proposed Changes

Allows blocks to receive their own dispose events.

Behavior Before Change

Change listeners would be removed, and then dispose events would be fired (so blocks would not receive their own dispose events).

Behavior After Change

Dispose events are fired and then change listeners are removed (so blocks do receive their own dispose events).

Reason for Changes

Sometimes blocks need to clean up state when they are disposed, this allows that to happen.

Test Coverage

  • Dispose events are properly received.
  • Procedure caller blocks continue to delete themselves when their definitions are deleted.

Documentation

It would be nice if we had some documentation about block lifecycle.

Additional Information

@cpcallen I had to move the block tests back into the main mocha folder to get them to run. Would love to know what I need to do to get them to run from the mocha/blocks directory.

Breaking Changes

This is a breaking change, because it could cause event listeners to be triggered when they were not previously. In particular, if you are using a deny list instead of an allow list. The recommended solution is to use an allow list in your change handler instead of a deny list.

@BeksOmega BeksOmega requested a review from a team as a code owner August 11, 2022 22:43
Copy link
Contributor

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

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

Approved subject to minor nits.

I'm not sure what's up with you having to move the test files in order for them to run. Can you be more specific about how they were failing. Were they just being ignored?

In the mean time: would it be better to rename the moved test files to tests/mocha/blocks_*_test.js (or …/libraryBlocks_*_test.js) to make it more clear what they are testing? (E.g. Blockly core doesn't really have any "lists" that need testing…)

tests/mocha/index.html Outdated Show resolved Hide resolved
@@ -980,7 +980,7 @@ const PROCEDURE_CALL_COMMON = {
Xml.domToWorkspace(xml, this.workspace);
Events.setGroup(false);
}
} else if (event.type === Events.BLOCK_DELETE) {
} else if (event.type === Events.BLOCK_DELETE && event.blockId != this.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking this is a breaking change and should probably be mentioned in the PR description, even if it's very unlikely to ever cause anyone an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this is a breaking change. Before blocks did not receive their own events, so this case would have never been hit. Now I've added the blockId check so it continues to not be hit.

Copy link
Contributor

Choose a reason for hiding this comment

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

onchange is not private, so it could be called by code outside Blockly, which could pass in an arbitrary event.

I agree this is unlikely in practice, which is why I said "strictly speaking". It's probably not useful to bump a major version number or to mention in the release notes, but it probably is worth making sure that I am not the only one who has considered this scenario, and hence the comment.

tests/mocha/procedures_test.js Outdated Show resolved Hide resolved
@BeksOmega
Copy link
Collaborator Author

I'm not sure what's up with you having to move the test files in order for them to run. Can you be more specific about how they were failing. Were they just being ignored?

They were just being ignored :/

In the mean time: would it be better to rename the moved test files to tests/mocha/blocks_test.js (or …/libraryBlocks_test.js) to make it more clear what they are testing? (E.g. Blockly core doesn't really have any "lists" that need testing…)

I would prefer to fix whatever the issue is. I think they were actually originally prefixed with block_ and moved into a separate directory for organizational purposes lol. But if there's no obvious solution I'm happy to rename them.

@cpcallen
Copy link
Contributor

I'm not sure what's up with you having to move the test files in order for them to run. Can you be more specific about how they were failing. Were they just being ignored?

They were just being ignored :/

I would prefer to fix whatever the issue is. I think they were actually originally prefixed with block_ and moved into a separate directory for organizational purposes lol. But if there's no obvious solution I'm happy to rename them.

Having noticed a bunch of resource not found errors in the console when running mocha tests in develop, I'm 95% sure the problem is files in tests/moca/blocks/ trying to import from '../../build/… instead of ../../../build/….

@BeksOmega BeksOmega added PR: feature Adds a feature component: events breaking change Used to mark a PR or issue that changes our public APIs. labels Aug 15, 2022
@BeksOmega BeksOmega merged commit e9920a5 into google:develop Aug 16, 2022
@cpcallen
Copy link
Contributor

I had a quick look at the final version of this PR, and it LGTM, but the post-review commit history is so convoluted that I would not say I was exactly happy to see it submitted based on my earlier approval. A judicious force-push to consolidate all the post-review changes into one or two easy-to-vet commits would definitely have made this less worrying.

@BeksOmega BeksOmega deleted the feat/delete-events branch October 4, 2022 18:08
@BeksOmega BeksOmega removed the breaking change Used to mark a PR or issue that changes our public APIs. label Dec 1, 2022
@BeksOmega BeksOmega restored the feat/delete-events branch December 1, 2022 22:11
@BeksOmega BeksOmega deleted the feat/delete-events branch December 1, 2022 22:11
@BeksOmega BeksOmega restored the feat/delete-events branch December 1, 2022 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants