Add functions that work with Promises
brianmhunt opened this issue · 2 comments
brianmhunt commented
In may scenarios things are simplified with Promises. It'd be handy to have some built into Dust e.g. (for illustration)
Object.assign(dust, {
asyncRenderSource(str='', view={}) {
return new Promise((res, rej) => {
const template = dust.loadSource(dust.compile(str, ''))
try {
dust.render(template, view, (err, out) => err ? rej(err) : res(out))
} catch(e) { rej(e) } // see #107
})
}
})
Noting #107 re. syntax errors.
Cheers .
sethkinast commented
I'm still bouncing around this impl for Dust 3.0 but this is definitely on my mind.
kugimiya commented
Hello, everyone!
@sethkinast, can I help with this? I can implement these cases:
- When a variable falls into the filter function, the filter can return
Promise
. So, we'll see something like this:Hello, [object Promise]!
. So, on the rendering side, we can look at the type of object that the filter function returns, and if we getPromise
- we are trying to resolve it. - The same behavior for the case described in the issue.