Skip to content
Myr

change res.locals to a plain js object.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Anyone who wants something fancier should use modules. - fixes annoyance with not being able to set 'name' property on locals

authored by Roman Shtylman · committed by Roman Shtylman · parent 337ab24 · Browse files · 8 files+23 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+23 added−29 removed

  • tests:+20 added−7 removed
  • other:+3 added−22 removed

8 files+23 added−29 removed

modified:lib/application.js+1 added-2 removed
6 unmodified lines
7 , Router = require('./router')8 , methods = require('methods')9 , middleware = require('./middleware')10 , debug = require('debug')('express:application')11 , locals = require('./utils').locals11 , View = require('./view')12 , http = require('http');1314/**
55 unmodified lines
70 return this._router.middleware;71 });7273 // setup locals75 this.locals = locals(this);74 this.locals = Object.create(null);7576 // default locals77 this.locals.settings = this.settings;78
397 unmodified lines
modified:lib/middleware.js+1 added-1 removed
modified:lib/utils.js-19 removed
23 unmodified lines
24 return '"' + crc32.signed(body) + '"';25};2627/**28 * Make `locals()` bound to the given `obj`.29 *30 * This is used for `app.locals` and `res.locals`.31 *32 * @param {Object} obj33 * @return {Function}34 * @api private35 */3637exports.locals = function(){38 function locals(obj){39 for (var key in obj) locals[key] = obj[key];40 return obj;41 };4243 return locals;44};4546/**28 * Check if `path` looks absolute.29 *30 * @param {String} path31 * @return {Boolean}
127 unmodified lines
added:test/fixtures/name.jade+1 added
1p= name
modified:test/app.locals.js+2 added-2 removed
modified:test/res.locals.js+2 added-5 removed
modified:test/res.render.js+15 added
45 unmodified lines
46 request(app)47 .get('/')48 .expect('<p>tobi</p>', done);49 })5051 it('should expose app.locals with `name` property', function(done){52 var app = express();5354 app.set('views', __dirname + '/fixtures');55 app.locals.name = 'tobi';5657 app.use(function(req, res){58 res.render('name.jade');59 });6061 request(app)62 .get('/')63 .expect('<p>tobi</p>', done);64 })65 66 it('should support index.<engine>', function(done){67 var app = express();68
204 unmodified lines
modified:History.md+1 added
8 unmodified lines
9 * change:10 - `req.accepts*` -> `req.accepts*s` - i.e. `req.acceptsEncoding` -> `req.acceptsEncodings`11 - `req.params` is now an object instead of an array12 - `json spaces` no longer enabled by default in development13 - `res.locals` is no longer a function. It is a plain js object. Treat it as such.14 * refactor:15 - `req.accepts*` with [accepts](https://github.com/expressjs/accepts)16 - `req.is` with [type-is](https://github.com/expressjs/type-is)17
1252 unmodified lines