Permalink
Browse files

Optimize use of YUI in server-side route handlers

  • Loading branch information...
1 parent 487aa77 commit 35bc52291b23c0b39867026bb8b0fdd48a62b75b @ericf committed Jul 19, 2013
Showing with 12 additions and 6 deletions.
  1. +6 −4 routes/photos.js
  2. +6 −2 routes/places.js
View
@@ -1,6 +1,10 @@
+var Y;
+
exports.load = function (req, res, next) {
- var Y = req.app.yui.use('pnm-photo'),
- photo = new Y.PNM.Photo({id: req.params.id}),
+ // Load YUI modules, once.
+ Y || (Y = req.app.yui.use('pnm-photo'));
+
+ var photo = new Y.PNM.Photo({id: req.params.id}),
place;
photo.load(function () {
@@ -12,8 +16,6 @@ exports.load = function (req, res, next) {
};
exports.render = function (req, res) {
- var Y = req.app.yui.use();
-
res.expose(req.place, 'DATA.place');
res.expose(req.photo, 'DATA.photo');
res.expose({name: 'lightbox'}, 'VIEW');
View
@@ -1,6 +1,10 @@
+var Y;
+
exports.load = function (req, res, next) {
- var Y = req.app.yui.use('parallel', 'pnm-place', 'pnm-photo', 'pnm-photos');
- place = new Y.PNM.Place({id: req.params.id}),
+ // Load YUI modules, once.
+ Y || (Y = req.app.yui.use('parallel', 'pnm-place', 'pnm-photo', 'pnm-photos'));
+
+ var place = new Y.PNM.Place({id: req.params.id}),
photos = new Y.PNM.Photos(),
requests = new Y.Parallel();

0 comments on commit 35bc522

Please sign in to comment.