Skip to content

Commit 7e0a8af

Browse files
chore(test): Eagerly bind the urlService in the TestPlugin.
feat(UrlService): allow eager or lazy binding of location objects during construction
1 parent 1ca93d0 commit 7e0a8af

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/url/urlService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ export class UrlService implements LocationServices, UrlSyncApi {
8282
private router: UIRouter;
8383

8484
/** @hidden */
85-
constructor(router: UIRouter) {
85+
constructor(router: UIRouter, lateBind = true) {
8686
this.router = router;
8787
this.rules = {} as any;
8888
this.config = {} as any;
8989

9090
// proxy function calls from UrlService to the LocationService/LocationConfig
9191
const locationServices = () => router.locationService;
92-
createProxyFunctions(locationServices, this, locationServices, locationServicesFns, true);
92+
createProxyFunctions(locationServices, this, locationServices, locationServicesFns, lateBind);
9393

9494
const locationConfig = () => router.locationConfig;
95-
createProxyFunctions(locationConfig, this.config, locationConfig, locationConfigFns, true);
95+
createProxyFunctions(locationConfig, this.config, locationConfig, locationConfigFns, lateBind);
9696

9797
const umf = () => router.urlMatcherFactory;
9898
createProxyFunctions(umf, this.config, umf, umfFns);

test/_testingPlugin.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UIRouter } from "../src/router";
22
import { UIRouterPluginBase } from "../src/interface";
33
import * as vanilla from "../src/vanilla";
4+
import { UrlService } from "../src/url/urlService";
45

56
export class TestingPlugin extends UIRouterPluginBase {
67
name: string = 'testing';
@@ -11,6 +12,8 @@ export class TestingPlugin extends UIRouterPluginBase {
1112
super();
1213
router.plugin(vanilla.servicesPlugin);
1314
router.plugin(vanilla.memoryLocationPlugin);
15+
// bind the location proxy functions immediately
16+
router.urlService = new UrlService(router, false);
1417

1518
this.addErrorLoopHandler();
1619

0 commit comments

Comments
 (0)