Skip to content

Commit

Permalink
Revert "refactor(router): Simplify router defaults by making the defa…
Browse files Browse the repository at this point in the history
…ults Injectable" (#48121)

This reverts commit 18033d5.

PR Close #48121
  • Loading branch information
dylhunn committed Nov 18, 2022
1 parent 764fa3d commit 57d9296
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 45 deletions.
8 changes: 0 additions & 8 deletions goldens/public-api/router/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,6 @@ export abstract class RouteReuseStrategy {
abstract shouldDetach(route: ActivatedRouteSnapshot): boolean;
abstract shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<RouteReuseStrategy, never>;
// (undocumented)
static ɵprov: i0.ɵɵInjectableDeclaration<RouteReuseStrategy>;
}

// @public
Expand Down Expand Up @@ -954,10 +950,6 @@ export abstract class UrlHandlingStrategy {
abstract extract(url: UrlTree): UrlTree;
abstract merge(newUrlPart: UrlTree, rawUrl: UrlTree): UrlTree;
abstract shouldProcessUrl(url: UrlTree): boolean;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<UrlHandlingStrategy, never>;
// (undocumented)
static ɵprov: i0.ɵɵInjectableDeclaration<UrlHandlingStrategy>;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion goldens/size-tracking/integration-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"cli-hello-world-lazy": {
"uncompressed": {
"runtime": 2835,
"main": 225766,
"main": 225113,
"polyfills": 33842,
"src_app_lazy_lazy_routes_ts": 487
}
Expand Down
21 changes: 0 additions & 21 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,9 @@
{
"name": "DefaultIfEmptySubscriber"
},
{
"name": "DefaultRouteReuseStrategy"
},
{
"name": "DefaultTitleStrategy"
},
{
"name": "DefaultUrlHandlingStrategy"
},
{
"name": "DefaultUrlSerializer"
},
Expand Down Expand Up @@ -470,9 +464,6 @@
{
"name": "RootViewRef"
},
{
"name": "RouteReuseStrategy"
},
{
"name": "RouteTitleKey"
},
Expand Down Expand Up @@ -626,9 +617,6 @@
{
"name": "UnsubscriptionError"
},
{
"name": "UrlHandlingStrategy"
},
{
"name": "UrlParser"
},
Expand Down Expand Up @@ -1100,9 +1088,6 @@
{
"name": "getFactoryDef"
},
{
"name": "getFactoryOf"
},
{
"name": "getFirstLContainer"
},
Expand Down Expand Up @@ -1361,9 +1346,6 @@
{
"name": "isEnvironmentProviders"
},
{
"name": "isForwardRef"
},
{
"name": "isFunction"
},
Expand Down Expand Up @@ -1544,9 +1526,6 @@
{
"name": "noMatch2"
},
{
"name": "noSideEffects"
},
{
"name": "nodeChildrenAsMap"
},
Expand Down
7 changes: 2 additions & 5 deletions packages/router/src/route_reuse_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ComponentRef, inject, Injectable} from '@angular/core';
import {ComponentRef} from '@angular/core';

import {OutletContext} from './router_outlet_context';
import {ActivatedRoute, ActivatedRouteSnapshot} from './router_state';
Expand Down Expand Up @@ -38,7 +38,6 @@ export type DetachedRouteHandleInternal = {
*
* @publicApi
*/
@Injectable({providedIn: 'root', useFactory: () => inject(DefaultRouteReuseStrategy)})
export abstract class RouteReuseStrategy {
/** Determines if this route (and its subtree) should be detached to be reused later */
abstract shouldDetach(route: ActivatedRouteSnapshot): boolean;
Expand Down Expand Up @@ -111,6 +110,4 @@ export abstract class BaseRouteReuseStrategy implements RouteReuseStrategy {
}
}

@Injectable({providedIn: 'root'})
export class DefaultRouteReuseStrategy extends BaseRouteReuseStrategy {
}
export class DefaultRouteReuseStrategy extends BaseRouteReuseStrategy {}
26 changes: 20 additions & 6 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import {checkGuards} from './operators/check_guards';
import {recognize} from './operators/recognize';
import {resolveData} from './operators/resolve_data';
import {switchTap} from './operators/switch_tap';
import {TitleStrategy} from './page_title_strategy';
import {RouteReuseStrategy} from './route_reuse_strategy';
import {DefaultTitleStrategy, TitleStrategy} from './page_title_strategy';
import {DefaultRouteReuseStrategy, RouteReuseStrategy} from './route_reuse_strategy';
import {ErrorHandler, ExtraOptions, ROUTER_CONFIGURATION} from './router_config';
import {RouterConfigLoader, ROUTES} from './router_config_loader';
import {ChildrenOutletContexts} from './router_outlet_context';
import {ActivatedRoute, ActivatedRouteSnapshot, createEmptyState, RouterState, RouterStateSnapshot} from './router_state';
import {Params} from './shared';
import {UrlHandlingStrategy} from './url_handling_strategy';
import {DefaultUrlHandlingStrategy, UrlHandlingStrategy} from './url_handling_strategy';
import {containsTree, IsActiveMatchOptions, isUrlTree, UrlSerializer, UrlTree} from './url_tree';
import {flatten} from './utils/collection';
import {standardizeConfig, validateConfig} from './utils/config';
Expand Down Expand Up @@ -325,9 +325,23 @@ export function setupRouter() {
const compiler = inject(Compiler);
const config = inject(ROUTES, {optional: true}) ?? [];
const opts = inject(ROUTER_CONFIGURATION, {optional: true}) ?? {};
const defaultTitleStrategy = inject(DefaultTitleStrategy);
const titleStrategy = inject(TitleStrategy, {optional: true});
const urlHandlingStrategy = inject(UrlHandlingStrategy, {optional: true});
const routeReuseStrategy = inject(RouteReuseStrategy, {optional: true});
const router =
new Router(null, urlSerializer, contexts, location, injector, compiler, flatten(config));

if (urlHandlingStrategy) {
router.urlHandlingStrategy = urlHandlingStrategy;
}

if (routeReuseStrategy) {
router.routeReuseStrategy = routeReuseStrategy;
}

router.titleStrategy = titleStrategy ?? defaultTitleStrategy;

assignExtraOptionsToRouter(opts, router);

return router;
Expand Down Expand Up @@ -485,23 +499,23 @@ export class Router {
* @deprecated Configure using `providers` instead:
* `{provide: UrlHandlingStrategy, useClass: MyStrategy}`.
*/
urlHandlingStrategy = inject(UrlHandlingStrategy);
urlHandlingStrategy: UrlHandlingStrategy = new DefaultUrlHandlingStrategy();

/**
* A strategy for re-using routes.
*
* @deprecated Configure using `providers` instead:
* `{provide: RouteReuseStrategy, useClass: MyStrategy}`.
*/
routeReuseStrategy = inject(RouteReuseStrategy);
routeReuseStrategy: RouteReuseStrategy = new DefaultRouteReuseStrategy();

/**
* A strategy for setting the title based on the `routerState`.
*
* @deprecated Configure using `providers` instead:
* `{provide: TitleStrategy, useClass: MyStrategy}`.
*/
titleStrategy?: TitleStrategy = inject(TitleStrategy);
titleStrategy?: TitleStrategy;

/**
* How to handle a navigation request to the current URL. One of:
Expand Down
4 changes: 0 additions & 4 deletions packages/router/src/url_handling_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import {inject, Injectable} from '@angular/core';

import {UrlTree} from './url_tree';

/**
Expand All @@ -17,7 +15,6 @@ import {UrlTree} from './url_tree';
*
* @publicApi
*/
@Injectable({providedIn: 'root', useFactory: () => inject(DefaultUrlHandlingStrategy)})
export abstract class UrlHandlingStrategy {
/**
* Tells the router if this URL should be processed.
Expand All @@ -44,7 +41,6 @@ export abstract class UrlHandlingStrategy {
/**
* @publicApi
*/
@Injectable({providedIn: 'root'})
export class DefaultUrlHandlingStrategy implements UrlHandlingStrategy {
shouldProcessUrl(url: UrlTree): boolean {
return true;
Expand Down

0 comments on commit 57d9296

Please sign in to comment.