I would like to use api.decorateWidget
after an Discourse.ajax
has run.
api.decorateWidget('post-contents:before', dec => {
const attrs = dec.attrs;
const result = [];
Discourse.ajax('/test', {
type: 'GET',
data: { topic_id: topic_id, group: group }
}).then(function(res){
if (res.test) {
//this push a virtual node into the result array
result.push(h('h1', 'test'));
//this logs the virtual node and confirm virtual-dom works here
console.log(result);
//expected result here is that api.decorateWidget gets the returned h1 virtual node and attached is, BUT it does nothing with no errors.
return result;
}
});
});
#EDIT: AFTER RUNNING SOME TESTS
So what all the code boils down to is…
- The
decorateWidget
function - An
ajax
call inside thedecorateWidget
- An if statement in the result of the
ajax
call that returns a vDOM element
I put a console.log
at each of these steps and got this (note: there are 2 posts on the thread I am testing on, which is why the widget decorator and ajax call runs twice):
Also, I am still not getting the vDOM element to return after the if statement.