Opened 8 years ago
Closed 7 years ago
#37269 closed enhancement (fixed)
Introduce removed event for wp.customize.Values collection
Reported by: | westonruter | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | Customize | Keywords: | has-patch has-unit-tests commit |
Focuses: | javascript | Cc: |
Description (last modified by )
Notifications were added to Customizer controls in #34893. Notifications are re-rendered when the control.notifications
collection (a wp.customize.Values
) has a wp.customize.Notification
added or removed with the code as follows (via wp.customize.Control#initialize
):
// After the control is embedded on the page, invoke the "ready" method. control.deferred.embedded.done( function () { /* * Note that this debounced/deferred rendering is needed for two reasons: * 1) The 'remove' event is triggered just _before_ the notification is actually removed. * 2) Improve performance when adding/removing multiple notifications at a time. */ var debouncedRenderNotifications = _.debounce( function renderNotifications() { control.renderNotifications(); } ); control.notifications.bind( 'add', function( notification ) { wp.a11y.speak( notification.message, 'assertive' ); debouncedRenderNotifications(); } ); control.notifications.bind( 'remove', debouncedRenderNotifications ); control.renderNotifications(); control.ready(); });
Notice the multi-line comment. We can't re-render the notifications at a remove
event because this event gets triggered just before it is removed, somewhat unexpectedly. We should therefore introduce a removed
event that gets triggered after the removal so that workarounds using debounce
or defer
aren't required.
Submitted patch should include unit test.
Change History (13)
This ticket was mentioned in Slack in #core by jorbin. View the logs.
8 years ago
This ticket was mentioned in Slack in #core-customize by celloexpressions. View the logs.
8 years ago
#8
@
8 years ago
- Keywords good-first-bug removed
- Owner set to delawski
- Status changed from new to assigned
@delawski nice. I added a code review comment.
#9
@
8 years ago
@westonruter Thank you for the review. I've added the condition as you suggested and also wrote additional unit test to cover case you've mentioned in the comment.
#10
@
8 years ago
- Keywords has-unit-tests commit added; needs-unit-tests removed
- Owner changed from delawski to westonruter
- Status changed from assigned to reviewing
Excellent. This can go into 4.8 as soon as trunk it open for enhancements.
#11
@
7 years ago
- Milestone changed from Future Release to 4.9
- Status changed from reviewing to accepted
I'm going to add this as part of #35210.
Can still make 4.7 if there's a patch, but we need a patch for now.