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

Pass transition object to activate/deactivate hooks and events #19086

Merged
merged 1 commit into from
Aug 7, 2020
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
18 changes: 10 additions & 8 deletions packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ class Route extends EmberObject implements IRoute {

@method exit
*/
exit() {
this.deactivate();
this.trigger('deactivate');
exit(transition?: Transition) {
this.deactivate(transition);
this.trigger('deactivate', transition);
this.teardownViews();
}

Expand All @@ -384,10 +384,10 @@ class Route extends EmberObject implements IRoute {

@method enter
*/
enter() {
enter(transition: Transition) {
ROUTE_CONNECTIONS.set(this, []);
this.activate();
this.trigger('activate');
this.activate(transition);
this.trigger('activate', transition);
}

/**
Expand Down Expand Up @@ -596,20 +596,22 @@ class Route extends EmberObject implements IRoute {
not executed when the model for the route changes.

@method deactivate
@param {Transition} transition
@since 1.0.0
@public
*/
deactivate() {}
deactivate(_transition?: Transition) {}

/**
This hook is executed when the router enters the route. It is not executed
when the model for the route changes.

@method activate
@param {Transition} transition
@since 1.0.0
@public
*/
activate() {}
activate(_transition: Transition) {}

/**
Transition the application into another route. The route may
Expand Down
16 changes: 10 additions & 6 deletions packages/ember/tests/routing/decoupled_basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ moduleFor(
}

['@test `activate` event fires on the route'](assert) {
assert.expect(2);
assert.expect(4);

let eventFired = 0;

Expand All @@ -1532,13 +1532,15 @@ moduleFor(
init() {
this._super(...arguments);

this.on('activate', function() {
this.on('activate', function(transition) {
assert.equal(++eventFired, 1, 'activate event is fired once');
assert.ok(transition, 'transition is passed to activate event');
});
},

activate() {
activate(transition) {
assert.ok(true, 'activate hook is called');
assert.ok(transition, 'transition is passed to activate hook');
},
})
);
Expand All @@ -1547,7 +1549,7 @@ moduleFor(
}

['@test `deactivate` event fires on the route'](assert) {
assert.expect(2);
assert.expect(4);

let eventFired = 0;

Expand All @@ -1562,13 +1564,15 @@ moduleFor(
init() {
this._super(...arguments);

this.on('deactivate', function() {
this.on('deactivate', function(transition) {
assert.equal(++eventFired, 1, 'deactivate event is fired once');
assert.ok(transition, 'transition is passed');
});
},

deactivate() {
deactivate(transition) {
assert.ok(true, 'deactivate hook is called');
assert.ok(transition, 'transition is passed');
},
})
);
Expand Down