From 53aa372ab99e35c7e4e4b28cf701e682ebf1ca56 Mon Sep 17 00:00:00 2001 From: Puru Guna Date: Wed, 4 Mar 2015 17:14:30 -0800 Subject: [PATCH] Upgrate 05_requirejs to 1.0.X --- 05_requirejs/app/app.js | 4 ++-- 05_requirejs/app/router.js | 2 +- 05_requirejs/app/views/app_view.js | 2 +- 05_requirejs/index.js | 25 +++++++++++++------------ 05_requirejs/package.json | 28 ++++++++++++++++------------ 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/05_requirejs/app/app.js b/05_requirejs/app/app.js index 2afb87b..4e72ccc 100644 --- a/05_requirejs/app/app.js +++ b/05_requirejs/app/app.js @@ -15,14 +15,14 @@ define(function(require) { /** * Client and server. * - * `postInitialize` is called on app initialize, both on the client and server. + * `initialize` is called on app initialize, both on the client and server. * On the server, an app is instantiated once for each request, and in the * client, it's instantiated once on page load. * * This is a good place to initialize any code that needs to be available to * app on both client and server. */ - postInitialize: function() { + initialize: function() { /** * Register our Handlebars helpers. * diff --git a/05_requirejs/app/router.js b/05_requirejs/app/router.js index 03a81ab..e4fa853 100644 --- a/05_requirejs/app/router.js +++ b/05_requirejs/app/router.js @@ -16,7 +16,7 @@ define(function(require) { Router.prototype = Object.create(BaseClientRouter.prototype); Router.prototype.constructor = BaseClientRouter; - Router.prototype.postInitialize = function() { + Router.prototype.initialize = function() { this.on('action:start', this.trackImpression, this); }; diff --git a/05_requirejs/app/views/app_view.js b/05_requirejs/app/views/app_view.js index 10f86e5..f495ec6 100644 --- a/05_requirejs/app/views/app_view.js +++ b/05_requirejs/app/views/app_view.js @@ -8,7 +8,7 @@ define(function(require) { var $body = $('body'); return BaseAppView.extend({ - postInitialize: function() { + initialize: function() { this.app.on('change:loading', function(app, loading) { $body.toggleClass('loading', loading); }, this); diff --git a/05_requirejs/index.js b/05_requirejs/index.js index 376f3f5..46d03e1 100644 --- a/05_requirejs/index.js +++ b/05_requirejs/index.js @@ -1,14 +1,9 @@ -var express = require('express') - , rendr = require('rendr') - , app = express(); - -/** - * Initialize Express middleware stack. - */ -app.use(express.compress()); -app.use(express.static(__dirname + '/public')); -app.use(express.logger()); -app.use(express.bodyParser()); +var express = require('express') + , rendr = require('rendr') + , app = express() + , bodyParser = require('body-parser') + , compression = require('compression') + , serveStatic = require('serve-static'); /** * In this simple example, the DataAdapter config, which specifies host, port, etc. of the API @@ -34,6 +29,12 @@ var server = rendr.createServer({ dataAdapterConfig: dataAdapterConfig }); +server.configure(function (expressApp) { + expressApp.use(compression()); + expressApp.use(serveStatic(__dirname + '/public')); + expressApp.use(bodyParser.json()); +}); + /** * To mount Rendr, which owns its own Express instance for better encapsulation, * simply add `server` as a middleware onto your Express app. @@ -42,7 +43,7 @@ var server = rendr.createServer({ * * app.use('/my_cool_app', server); */ -app.use(server); +app.use(server.expressApp); /** * Start the Express server. diff --git a/05_requirejs/package.json b/05_requirejs/package.json index 3215254..bc18d4d 100644 --- a/05_requirejs/package.json +++ b/05_requirejs/package.json @@ -10,24 +10,28 @@ "postupdate": "test -f ../../package.json && npm install ../../ || echo" }, "dependencies": { - "express": "~3", - "underscore": "~1.5.2", - "async": "~0.2.9", - "rendr-handlebars": "0.2.0", - "rendr": "0.5.0", + "body-parser": "^1.12.0", + "compression": "^1.4.1", + "express": "^4.12.0", + "jquery": "^2.1.3", + "rendr": "1.0.x", + "rendr-handlebars": "^1.0.0", + "serve-static": "^1.9.1", + "underscore": "^1.8.2", "amdefine": "~0.1.0" }, "devDependencies": { - "requirejs": "~2.1.10", - "grunt": "~0.4.1", - "grunt-contrib-watch": "~0.3.1", - "grunt-contrib-stylus": "~0.5.0", - "grunt-contrib-handlebars": "~0.5.11", + "requirejs": "~2.1.15", + "grunt": "~0.4.5", + "grunt-contrib-watch": "~0.6.1", + "grunt-contrib-stylus": "~0.20.0", + "grunt-contrib-handlebars": "~0.9.3", "grunt-contrib-requirejs": "~0.4.1", - "grunt-rendr-requirejs": "~0.1.1", + "grunt-rendr-requirejs": "~1.0.0", "nodemon": "~0.7.6", "mocha": "~1.9.0", - "should": "~1.2.2" + "should": "~1.2.2", + "async": "~0.9.0" }, "engines": { "node": ">=0.8"