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

Example with AJAX request #62

Open
hdriqi opened this issue Jan 11, 2017 · 4 comments
Open

Example with AJAX request #62

hdriqi opened this issue Jan 11, 2017 · 4 comments

Comments

@hdriqi
Copy link

hdriqi commented Jan 11, 2017

Can someone provide best practice for ajax request and yo yo template?

@juliangruber
Copy link
Contributor

juliangruber commented Jan 11, 2017

ajax and templates are two different problem domains and yo yo doesn't aim to solve them both - unlike say jQuery.

There's a bunch of ways you can do Ajax, like the xhr library on npm, or the new fetch api.

If your question is more about the asynchronous nature of ajax requests, can you elaborate more?

@hdriqi
Copy link
Author

hdriqi commented Jan 11, 2017

@juliangruber yes, it is more on asynchronous.
For example I want to do ajax request and after that update using yo.update

What is the best way to do that, is it by doing ajax request at the root node and after the data has been received use yo.update(treeID, newTree) ??

@juliangruber
Copy link
Contributor

can you maybe post a code example of what you're doing? not quite sure i follow your example

@hdriqi
Copy link
Author

hdriqi commented Jan 11, 2017

function ajaxReq(){
    doAjaxRequest
    .done((newData) => {
        var newMain = main(newData)
        yo.update(main(), newMain)
    })
}

function main (data) {
  return yo`
    <div>
      ${data}
    </div>
  `
}

yo.update(document.body.firstChild, main())
ajaxReq()

Is this a good practice for doing ajax request?

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

No branches or pull requests

2 participants