[wp-trac] [WordPress Trac] #38797: api.previewer.refresh() could return a deferred.promise() with custom server data

WordPress Trac noreply at wordpress.org
Tue Jan 24 19:18:10 UTC 2017


#38797: api.previewer.refresh() could return a deferred.promise() with custom
server data
-------------------------+-----------------------------
 Reporter:  nikeo        |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Customize    |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |     Focuses:  javascript
-------------------------+-----------------------------

Comment (by nikeo):

 @celloexpressions this is a proposition of implementation for the refresh
 promise.
 I've also created a small plugin to test it with TwentySeventeen :
 https://gist.github.com/Nikeo/86eeff438fb6e23b1da0a74a89dd8199

 **Changes in wp-admin/customize-control.js :**
 I had to adapt the original debounced refresh because `_.debounce` won't
 work properly with a promise object. The proposed code should normally do
 the same job with `setTimeout`. The `originaRefresh.call( previewer )` is
 now replaced by `api.Previewer.prototype.refresh.call( previewer )`

 The `onceSynced` event now takes the `server_data` as params and resolves
 the `$.Deferred` object with it.

 **Changes in wp-includes/customize-preview.js :**
 The idea is to allow developer to hook on the `synced` event, and send for
 example contextual informations to the panel.
 I have introduced a new api.Value to store those data :
 `api.server_data()` and a `before_synced` event to set it.

 The gist example illustrates a possible use of this code to send the post
 informations to the panel in a is_singular context.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38797#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list