Question
The Populate a repeater using static data example in onItemReady() documentation uses async function within onReady function.
Here’s the code from the documentation:
// Static array of objects, each containing a unique `_id` value
const staticData = [
{_id: '1', language: 'English', greeting: 'Hello World!'},
{_id: '2', language: 'French', greeting: 'Bonjour monde!'},
{_id: '3', language: 'Japanese', greeting: 'こんにちは世界!'},
{_id: '4', language: 'Portuguese', greeting: 'Olá Mundo!'},
{_id: '5', language: 'Spanish', greeting: '¡Hola Mundo!'},
{_id: '6', language: 'Ukrainian', greeting: 'Привіт Світ!'}
];
$w.onReady(async function () {
// Define how to set up each new repeater item
$w('#helloRepeater').onItemReady( ($item, itemData, index) => {
$item('#languageText').text = itemData.language;
$item('#helloText').text = itemData.greeting;
$item('#indexText').text = (index + 1).toString();
$item('#itemContainer').onMouseIn( () => {
$item('#languageText').show();
});
$item('#itemContainer').onMouseOut( () => {
$item('#languageText').hide();
});
} );
console.log(staticData);
// Set the data to associate with the repeater
$w('#helloRepeater').data = staticData;
});
Would using async function introduce a risk of onItemReady function running after the data property of repeater is set?
Additional Context
The reason I’m asking is because the onItemReady() documentation states:
Because setting a repeater’s
dataproperty triggers theonItemReady()callback to run, make sure you callonItemReady()before you set thedataproperty. Failing to do so will mean that your callbacks (plural?) are not triggered when you set thedataproperty.
It sounds like it’s important to have onItemReady defined/called before data property is set but I’m worried that using async keyword could result in the data property being defined first and onItemReady being defined after the data property is set.
Is it possible that onItemReady is called after the data property is set inside of an async function?