Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're asking different questions, but certainly they are connected. The first is about loading additional <strong>javascript</strong> code into your <strong>meteor</strong> app. Of course you can use thing like <code>requirejs</code>. This should work fine supposing your lazy code is located in the <code>public</code> directory of your <strong>meteor</strong> project. However, my experience is that <code>requirejs</code> goes mad when the contents of <code>public</code> gets updated often, so for example in the development environment. Maybe it's a matter of customizing the library, but I would rather recommend using some lightweight homebrewed package. Look <a href="https://github.com/apendua/module-loader" rel="nofollow">here</a>, if you need some inspiration.</p> <p>The second question is about lazy template definition. Each template consists of two parts. The first is its <code>html</code> code, written in <code>handlebars</code> syntax, the second is all the <strong>javascript</strong> code which you write to define how your template should behave (e.g. helpers, event handlers). The second part is easy, as long as we assume that we already know how to load the lazy code (see the above paragraph) and the template, lets call it <code>myLazyTemplate</code>, is already defined, so basically speaking <code>Template.myLazyTemplate</code> is not <code>undefined</code>. So how to achieve the latter?</p> <p>To dynamically define a new template you'll need to call <code>Template.__define__(name, raw_func)</code> on the client. So the last question is "what is <code>raw_func</code>?". This is a <strong>compiled</strong> version of your <strong>html</strong> code which is normally created automatically on the server and then sent down the wire to the client when the app gets loaded (look <a href="https://github.com/meteor/meteor/blob/d477c8d03bb078f7e8e85dbe4b51db7ae5689573/packages/templating/plugin/html_scanner.js#L149-L183" rel="nofollow">here</a> to see how it's done in <strong>meteor</strong>). But we want to do it dynamically, right?</p> <p>So the idea is to compile the template code manually with a help of the <code>Handlebars.to_json_ast</code> routine. You can feed it with your template <strong>html</strong> code, and the output is some <strong>javascript</strong> array that can be sent to the client anytime by the method we've already talked about. The last thing you need to do is to call <code>Handlebars.json_ast_to_func</code> on the client, using the data sent from the server as the only argument. The output produced by <code>Handlebars.json_ast_to_func</code> is the <code>raw_func</code> you can use to produce <code>myLazyTemplate</code> template.</p> <p>I'm aware that this is only a rough idea, not the whole solution to your problem. I hope this will help you to figure out the final solution on your own.</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.
 

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