[wp-trac] [WordPress Trac] #38889: Proposition to allow an api.Value() using asynchronous callbacks
WordPress Trac
noreply at wordpress.org
Tue Nov 22 09:37:15 UTC 2016
#38889: Proposition to allow an api.Value() using asynchronous callbacks
-------------------------------+------------------------------
Reporter: nikeo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: trunk
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: javascript
-------------------------------+------------------------------
Comment (by nikeo):
@westonruter thanks for examples and use case.
If we continue with the same example of a section lazy loading its
controls, my goal is to do things when the section controls are all
embedded ( `fooSectionPopulated.done()` in your example ).
The question to address is : when is the section expansion actually done
?
1. Is it when its value has been set ?
2. Or is it when all its callback have finished their jobs ?
If we consider that a section is expanded as soon as its value is set,
then we might have issues using a code like this :
{{{
#!javascript
section( section_id )(true);
do_things_with_the_section_controls(); // <= some controls are not ready
yet
}}}
If we consider that the section is completely expanded when all its
callbacks are done, then it make sense to have a way to capture the
callbacks promises and to use this syntax :
{{{
#!javascript
section( section_id )(true).done( function() {
do_things_with_the_section_controls(); //<= yes we are sure that all
controls are ready because their promises are all resolved
} );
}}}
Our approaches differ in the sense that the promise of the section ready (
`fooSectionPopulated` ) is outside the callback, when I propose that the
callback returns the promise.
I agree that there are currently other ways to listen to the Value changes
(bind / unbind ). I wanted to propose a complement to the code ( which has
no impact if you don't specify the deferred param ), in order to allow
different syntaxes when using `api.Value()` with asynchronous callbacks.
Thanks for the discussion in any cases !
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38889#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list