max-mapper / yo-yo

A tiny library for building modular UI components using DOM diffing and ES6 tagged template literals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example with AJAX request

hdriqi opened this issue · comments

commented

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

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?

commented

@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) ??

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

commented
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?