dustjs icon indicating copy to clipboard operation
dustjs copied to clipboard

Add functions that work with Promises

Open brianmhunt opened this issue 7 years ago • 2 comments

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 . :beers:

brianmhunt avatar Apr 06 '17 12:04 brianmhunt

I'm still bouncing around this impl for Dust 3.0 but this is definitely on my mind.

sethkinast avatar Apr 06 '17 17:04 sethkinast

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 get Promise - we are trying to resolve it.
  • The same behavior for the case described in the issue.

kugimiya avatar Jan 23 '18 18:01 kugimiya