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

Extensibility: Apply filters without function wrappers #3933

Merged
merged 2 commits into from
Dec 14, 2017

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Dec 12, 2017

Description

Raised by @aduth when working on converting all filters for the components to work as HOCs (#3827 (comment)):

Minor: Do we need to export these as functions anymore, or can they just call to addFilter when imported?

This PR explores if we can avoid exporting functions that enable filters for blocks. Instead we apply them directly in the same file when corresponding callbacks are defined.

How Has This Been Tested?

Unit tested.

Types of changes

Refactoring.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@gziolo gziolo added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Feature] Extensibility The ability to extend blocks or the editing experience labels Dec 12, 2017
@gziolo gziolo self-assigned this Dec 12, 2017
@gziolo gziolo requested a review from aduth December 12, 2017 07:34
@gziolo gziolo changed the title Update/hooks without wrappers Extensibility: Apply filters without function wrappers Dec 12, 2017
@@ -6,41 +6,31 @@ import { noop } from 'lodash';
/**
* WordPress dependencies
*/
import { applyFilters, removeAllFilters } from '@wordpress/hooks';
Copy link
Member

Choose a reason for hiding this comment

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

So the downside to this approach is that we can't clean up lingering handlers after tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Test files are isolated, so they should be cleaned up anyways. I hope 😄

Copy link
Member

Choose a reason for hiding this comment

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

Test files are isolated, so they should be cleaned up anyways. I hope 😄

Hmm, the require cache is cleared between each? Would be (good) news to me if true.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it isn’t the case only for mocks imported in Jest setup file.

You can enable reseting modules per test using resetModules config option or call it programmatically with the method called the same.

@gziolo
Copy link
Member Author

gziolo commented Dec 14, 2017

@aduth should I proceed with this PR? Let me know if you like it more? I'm convinced :)

@gziolo gziolo merged commit 79c3f34 into master Dec 14, 2017
@gziolo gziolo deleted the update/hooks-without-wrappers branch December 14, 2017 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants