JSFiddle - React, Tailwind, and code Playground
JavaScript
var normalFilter = index => index % 2 == 0;
var asyncFilter = async index => {
// same filter but returns after 500ms. In the actual application the result is returned from a c# function
return await fakeInteropCall(index, normalFilter);
}
var conf = {
filter: normalFilter // if you put asyncFilter here, everything will be filtered
};
fakeConsumer(conf); // call the consumer with the config
// I can't change this consumer, it's actually chart.js
function fakeConsumer(config) {
for (let i = 0; i < 5; i++) {
if (config.filter(i)) {
console.log("filtered " + i);
} else {
console.log(i);
}
}
}
// I can't change this interop call, it's from blazor and only the async version works on all variants
function fakeInteropCall(index, filterFunc) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(filterFunc(index));
}, 500);
});
}