Comments (8)
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.
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.
So you're specifying both a layout in your render call and 'inheriting' the layout in your template?
from adaro.
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.
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.
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.
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.
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)
- How to get dustjs instance from adaro HOT 16
- Docs seems outdated HOT 4
- adaro should expose a way to configure dust
- Update Dust.js to 2.7.4
- Need for Brook?
- TypeError: require.cache.hasOwnProperty is not a function HOT 4
- where is dustjs defined? HOT 1
- npm audit detected a vulnerability
- Dependency package has a security vulnerability HOT 1
- Does not work after Node v10
- TypeError: Cannot read property 'substr' of undefined HOT 33
- Document dust filter initialization using helpers: property. HOT 2
- Possible to stream without repeated code? HOT 2
- Documentation is inaccurate / missing HOT 11
- The rendering blocks / waits infinitely when using partials inside an helper context HOT 2
- Consider not requiring a .properties file for each .dust file HOT 3
- Reqwire always calls process.cwd with relative files HOT 1
- adaro/lib/patch/index.js:121:21: TypeError: Cannot read property 'name' of undefined HOT 7
- Looping issue when rendering an object hierarchy to ul/li tags HOT 1
- using dust with express HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adaro.