Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE ember-routing-fire-activate-deactivate-events] Fire activate and deactivate events on Ember.Route #5569

Merged
merged 1 commit into from
Oct 20, 2014
Merged
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
7 changes: 7 additions & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ for a detailed explanation.
property of an `array controller`.

Added in [#5301](https://github.com/emberjs/ember.js/pull/5301)

* `ember-routing-fire-activate-deactivate-events`

Fire `activate` and `deactivate` events, additionally to the corresponding
`Ember.Route` hooks.

Added in [#5569](https://github.com/emberjs/ember.js/pull/5569)
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"ember-routing-handlebars-action-with-key-code": null,
"ember-runtime-item-controller-inline-class": null,
"ember-metal-injected-properties": null,
"mandatory-setter": "development-only"
"mandatory-setter": "development-only",
"ember-routing-fire-activate-deactivate-events": null
},
"debugStatements": [
"Ember.warn",
Expand Down
13 changes: 13 additions & 0 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
classify
} from "ember-runtime/system/string";
import EmberObject from "ember-runtime/system/object";
import Evented from "ember-runtime/mixins/evented";
import ActionHandler from "ember-runtime/mixins/action_handler";
import generateController from "ember-routing/system/generate_controller";
import { stashParamNames } from "ember-routing/utils";
Expand Down Expand Up @@ -340,6 +341,9 @@ var Route = EmberObject.extend(ActionHandler, {
*/
exit: function() {
this.deactivate();
if (Ember.FEATURES.isEnabled("ember-routing-fire-activate-deactivate-events")) {
this.trigger('deactivate');
}
this.teardownViews();
},

Expand All @@ -364,6 +368,9 @@ var Route = EmberObject.extend(ActionHandler, {
*/
enter: function() {
this.activate();
if (Ember.FEATURES.isEnabled("ember-routing-fire-activate-deactivate-events")) {
this.trigger('activate');
}
},

/**
Expand Down Expand Up @@ -1845,6 +1852,12 @@ var Route = EmberObject.extend(ActionHandler, {
}
});

if (Ember.FEATURES.isEnabled("ember-routing-fire-activate-deactivate-events")) {
// TODO add mixin directly to `Route` class definition above, once this
// feature is merged:
Route.reopen(Evented);
}

var defaultQPMeta = {
qps: [],
map: {},
Expand Down
60 changes: 60 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,66 @@ test("`didTransition` can be reopened", function() {
bootApplication();
});

if (Ember.FEATURES.isEnabled("ember-routing-fire-activate-deactivate-events")) {
test("`activate` event fires on the route", function() {
expect(2);

var eventFired = 0;

Router.map(function(){
this.route("nork");
});

App.NorkRoute = Ember.Route.extend({
init: function() {
this._super();

this.on("activate", function() {
equal(++eventFired, 1, "activate event is fired once");
});
},

activate: function() {
ok(true, "activate hook is called");
}
});

bootApplication();

Ember.run(router, 'transitionTo', 'nork');
});

test("`deactivate` event fires on the route", function() {
expect(2);

var eventFired = 0;

Router.map(function(){
this.route("nork");
this.route("dork");
});

App.NorkRoute = Ember.Route.extend({
init: function() {
this._super();

this.on("deactivate", function() {
equal(++eventFired, 1, "deactivate event is fired once");
});
},

deactivate: function() {
ok(true, "deactivate hook is called");
}
});

bootApplication();

Ember.run(router, 'transitionTo', 'nork');
Ember.run(router, 'transitionTo', 'dork');
});
}

test("Actions can be handled by inherited action handlers", function() {

expect(4);
Expand Down