You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that the partial() view helpers works async, by inserting a placeholder.
Is it possible to create own async view helpers working with the same method?
If not what would be the best place to include such kind of feature?
Possible API:
Using functions: if helper methods returns a function, execute this function right after rendering and pass it a callback function as single argument. the callback should get an error as first and the result of the async helper as second argument:
functionasyncHelper(){returnfunction(whenDone){// do your async stuffwhenDone(null,'this will get insert');// <- pass an Error instead of null if an error occured};}
Using promises: if the helper method returns a promise, use its resolve() to replace the placeholder content and the catch() to catch helper errors:
functionpromiseHelper(){returnnewPromise(function(resolve,reject){// do async stuffresolve('this will get insert');// <- use catch(Error) to pass an error});}
Using a wrapping build-in async helper: Geddy will include a build-in async view helper. This helper will do almost the same as the existing partial helper and needs either a promise or function as in the upper cases passed as argument. Template code could then look like this:
<%-async(asyncHelper()) %>
or with promise
<%-async(promiseHelper()) %>
The benefits of this are that we could be able to pass options to the helper that would for example trigger caching of the async result.
The text was updated successfully, but these errors were encountered:
I know that the
partial()
view helpers works async, by inserting a placeholder.Is it possible to create own async view helpers working with the same method?
If not what would be the best place to include such kind of feature?
Possible API:
Using functions: if helper methods returns a function, execute this function right after rendering and pass it a callback function as single argument. the callback should get an error as first and the result of the async helper as second argument:
Using promises: if the helper method returns a promise, use its
resolve()
to replace the placeholder content and thecatch()
to catch helper errors:Using a wrapping build-in async helper: Geddy will include a build-in
async
view helper. This helper will do almost the same as the existingpartial
helper and needs either a promise or function as in the upper cases passed as argument. Template code could then look like this:The benefits of this are that we could be able to pass options to the helper that would for example trigger caching of the async result.
The text was updated successfully, but these errors were encountered: