Added support for Promises in Spacebars.call and Spacebars.dot.#413
Conversation
aaahhhh... noice... Couldn't we then not just implement Something like this: ... there's always the problem of the re-running of the autorun above then re-triggering the entire call which then would lead to re-triggering the call with a fresh promise which would then lead to... not the result which we want 😃 -> But as a general idea it might be feasible and I'll toy with it when I'll have a bit of time. Or maybe @radekmie you know exactly how something like this could / should be implemented & do it in a heartbeat, which i'd be 100% onboard with :) Thank you for the PR & hear you later! |
|
I wouldn't think of |
While #412 adds a way to unwrap
Promises in templates, here we'll focus on their usability. Currently, accessing aPromiseresults inundefinedas they have very few accessible properties (most importantly, the resolved value is not there).In this pull request, I made
Spacebars.callandSpacebars.dothelpers aware ofPromises. The former resolves all of the arguments before calling the function, while the latter wraps property accesses inPromises.For details, please refer to the newly added tests.
(Fun fact: there are 0 deleted lines in this pull request.)
Once this and #412 will be merged, the "
awaitunrolling" proposed before would not be needed. Consider the example from #409 (comment):{{#if await someFunc ((await calcParamA) (await someOtherparamB)) (await calcParamB (await someOtherparamC) (someOtherparamD)) }} (...) {{/if}}This will have to unwrap the
Promise, but the entire computation will be simple:{{#let result=(someFunc (calcParamA someOtherparamB) (calcParamB someOtherparamC someOtherparamD))}} {{#if result}} (...) {{/if}} {{/let}}Of course, it'll be possible to use the
@pending,@rejected, and@resolvedhelpers to check the progress of calculatingresultas well.