From 12e6ab68332a89dfff905cedfcbc9dabbd203478 Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 30 Jul 2020 13:49:18 -0700 Subject: [PATCH] Pass transition object to activate/deactivate hooks and events Closes #19022 --- .../-internals/routing/lib/system/route.ts | 18 ++++++++++-------- .../tests/routing/decoupled_basic_test.js | 16 ++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/@ember/-internals/routing/lib/system/route.ts b/packages/@ember/-internals/routing/lib/system/route.ts index 3cebc41ebda..51f9c7ba30d 100644 --- a/packages/@ember/-internals/routing/lib/system/route.ts +++ b/packages/@ember/-internals/routing/lib/system/route.ts @@ -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(); } @@ -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); } /** @@ -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 diff --git a/packages/ember/tests/routing/decoupled_basic_test.js b/packages/ember/tests/routing/decoupled_basic_test.js index 8d6865a0f05..d8727e96d1e 100644 --- a/packages/ember/tests/routing/decoupled_basic_test.js +++ b/packages/ember/tests/routing/decoupled_basic_test.js @@ -1518,7 +1518,7 @@ moduleFor( } ['@test `activate` event fires on the route'](assert) { - assert.expect(2); + assert.expect(4); let eventFired = 0; @@ -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'); }, }) ); @@ -1547,7 +1549,7 @@ moduleFor( } ['@test `deactivate` event fires on the route'](assert) { - assert.expect(2); + assert.expect(4); let eventFired = 0; @@ -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'); }, }) );