Continuing the discussion from Accessing topic.views from widget or plugin initializer:
I was encountering issues, as per the linked topic and I have boiled it down to this:
I cannot seem to return a virtual-dom element to api.decorateWidget
from within a function.
As an example, this works:
api.decorateWidget('post-meta-data:after', dec => {
return h('i.fa.fa-eye')
});
But this do not work:
api.decorateWidget('post-meta-data:after', dec => {
function doThis() {
return h('i.fa.fa-eye')
}
doThis();
});
Can’t figure out why?
Scope?
maybe
api.decorateWidget('post-meta-data:after', dec => {
function doThis() {
return h('i.fa.fa-eye')
};
return doThis();
});
1 Like
Oh wait ya I just realized that too. I should just use my actual code instead of trying to simplify my problem.
I am doing this:
api.decorateWidget('post-meta-data:after', dec => {
const attrs = dec.attrs;
function passViews(views) {
//views is successfully passed to this function from getJSON
console.log(views);
//the below vDom test element does NOT attach as expected
return h('i.fa.fa-eye'));
}
$.getJSON(attrs.topicUrl + '.json', function (data) {
//passing function to success because ultimately I want to
// get the topic views
success: passViews(data.views);
});
});