1.2.0-beta.0
·
326 commits
to master
since this release
This is a beta release of 1.2.0, which introduces SSR Zones as a public API in done-ssr. It's unknown whether these zones will remain in done-ssr for 1.2.0 or if they are going to be moved to their own repositories, hence why this is a beta release.
For normal done-ssr users nothing has changed, and there's probably no reason to use the beta release. But for those who want a little more control, you can use the new Zones API. You can read about the API here.
This is a typical example of usage:
var Zone = require("can-zone");
var requests = require("done-ssr/zones/requests");
var dom = require("done-ssr/zones/can-simple-dom");
var pushFetch = require("done-ssr/zones/push-fetch");
var pushImages = require("done-ssr/zones/push-images");
var app = require("./app");
require("spdy").createServer(options, function(request, response){
var zone = new Zone([
// Overrides XHR, fetch
requests(request),
// Sets up a DOM
dom(request),
pushFetch(response),
pushImages(response)
]);
zone.run(app).then(function(data){
// The full HTML after all async tasks are complete
response.end(data.html);
});
});
Where app.js
looks like:
module.exports = function(){
// can-zone-jsdom provides a global `document`
var main = document.createElement("main");
var ul = document.createElement("ul");
main.appendChild(ul);
// This will be PUSHed
var img = document.createElement("img");
img.src = "/images/cat.png";
main.appendChild(img);
// This will be PUSHed
fetch("/api/todos").then(res => res.json()).then(todos => {
todos.forEach(todo => {
var li = document.createElement("li");
li.textContent = todo;
ul.appendChild(li);
});
});
};