Skip to content

Commit cf4e5f9

Browse files
refactor(urlMatcher): move init of urlmatcherfactory to angular1.ts
1 parent c9c9a04 commit cf4e5f9

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/common/angular1.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @module common */ /** for typedoc */
22
/// <reference path='../../typings/angularjs/angular.d.ts' />
33
import {IQService} from "angular";
4+
import {Router} from "../router";
45

56
let app = angular.module("ui.router.angular1", []);
67

@@ -58,3 +59,12 @@ function runBlock($injector) {
5859
}
5960

6061
app.run(runBlock);
62+
63+
64+
let router = new Router();
65+
66+
// Register as a provider so it's available to other providers
67+
angular.module('ui.router.util').provider('$urlMatcherFactory', () => router.urlMatcherFactory);
68+
angular.module('ui.router.util').run(['$urlMatcherFactory', function($urlMatcherFactory) { }]);
69+
70+
export { router };

src/router.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
export class UIRouter {
1+
import {UrlMatcherFactory} from "./url/urlMatcherFactory";
22

3-
}
3+
class Router {
4+
constructor() {}
5+
urlMatcherFactory: UrlMatcherFactory = new UrlMatcherFactory();
6+
}
7+
8+
export { Router };

src/url/urlMatcherConfig.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@ class MatcherConfig {
77
_defaultSquashPolicy: (boolean|string) = false;
88

99
caseInsensitive(value?: boolean): boolean {
10-
if (!isDefined(value))
11-
return this._isCaseInsensitive;
12-
13-
return this._isCaseInsensitive = value;
10+
return this._isCaseInsensitive = isDefined(value) ? value : this._isCaseInsensitive;
1411
}
1512

1613
strictMode(value?: boolean): boolean {
17-
if (!isDefined(value))
18-
return this._isStrictMode;
19-
20-
return this._isStrictMode = value;
14+
return this._isStrictMode = isDefined(value) ? value : this._isStrictMode;
2115
}
2216

2317
defaultSquashPolicy(value?: (boolean|string)): (boolean|string) {
24-
if (!isDefined(value))
25-
return this._defaultSquashPolicy;
26-
27-
if (value !== true && value !== false && !isString(value))
18+
if (isDefined(value) && value !== true && value !== false && !isString(value))
2819
throw new Error(`Invalid squash policy: ${value}. Valid policies: false, true, arbitrary-string`);
29-
30-
return this._defaultSquashPolicy = value;
20+
return this._defaultSquashPolicy = isDefined(value) ? value : this._defaultSquashPolicy;
3121
}
3222
}
3323

src/url/urlMatcherFactory.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,3 @@ export class UrlMatcherFactory {
151151
return this;
152152
};
153153
}
154-
155-
// Register as a provider so it's available to other providers
156-
angular.module('ui.router.util').provider('$urlMatcherFactory', <any> UrlMatcherFactory);
157-
angular.module('ui.router.util').run(['$urlMatcherFactory', function($urlMatcherFactory) { }]);

0 commit comments

Comments
 (0)