Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Lets render return a promise for doing async work
Browse files Browse the repository at this point in the history
This allows userland code to perform async actions and render the HTML
some time in the future. This opens up the possibility for doing async
rendering, data fetching prior to rendering, code splitting with
routing, etc.
  • Loading branch information
goatslacker committed Jun 5, 2017
1 parent 9982a18 commit ca74d21
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/utils/BatchManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,18 @@ class BatchManager {
if (!renderFn || typeof renderFn !== 'function') {
// component not registered
context.statusCode = 404;
context.duration = msSince(start);
throw notFound(name);
return Promise.reject(notFound(name));
}

let response = null;

// render the component!
try {
context.html = renderFn(context.props);
} catch (e) {
response = Promise.reject(e);
} finally {
context.duration = msSince(start);
}

return response;
return Promise.resolve(renderFn(context.props));
})
.then((html) => {
context.html = html;
context.duration = msSince(start);
})
.catch((err) => {
context.duration = msSince(start);
return Promise.reject(err);
});
}

Expand Down

0 comments on commit ca74d21

Please sign in to comment.