Skip to content
Myr

Added mounted hook. Closes #369

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 16a24cf · Browse files · 2 files+17 added−1 removed
This commit

State

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

Diff stats

2 files+17 added−1 removed

  • tests:+9 added−1 removed
  • other:+8 added−0 removed

2 files+17 added−1 removed

modified:lib/express/server.js+8 added
102 unmodified lines
103 }104105 connect.Server.prototype.use.call(this, route, middleware);106107 // Mounted an app108 if (middleware instanceof Server) {109 // Home is /:route/:home110 var app = middleware,111 home = app.set('home');112 if (home === '/') home = '';113 app.set('home', (app.route || '') + home);114 // Mounted hook115 if (app.__mounted) app.__mounted.call(app, this);116 }117118 return this;119};120121Server.prototype.mounted = function(fn){122 this.__mounted = fn;123};124125/**126 * Register the given view helpers `obj`. This method127 * can be called several times to apply additional helpers.128 *
126 unmodified lines
modified:test/express.test.js+9 added-1 removed
264 unmodified lines
265 { body: '{"name":"tj"}' });266 },267 268 'test mounting': function(assert){269 var called,269 var app = express.createServer(),270 app = express.createServer(),271 blog = express.createServer(),272 map = express.createServer();273274 map.set('home', '/map');275 276 map.mounted(function(parent){277 called = true;278 assert.equal(this, map, 'mounted() is not in context of the child app');279 assert.equal(app, parent, 'mounted() was not called with parent app');280 });281 282 app.use('/blog', blog);283 app.use('/contact', map);284 assert.equal('/blog', blog.route);285 assert.equal('/contact', map.route);286 assert.ok(called, 'mounted() hook failed');287 288 app.get('/', function(req, res){289 assert.equal('/', app.set('home'), "home did not default to /");290 assert.equal('/blog', blog.set('home'), "home did not default to Server#route when mounted");
26 unmodified lines