GithubHelp home page GithubHelp logo

Comments (8)

aredridel avatar aredridel commented on July 18, 2024

Most of our examples are in the generated kraken apps; let me see if I can sum up.

Mostly it's just

var express = require('express');
var dustjs = require('adaro');

var app = express();

app.engine('dust', dustjs.dust({ ... });
app.set('view engine', 'dust');

then res.render('templatename') for how we use it.

What about the asynchronous rendering are you having trouble with?

from adaro.

jeffersonlam avatar jeffersonlam commented on July 18, 2024

Thanks for the speedy reply.

About including Adaro, I successfully have that portion working (requiring adaro rather than dustjs-linkedin) but it's somehow broken our inline partials; the default template gets rendered and the inline-partials no longer work.

In one file layout.dust I have:

{+content}
      Content goes here
{/content}

And in another I have:

{>layout/}
{<content}
    This is the content
    {#data.foo}
        {bar}
    {/data.foo}
{/content}

What I'm doing is making a series of API calls in the server with Express, and that data is shown in the view using Dust (as structured above). The way it's currently structured is that the view doesn't get rendered until all of the API calls are done. This makes it such that there's a long delay until the page actually gets rendered. What we want to happen is for the page to get loaded, and then as the API calls are finished, asynchronously pipe that data into the view. I haven't found much info on how to asynchronously pipe this information into the view.

My code currently looks something like this:

var express = require('express')
,   router = express.Router()
,   requestify = require('requestify')
;

router.get('/page', function(req, res){
  requestify.get('https://get.request/)
    .then(function(response) {
      var data = response.getBody();
      data.foo = [];
      for (var i = 0; i < data.array.length; i++) (function(i){
         requestify.get('https:/get.request/more?='+data.array[i])
           .then(function(response2){
             data.foo.push(response2.getBody());
             count++;
             if (count == data.array.length){
               res.render('page', { layout: 'layout', data: data });
             }
           });
       })(i);
});

Obviously a for-loop of GET requests that ultimately renders a view isn't ideal. This is what I'm trying to avoid. But, I don't know how to structure the code such that I can pipe data into the view.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

So you're specifying both a layout in your render call and 'inheriting' the layout in your template?

from adaro.

jeffersonlam avatar jeffersonlam commented on July 18, 2024

Yes, I think so. A lot of the code wasn't written by myself and I'm not a Dust expert (I've also opened an issue on the Dust repo for more docs), but I believe that's what we're doing.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Yeah. That can be a problem -- the in-template way is the "dust way", though adaro allows you to specify a layout too. I'd pick one or the other instead of mixing them.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Now the problem you're trying to solve is hard, because dust templates, even when rendered asynchronously, can have to wait for the final pieces to come back before you get much. The streaming interface optimizes a bit, but not as much as you might suspect.

from adaro.

jeffersonlam avatar jeffersonlam commented on July 18, 2024

What do you mean by in-template and specifying a layout? These terms and concepts escape me a bit.

Is it possible to have a template rendered, and then have pieces of the page get populated with data that asynchronously gets sent in from the server? Are there code samples of that in action?

from adaro.

aredridel avatar aredridel commented on July 18, 2024

In-template specification of a layout: {>layout/}

Specifying in adaro: layout: 'layout' in the render options.

Both of those do similar things.

from adaro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.