You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have defined an extension, which tries to read some data from IndexedDB, process it and submit it to an HTTP endpoint.
I have problems because Dexie.js works asynchronously, and I cannot make encodeParameters() wait for the result of the db.notes.where() call, which is a Promise.
So, the payload of my HTTP Request is '[object Promise]', while I would have wanted it to be the result of the eventually fulfilled Promise, i.e. something like
3 100324 104773 108681
6 12309248 89069683
(which is what is printed in the console by the statement console.log(ret)
Is it possible in principle, to make encodeParameters wait for the Promises to be fulfilled before returning? I post one of my many attempts, where I have made the function async and use an await statement.
htmx.defineExtension('notes-plain-h', {
onEvent: function (name, evt) {
if (name === "htmx:configRequest") {
evt.detail.headers['Content-Type'] = "text/plain";
}
},
encodeParameters : async function(xhr, parameters, elt) {
xhr.overrideMimeType('text/plain');
let dict = {};
let result = await db.notes.where('suit').equals('h').each(n => {
if (!(n.marketId in dict))
dict[n.marketId] = [];
dict[n.marketId].push(n.productId);
})
.then(() => { return dict; })
.then((d) => {
console.log(d);
let ret = ""
for (const [m_id, products] of Object.entries(d)) {
let s = m_id;
for (let p_id of products)
s = s + " " + p_id;
ret = ret + s + "\n";
};
console.log(ret);
return(ret);
})
return result;
}
});
The text was updated successfully, but these errors were encountered:
Hello, I have defined an extension, which tries to read some data from IndexedDB, process it and submit it to an HTTP endpoint.
I have problems because Dexie.js works asynchronously, and I cannot make encodeParameters() wait for the result of the db.notes.where() call, which is a Promise.
So, the payload of my HTTP Request is '[object Promise]', while I would have wanted it to be the result of the eventually fulfilled Promise, i.e. something like
3 100324 104773 108681
6 12309248 89069683
(which is what is printed in the console by the statement console.log(ret)
Is it possible in principle, to make encodeParameters wait for the Promises to be fulfilled before returning? I post one of my many attempts, where I have made the function async and use an await statement.
The text was updated successfully, but these errors were encountered: