Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,27 @@ function doTransition(router, method, args) {

Ember.Router.reopenClass({
map: function(callback) {
var router = this.router = new Router();

var dsl = Ember.RouterDSL.map(function() {
this.resource('application', { path: "/" }, function() {
callback.call(this);
// Make sure the mapCallbacks exists
if (this.mapCallbacks == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not define it as a class variable on line 235.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference: #2892

this.mapCallbacks = [];
}
this.mapCallbacks.push(callback);

var router = this.router,
self = this;
if (this.router === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machty Unless I'm misunderstanding you, I've already changed the behavior here to not discard the Router instance. We are still regenerating the DSL though, is this what you are asking me to defer?

Apologies for the confusion, I'm in #emberjs if a direct chat resolves this more easily

router = this.router = new Router();
}

var dsl = Ember.RouterDSL.map(function() {
this.resource('application', { path: "/" }, function() {
for (var cb_i = 0, cb_l = self.mapCallbacks.length; cb_i < cb_l; cb_i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you factoring out cb_l? I think it makes the for loop longer/harder to read.

self.mapCallbacks[cb_i].call(this);
}
});
});
});

router.map(dsl.generate());
return router;
router.map(dsl.generate());
return router;
}
});
48 changes: 48 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module("Basic Routing", {
Ember.TEMPLATES.application = compile("{{outlet}}");
Ember.TEMPLATES.home = compile("<h3>Hours</h3>");
Ember.TEMPLATES.homepage = compile("<h3>Megatroll</h3><p>{{home}}</p>");
Ember.TEMPLATES.camelot = compile('<section><h3>Is a silly place</h3></section>');
});
},

Expand Down Expand Up @@ -74,6 +75,53 @@ test("The Homepage", function() {
equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
});

test("The Home page and the Camelot page with multiple Router.map calls", function() {
Router.map(function() {
this.route("home", { path: "/" });
});

Router.map(function() {
this.route("camelot", {path: "/camelot"});
});

App.HomeRoute = Ember.Route.extend({
});

App.CamelotRoute = Ember.Route.extend({
});

var currentPath;

App.ApplicationController = Ember.Controller.extend({
currentPathDidChange: Ember.observer(function() {
currentPath = get(this, 'currentPath');
}, 'currentPath')
});

App.CamelotController = Ember.Controller.extend({
currentPathDidChange: Ember.observer(function() {
currentPath = get(this, 'currentPath');
}, 'currentPath')
});

bootApplication();

Ember.run(function() {
router.handleURL("/camelot");
});

equal(currentPath, 'camelot');
equal(Ember.$('h3:contains(silly)', '#qunit-fixture').length, 1, "The camelot template was rendered");


Ember.run(function() {
router.handleURL("/");
});

equal(currentPath, 'home');
equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
});

test("The Homepage register as activeView", function() {
Router.map(function() {
this.route("home", { path: "/" });
Expand Down