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

Refactor router: remove owner presence checks #19458

Merged
merged 1 commit into from
Mar 12, 2021
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
53 changes: 26 additions & 27 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function defaultDidTransition(this: EmberRouter, infos: PrivateRouteInfo[]) {
once(this, this.trigger, 'didTransition');

if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
if (this.namespace.LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
console.log(`Transitioned into '${EmberRouter._routePath(infos)}'`);
}
Expand All @@ -69,7 +69,7 @@ function defaultWillTransition(
once(this, this.trigger, 'willTransition', transition);

if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
if (this.namespace.LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
console.log(
`Preparing to transition from '${EmberRouter._routePath(
Expand Down Expand Up @@ -156,24 +156,28 @@ class EmberRouter extends EmberObject {
_qpUpdates = new Set();
_queuedQPChanges: { [key: string]: unknown } = {};

_bucketCache: BucketCache | undefined;
_bucketCache: BucketCache;
_toplevelView: OutletView | null = null;
_handledErrors = new Set();
_engineInstances: { [name: string]: { [id: string]: EngineInstance } } = Object.create(null);
_engineInfoByRoute = Object.create(null);
_routerService: RouterService | undefined;
_routerService: RouterService;

_slowTransitionTimer: unknown;

constructor(owner: Owner) {
super(...arguments);

this._resetQueuedQueryParameterChanges();
if (owner) {
this.namespace = owner.lookup('application:main');
this._bucketCache = owner.lookup(P`-bucket-cache:main`);
this._routerService = owner.lookup('service:router');
}
this.namespace = owner.lookup('application:main');

let bucketCache: BucketCache | undefined = owner.lookup(P`-bucket-cache:main`);
assert('BUG: BucketCache should always be present', bucketCache !== undefined);
this._bucketCache = bucketCache;

let routerService: RouterService | undefined = owner.lookup('service:router');
assert('BUG: RouterService should always be present', routerService !== undefined);
this._routerService = routerService;
}

_initRouterJs() {
Expand Down Expand Up @@ -211,7 +215,7 @@ class EmberRouter extends EmberObject {
route = routeOwner.lookup(fullRouteName);

if (DEBUG) {
if (get(router, 'namespace.LOG_ACTIVE_GENERATION')) {
if (router.namespace.LOG_ACTIVE_GENERATION) {
info(`generated -> ${fullRouteName}`, { fullName: fullRouteName });
}
}
Expand Down Expand Up @@ -303,12 +307,12 @@ class EmberRouter extends EmberObject {

routeWillChange(transition: Transition) {
router.trigger('routeWillChange', transition);
if (router._routerService) {
if (DEBUG) {
freezeRouteInfo(transition);
}
router._routerService.trigger('routeWillChange', transition);

if (DEBUG) {
freezeRouteInfo(transition);
}
router._routerService.trigger('routeWillChange', transition);

// in case of intermediate transition we update the current route
// to make router.currentRoute.name consistent with router.currentRouteName
// see https://github.com/emberjs/ember.js/issues/19449
Expand All @@ -321,12 +325,11 @@ class EmberRouter extends EmberObject {
router.set('currentRoute', transition.to);
once(() => {
router.trigger('routeDidChange', transition);
if (router._routerService) {
if (DEBUG) {
freezeRouteInfo(transition);
}
router._routerService.trigger('routeDidChange', transition);

if (DEBUG) {
freezeRouteInfo(transition);
}
router._routerService.trigger('routeDidChange', transition);
});
}

Expand Down Expand Up @@ -384,7 +387,7 @@ class EmberRouter extends EmberObject {
);

if (DEBUG) {
if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
if (this.namespace.LOG_TRANSITIONS_INTERNAL) {
routerMicrolib.log = console.log.bind(console); // eslint-disable-line no-console
}
}
Expand Down Expand Up @@ -422,10 +425,6 @@ class EmberRouter extends EmberObject {

_hasModuleBasedResolver() {
let owner = getOwner(this);
if (!owner) {
return false;
}

let resolver = get(owner, 'application.__registry__.resolver.moduleBasedResolver');
return Boolean(resolver);
}
Expand Down Expand Up @@ -588,7 +587,7 @@ class EmberRouter extends EmberObject {

if (DEBUG) {
let infos = this._routerMicrolib.currentRouteInfos;
if (get(this, 'namespace').LOG_TRANSITIONS) {
if (this.namespace.LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
console.log(`Intermediate-transitioned into '${EmberRouter._routePath(infos)}'`);
}
Expand Down Expand Up @@ -722,7 +721,7 @@ class EmberRouter extends EmberObject {
let rootURL = this.rootURL;
let owner = getOwner(this);

if ('string' === typeof location && owner) {
if ('string' === typeof location) {
let resolvedLocation = owner.lookup<IEmberLocation>(`location:${location}`);

if (resolvedLocation !== undefined) {
Expand Down
Loading