Skip to content

Commit bab3ad7

Browse files
refactor(url): rename $loc to $url. make router instance variables private
1 parent c006f44 commit bab3ad7

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/url/urlRouter.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ export class UrlRouterProvider implements Disposable {
5050
otherwiseFn: ($injector: $InjectorLike, $location: LocationServices) => string;
5151
/** @hidden */
5252
interceptDeferred = false;
53+
/** @hidden */
54+
_router: UIRouter;
5355

54-
constructor(public router: UIRouter) { }
56+
constructor(router: UIRouter) {
57+
this._router = router;
58+
}
5559

5660
/** @internalapi */
5761
dispose() {
@@ -178,10 +182,10 @@ export class UrlRouterProvider implements Disposable {
178182
* Note: the handler may also invoke arbitrary code, such as `$state.go()`
179183
*/
180184
when(what: (RegExp|UrlMatcher|string), handler: string|IInjectable, ruleCallback = function(rule) {}) {
181-
let router = this.router;
185+
let router = this._router;
182186
let $urlMatcherFactory = router.urlMatcherFactory;
183187
let $stateParams = router.globals.params;
184-
let $loc = router.urlService;
188+
let $url = router.urlService;
185189
let redirect, handlerIsString = isString(handler);
186190

187191
// @todo Queue this
@@ -197,7 +201,7 @@ export class UrlRouterProvider implements Disposable {
197201
_handler = ['$match', redirect.format.bind(redirect)];
198202
}
199203
return extend(function () {
200-
return handleIfMatch(services.$injector, $stateParams, _handler, _what.exec($loc.path(), $loc.search(), $loc.hash()));
204+
return handleIfMatch(services.$injector, $stateParams, _handler, _what.exec($url.path(), $url.search(), $url.hash()));
201205
}, {
202206
prefix: isString(_what.prefix) ? _what.prefix : ''
203207
});
@@ -210,7 +214,7 @@ export class UrlRouterProvider implements Disposable {
210214
_handler = ['$match', ($match) => interpolate(redirect, $match)];
211215
}
212216
return extend(function () {
213-
return handleIfMatch(services.$injector, $stateParams, _handler, _what.exec($loc.path()));
217+
return handleIfMatch(services.$injector, $stateParams, _handler, _what.exec($url.path()));
214218
}, {
215219
prefix: regExpPrefix(_what)
216220
});
@@ -274,9 +278,12 @@ export class UrlRouter implements Disposable {
274278
private location: string;
275279
/** @hidden */
276280
private listener: Function;
281+
/** @hidden */
282+
private _router: UIRouter;
277283

278284
/** @hidden */
279-
constructor(public router: UIRouter) {
285+
constructor(router: UIRouter) {
286+
this._router = router;
280287
createProxyFunctions(UrlRouter.prototype, this, this);
281288
}
282289

@@ -312,17 +319,17 @@ export class UrlRouter implements Disposable {
312319
sync(evt?) {
313320
if (evt && evt.defaultPrevented) return;
314321

315-
let router = this.router;
316-
let $loc = router.urlService;
322+
let router = this._router;
323+
let $url = router.urlService;
317324
let rules = router.urlRouterProvider.rules;
318325
let otherwiseFn = router.urlRouterProvider.otherwiseFn;
319326

320327
function check(rule: Function) {
321-
let handled = rule(services.$injector, $loc);
328+
let handled = rule(services.$injector, $url);
322329

323330
if (!handled) return false;
324331
if (isString(handled)) {
325-
$loc.setUrl(handled, true);
332+
$url.setUrl(handled, true);
326333
}
327334
return true;
328335
}
@@ -342,21 +349,21 @@ export class UrlRouter implements Disposable {
342349
* This causes [[UrlRouter]] to start listening for changes to the URL, if it wasn't already listening.
343350
*/
344351
listen(): Function {
345-
return this.listener = this.listener || this.router.urlService.onChange(evt => this.sync(evt));
352+
return this.listener = this.listener || this._router.urlService.onChange(evt => this.sync(evt));
346353
}
347354

348355
/**
349356
* Internal API.
350357
*/
351358
update(read?: boolean) {
352-
let $loc = this.router.urlService;
359+
let $url = this._router.urlService;
353360
if (read) {
354-
this.location = $loc.path();
361+
this.location = $url.path();
355362
return;
356363
}
357-
if ($loc.path() === this.location) return;
364+
if ($url.path() === this.location) return;
358365

359-
$loc.setUrl(this.location, true);
366+
$url.setUrl(this.location, true);
360367
}
361368

362369
/**
@@ -370,7 +377,7 @@ export class UrlRouter implements Disposable {
370377
*/
371378
push(urlMatcher: UrlMatcher, params: RawParams, options: { replace?: (string|boolean) }) {
372379
let replace = options && !!options.replace;
373-
this.router.urlService.setUrl(urlMatcher.format(params || {}), replace);
380+
this._router.urlService.setUrl(urlMatcher.format(params || {}), replace);
374381
}
375382

376383
/**
@@ -398,7 +405,7 @@ export class UrlRouter implements Disposable {
398405
let url = urlMatcher.format(params);
399406
options = options || { absolute: false };
400407

401-
let cfg = this.router.urlService.config;
408+
let cfg = this._router.urlService.config;
402409
let isHtml5 = cfg.html5Mode();
403410
if (!isHtml5 && url !== null) {
404411
url = "#" + cfg.hashPrefix() + url;

0 commit comments

Comments
 (0)