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

Add props to withFilters #10195

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/components/src/higher-order/with-filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export default function withFilters( hookName ) {
/** @inheritdoc */
constructor( props ) {
super( props );
this.ComponentProps = applyFilters( hookName + 'Props', props );
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be called also inside throttledForceUpdate

Copy link
Member Author

Choose a reason for hiding this comment

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

good point - thanks for the feedback - addressed in 08f27c3. If you think this might be something we would adopt, I can take a pass at adding some tests.


this.onHooksUpdated = this.onHooksUpdated.bind( this );
this.Component = applyFilters( hookName, OriginalComponent );
this.namespace = uniqueId( 'core/with-filters/component-' );
this.throttledForceUpdate = debounce( () => {
this.Component = applyFilters( hookName, OriginalComponent );
this.ComponentProps = applyFilters( hookName + 'Props', props );
this.forceUpdate();
}, ANIMATION_FRAME_PERIOD );

Expand All @@ -54,14 +56,14 @@ export default function withFilters( hookName ) {
* @param {string} updatedHookName Name of the hook that was updated.
*/
onHooksUpdated( updatedHookName ) {
if ( updatedHookName === hookName ) {
if ( updatedHookName === hookName || updatedHookName === hookName + 'Props' ) {
this.throttledForceUpdate();
}
}

/** @inheritdoc */
render() {
return <this.Component { ...this.props } />;
return <this.Component { ...this.ComponentProps } />;
}
};
}, 'withFilters' );
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { noop, get } from 'lodash';
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { Button, withFilters } from '@wordpress/components';
import { Component, createRef } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
Expand Down Expand Up @@ -102,4 +102,5 @@ export default compose( [
onSave: savePost,
};
} ),
withFilters( 'editor.PostPublishButton' ),
] )( PostPublishButton );
3 changes: 2 additions & 1 deletion packages/editor/src/components/post-publish-panel/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { get } from 'lodash';
/**
* WordPress Dependencies
*/
import { Button } from '@wordpress/components';
import { Button, withFilters } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -83,4 +83,5 @@ export default compose( [
postType: getCurrentPostType(),
};
} ),
withFilters( 'editor.PostPublishPanelToggle' ),
] )( PostPublishPanelToggle );