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

More detailed explanation for function prepareInterface() #701

Closed
docahrens opened this issue Feb 25, 2016 · 4 comments
Closed

More detailed explanation for function prepareInterface() #701

docahrens opened this issue Feb 25, 2016 · 4 comments
Assignees

Comments

@docahrens
Copy link

The last example including the function prepareInterface() looks like a great example with lots to learn, but the explanation of the most difficult aspect of the example is lacking. In regard to prepareInterface(), it says:
"The application also has a function (prepareInterface()) which returns a promise to complete animating our containers for both the news and reactions."

It would be very useful to see a much more detailed explanation of what is happening in prepareInterface() and how it is useful. I am new to the idea of deferreds and promises, and unfortunately, it was not at all obvious to me what is happening in that method. Seems like a tutorial would be an excellent place for such an explanation...

@docahrens docahrens changed the title More detailed explanation for function (prepareInterface() More detailed explanation for function prepareInterface() Feb 25, 2016
@agcolom
Copy link
Member

agcolom commented Mar 2, 2016

Here's a link to the article: http://learn.jquery.com/code-organization/deferreds/jquery-deferreds/ for ref. @timmywil @dmethvin @jaubourg Could you please take a look and suggest how to go about this? Thanks

@dmethvin
Copy link
Member

dmethvin commented Mar 2, 2016

The example confuses me as well! It seems like you would not want to show the two sections until the data is filled, in which case the code should look like this?

// Assume .news and .reactions are initially hidden
$.when(
    getLatestNews(),
    getLatestReactions()
).then(
    prepareInterface
)
...

The magic in prepareInterface is somewhat deep because it creates a new Deferred and uses dfd.resolve in the animation callback. Would this be clearer with a different name?

function showAjaxedContent() {
    return $( ".news, .reactions" ).slideDown( 500, function() {
       $(this).addClass( "active" );
    }).promise();
}

@agcolom
Copy link
Member

agcolom commented Mar 9, 2016

@docahrens would the suggestion by @dmethvin solve your issue? Thanks

@kswedberg
Copy link
Member

Fixed in 9878874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants