Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to modify the LayoutManger to handle asynchronous rendering of templates.</p> <p>One of the ways to do this is to use the jQuery Deferred object where the call to <code>render</code> returns an instance of a <code>Deferred</code> object, which you then resolve in the call to the <code>Dust</code> library.</p> <p>Then, modify Backbone.LayoutManager to NOT continue doing what it wants to with the templates until that Deferred object has been resolve.</p> <p>in <code>render</code>:</p> <pre><code>render: (template, context) -&gt; dfd = $.Deferred() dust.render @template, context, (err, out) -&gt; throw err if err done(out) dfd.resolve() return dfd; </code></pre> <p>You then take the method in Backbone.LayoutManager that calls render and instead of doing something with the return from render you attach that "something" to the <code>done</code> handler for the deferred you passed back.</p> <pre><code> dfd = render(template, context) dfd.done(do_something_with_this_template); </code></pre> <p>I'm using Marionette.js (along with it's async variant) and dust, this is what my core <code>render</code> method looks like:</p> <pre><code> render: function(){ var dfd = $.Deferred(); var template_context = this.model; if(_.isUndefined(template_context) || _.isFunction(template_context)){ template_context = new (Backbone.Model.extend({})); } if(this.id) this.$el.attr('id', this.id); var that = this; dust.stream(this.tpl_name, template_context.toJSON()) .on('data', function(data){ that.$el.html(data); }) .on('end', function(){ dfd.resolve(); that.enable_menus(); that.trigger('template:rendered'); }) .on('error', function(err){ dfd.reject(); window.le(err.message, err); that.trigger('template:error'); }); return dfd; } </code></pre> <p>(Obviously not using coffeescript either...)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload