raptorjs-legacy / raptorjs

Source code for the RaptorJS Toolkit
Other
94 stars 12 forks source link

Raptor Templates: Add support for asynchronous rendering #36

Closed patrick-steele-idem closed 11 years ago

patrick-steele-idem commented 11 years ago

Add the ability to define asynchronous fragments during rendered. The render context should expose methods to begin and end asynchronous fragments. A promise should be returned by the render function to notify the callee when all asynchronous fragments have been flushed to the underlying writer.

NOTE: When using asynchronous fragments, the subsequent fragments can be either be buffered (and sent in order) or sent immediately and moved into place using JavaScript on the client. Both should be supported.

Example usage:

require('raptor/templating').renderAsync(name, data, context)
    .then(function() {
        // Async rendering complete
    });
<async:fragment data="todos" args="" var="todos">
    <!-- The todos have been retrieved and are ready to use! -->
    <ul>
       <li c:for="todo in todos"> ... </li>
    </ul>
</async:fragment>