1
Hello I’m new and just turn in js currently using vueJs. but I still can’t turn normal process into async await, nor with promise, the old way.
I know I have to get it into my head.
I have a way in vuejs.
Carregar(data) {
let posicaoscroll = window.scrollY
data.map(res => this.messages.unshift(res))
window.scrollTo(0, posicaoscroll)
}
Sometimes when I run it works by putting the data at the beginning of the array to make a progressive message upload, the scroll changes position so I use it to continue in msm place more is insert hour works no time. I believe one is being faster than another by the characteristic of js.
then how to transform this function into something that only after doing
data.map(res => this.messages.unshift(res))
execute
window.scrollTo(0, posicaoscroll)
Thanks in advance.
Thanks for the tip from the foreach ;)
– Sidiclei F. Almeida
It is worth remembering that when using the foreach the looping becomes asynchronous ie, the function will not wait for the looping to finish to pass to the next instruction as with the map.
– Felipe Duarte
Felipe Duarte Negativo, the looping structure follows the same basic principle for all Javascript Declarative features(foreach, some, Every, map, reduce, filter among others...).
– cpurificacao
The execution remains procedural and synchronous with both, the execution of the foreach uses a conventional loop for (Imperative) to run the callback passed to each item of the supplied array!
– cpurificacao