Skip to content

Commit

Permalink
Wrap deprecations in router-service flag
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Oct 1, 2018
1 parent d91a4d0 commit 55bd846
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 106 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"puppeteer": "^1.3.0",
"qunit": "^2.5.0",
"route-recognizer": "^0.3.4",
"router_js": "^5.0.1",
"router_js": "^5.0.3",
"rsvp": "^4.8.2",
"semver": "^5.5.0",
"serve-static": "^1.12.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class Route extends EmberObject implements IRoute {
@method _reset
@since 1.7.0
*/
reset(isExiting: boolean, transition: Transition) {
_internalReset(isExiting: boolean, transition: Transition) {
let controller = this.controller;
controller._qpDelegate = get(this, '_qp.states.inactive');

Expand Down
106 changes: 59 additions & 47 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { computed, defineProperty, get, set } from '@ember/-internals/metal';
import { getOwner, Owner } from '@ember/-internals/owner';
import { A as emberA, Evented, Object as EmberObject, typeOf } from '@ember/-internals/runtime';
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features';
import { assert, deprecate, info } from '@ember/debug';
import { HANDLER_INFOS } from '@ember/deprecated-features';
import EmberError from '@ember/error';
Expand Down Expand Up @@ -28,82 +29,93 @@ import { EngineRouteInfo } from './engines';
if (HANDLER_INFOS) {
Object.defineProperty(InternalRouteInfo.prototype, 'handler', {
get() {
deprecate(
'You attempted to read "handlerInfo.handler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to read "handlerInfo.handler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
return this.route;
},

set(value: string) {
deprecate(
'You attempted to set "handlerInfo.handler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to set "handlerInfo.handler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
this.route = value;
},
});

Object.defineProperty(InternalTransition.prototype, 'handlerInfos', {
get() {
deprecate(
'You attempted to use "transition.handlerInfos" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to use "transition.handlerInfos" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
return this.routeInfos;
},
});

Object.defineProperty(TransitionState.prototype, 'handlerInfos', {
get() {
deprecate(
'You attempted to use "transition.state.handlerInfos" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);

if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to use "transition.state.handlerInfos" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
return this.routeInfos;
},
});

Object.defineProperty(Router.prototype, 'currentHandlerInfos', {
get() {
if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to use "_routerMicrolib.currentHandlerInfos" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
return this.currentRouteInfos;
},
});

Router.prototype['getHandler'] = function(name: string) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
deprecate(
'You attempted to use "_routerMicrolib.currentHandlerInfos" which is a private API that will be removed.',
'You attempted to use "_routerMicrolib.getHandler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
return this.currentRouteInfos;
},
});

Router.prototype['getHandler'] = function(name: string) {
deprecate(
'You attempted to use "_routerMicrolib.getHandler" which is a private API that will be removed.',
false,
{
id: 'remove-handler-infos',
until: '3.9.0',
}
);
}
return this.getRoute(name);
};
}
Expand Down
111 changes: 57 additions & 54 deletions packages/ember/tests/routing/deprecated_handler_infos_test.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
import { moduleFor, ApplicationTestCase } from 'internal-test-helpers';
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features';

moduleFor(
'Deprecated HandlerInfos',
class extends ApplicationTestCase {
constructor() {
super(...arguments);
this.router.map(function() {
this.route('parent', function() {
this.route('child');
this.route('sibling');
if (EMBER_ROUTING_ROUTER_SERVICE) {
moduleFor(
'Deprecated HandlerInfos',
class extends ApplicationTestCase {
constructor() {
super(...arguments);
this.router.map(function() {
this.route('parent', function() {
this.route('child');
this.route('sibling');
});
});
});
}

get routerOptions() {
return {
willTransition(oldHandlers, newHandlers, transition) {
expectDeprecation(() => {
this._routerMicrolib.currentHandlerInfos;
}, 'You attempted to use "_routerMicrolib.currentHandlerInfos" which is a private API that will be removed.');
}

expectDeprecation(() => {
this._routerMicrolib.getHandler('parent');
}, 'You attempted to use "_routerMicrolib.getHandler" which is a private API that will be removed.');

oldHandlers.forEach(handler => {
get routerOptions() {
return {
willTransition(oldHandlers, newHandlers, transition) {
expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});
newHandlers.forEach(handler => {
this._routerMicrolib.currentHandlerInfos;
}, 'You attempted to use "_routerMicrolib.currentHandlerInfos" which is a private API that will be removed.');

expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});
this._routerMicrolib.getHandler('parent');
}, 'You attempted to use "_routerMicrolib.getHandler" which is a private API that will be removed.');

expectDeprecation(() => {
transition.handlerInfos;
}, 'You attempted to use "transition.handlerInfos" which is a private API that will be removed.');
oldHandlers.forEach(handler => {
expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});
newHandlers.forEach(handler => {
expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});

expectDeprecation(() => {
transition.state.handlerInfos;
}, 'You attempted to use "transition.state.handlerInfos" which is a private API that will be removed.');
QUnit.assert.ok(true, 'willTransition');
},
expectDeprecation(() => {
transition.handlerInfos;
}, 'You attempted to use "transition.handlerInfos" which is a private API that will be removed.');

didTransition(newHandlers) {
newHandlers.forEach(handler => {
expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});
QUnit.assert.ok(true, 'didTransition');
},
};
}
transition.state.handlerInfos;
}, 'You attempted to use "transition.state.handlerInfos" which is a private API that will be removed.');
QUnit.assert.ok(true, 'willTransition');
},

didTransition(newHandlers) {
newHandlers.forEach(handler => {
expectDeprecation(() => {
handler.handler;
}, 'You attempted to read "handlerInfo.handler" which is a private API that will be removed.');
});
QUnit.assert.ok(true, 'didTransition');
},
};
}

'@test handlerInfos are deprecated and associated private apis'(assert) {
let done = assert.async();
return this.visit('/parent').then(() => {
done();
});
'@test handlerInfos are deprecated and associated private apis'(assert) {
let done = assert.async();
return this.visit('/parent').then(() => {
done();
});
}
}
}
);
);
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6405,9 +6405,9 @@ route-recognizer@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3"

router_js@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-5.0.1.tgz#5c5ed5d306f71019b39128cabdbfbb5f09d10bc5"
router_js@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-5.0.3.tgz#38dda09088f9b2bc764ada05eaab628d829f1c17"
dependencies:
"@types/node" "^10.5.5"

Expand Down

0 comments on commit 55bd846

Please sign in to comment.