Skip to content

Commit 9bb87c4

Browse files
committed
Refactor on and
1 parent b156959 commit 9bb87c4

45 files changed

Lines changed: 715 additions & 460 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

@types/interface.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export * from "./core/di/ng-module.js";
44
export * from "./services/http/interface.ts";
55
export * from "./services/log/interface.ts";
66
export * from "./services/log/log.js";
7+
export * from "./services/location/interface.ts";
8+
export * from "./services/location/location.js";
79
export * from "./services/pubsub/pubsub.js";
810
export * from "./services/template-cache/interface.ts";
911
export * from "./services/template-cache/template-cache.js";

@types/router/url/url-matcher.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ export class UrlMatcher {
112112
* // returns { id: 'bob', q: 'hello', r: null }
113113
* ```
114114
*
115-
* @param path The URL path to match, e.g. `$location.path()`.
116-
* @param search URL search parameters, e.g. `$location.search()`.
115+
* @param path The URL path to match, e.g. `$location.getPath()`.
116+
* @param search URL search parameters, e.g. `$location.getSearch()`.
117117
* @param hash URL hash e.g. `$location.getHash()`.
118118
*
119119
* @returns The captured parameter values.

@types/router/url/url-rules.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* The most commonly used methods are [[otherwise]] and [[when]].
88
*
9-
* This API is found at `$urlService.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])
9+
* This API is found at `$url.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])
1010
*/
1111
export class UrlRules {
1212
constructor(urlRuleFactory: any);

@types/router/url/url-service.d.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ export class UrlService {
3333
config: import("./url-config.js").UrlConfigProvider;
3434
/** Creates a new [[Param]] for a given location (DefType) */
3535
paramFactory: ParamFactory;
36+
_urlListeners: any[];
3637
/**
3738
* Gets the path part of the current url
3839
*
3940
* If the current URL is `/some/path?query=value#anchor`, this returns `/some/path`
4041
*
41-
* @return the path portion of the url
42+
* @return {string} the path portion of the url
4243
*/
43-
path: () => any;
44+
getPath(): string;
4445
/**
4546
* Gets the search part of the current url as an object
4647
*
4748
* If the current URL is `/some/path?query=value#anchor`, this returns `{ query: 'value' }`
4849
*
49-
* @return the search (query) portion of the url, as an object
50+
* @return {Object} the search (query) portion of the url, as an object
5051
*/
51-
search: () => any;
52+
getSearch(): any;
5253
/**
5354
* Gets the hash part of the current url
5455
*
5556
* If the current URL is `/some/path?query=value#anchor`, this returns `anchor`
5657
*
57-
* @return the hash (anchor) portion of the url
58+
* @return {string} the hash (anchor) portion of the url
5859
*/
59-
hash: () => any;
60-
_urlListeners: any[];
60+
getHash(): string;
6161
$get: (
6262
| string
6363
| ((
@@ -69,6 +69,9 @@ export class UrlService {
6969
* @returns {boolean}
7070
*/
7171
html5Mode(): boolean;
72+
/**
73+
* @returns {string}
74+
*/
7275
baseHref(): string;
7376
_baseHref: string;
7477
/**
@@ -124,7 +127,7 @@ export class UrlService {
124127
*/
125128
url(newUrl?: string, state?: any): any;
126129
/**
127-
* @internal
130+
* @private
128131
*
129132
* Registers a low level url change handler
130133
*
@@ -135,10 +138,10 @@ export class UrlService {
135138
* let deregisterFn = locationServices.onChange((evt) => console.log("url change", evt));
136139
* ```
137140
*
138-
* @param callback a function that will be called when the url is changing
139-
* @return a function that de-registers the callback
141+
* @param {Function} callback a function that will be called when the url is changing
142+
* @return {Function} a function that de-registers the callback
140143
*/
141-
onChange(callback: any): () => any;
144+
private onChange;
142145
/**
143146
* Gets the current URL parts.
144147
*
@@ -219,7 +222,7 @@ export class UrlService {
219222
* ```js
220223
* matcher = $umf.compile("/about/:person");
221224
* params = { person: "bob" };
222-
* $bob = $urlService.href(matcher, params);
225+
* $bob = $url.href(matcher, params);
223226
* // $bob == "/about/bob";
224227
* ```
225228
*

@types/services/location/location.d.ts

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ export class Location {
211211
* @type {string}
212212
*/
213213
$$path: string;
214+
/**
215+
* Current url
216+
* @type {string}
217+
*/
218+
$$url: string;
214219
/**
215220
* The hash string, minus the hash symbol
216221
* @type {string}
@@ -243,28 +248,6 @@ export class Location {
243248
* @return {string} url
244249
*/
245250
getUrl(): string;
246-
/**
247-
* @deprecated
248-
* This method is getter / setter.
249-
*
250-
* Return path of current URL when called without any parameter.
251-
*
252-
* Change path when called with parameter and return `$location`.
253-
*
254-
* Note: Path should always begin with forward slash (/), this method will add the forward slash
255-
* if it is missing.
256-
*
257-
*
258-
* ```js
259-
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
260-
* let path = $location.path();
261-
* // => "/some/path"
262-
* ```
263-
*
264-
* @param {(string|number)=} path New path
265-
* @return {(string|object)} path if called with no parameters, or `$location` if called with a parameter
266-
*/
267-
path(path?: (string | number) | undefined): string | object;
268251
/**
269252
* Change path parameter and return `$location`.
270253
*
@@ -274,30 +257,11 @@ export class Location {
274257
setPath(path: string | number): Location;
275258
/**
276259
*
277-
* Return path of current URL when called without any parameter.
278-
*
279-
* @return {(string|object)} path if called with no parameters, or `$location` if called with a parameter
280-
*/
281-
getPath(): string | object;
282-
/**
283-
* @deprecated
284-
* This method is getter / setter.
260+
* Return path of current URL
285261
*
286-
* Returns the hash fragment when called without any parameters.
287-
*
288-
* Changes the hash fragment when called with a parameter and returns `$location`.
289-
*
290-
*
291-
* ```js
292-
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
293-
* let hash = $location.getHash();
294-
* // => "hashValue"
295-
* ```
296-
*
297-
* @param {(string|number)=} hash New hash fragment
298-
* @return {string|Location} hash
262+
* @return {string}
299263
*/
300-
hash(hash?: (string | number) | undefined): string | Location;
264+
getPath(): string;
301265
/**
302266
* Changes the hash fragment when called with a parameter and returns `$location`.
303267
* @param {(string|number)} hash New hash fragment
@@ -341,25 +305,29 @@ export class Location {
341305
* @returns {Object} Search object or Location object
342306
*/
343307
getSearch(): any;
344-
$$url: string;
345308
/**
346-
* This method is getter / setter.
347-
*
348-
* Return the history state object when called without any parameter.
349-
*
309+
* Compose url and update `url` and `absUrl` property
310+
* @returns {void}
311+
*/
312+
$$compose(): void;
313+
/**
350314
* Change the history state object when called with one parameter and return `$location`.
351315
* The state object is later passed to `pushState` or `replaceState`.
352316
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#state|History.state}
353317
*
354318
* NOTE: This method is supported only in HTML5 mode and only in browsers supporting
355319
* the HTML5 History API (i.e. methods `pushState` and `replaceState`). If you need to support
356320
* older browsers (like IE9 or Android < 4.0), don't use this method.
357-
*
358-
* @param {any} state State object for pushState or replaceState
359-
* @return {any} state
321+
* @param {any} state
322+
* @returns {Location}
360323
*/
361-
state(state: any, ...args: any[]): any;
324+
setState(state: any): Location;
362325
$$state: any;
326+
/**
327+
* Return the history state object
328+
* @returns {any}
329+
*/
330+
getState(): any;
363331
/**
364332
* @param {string} url
365333
* @param {string} relHref
@@ -371,7 +339,6 @@ export class Location {
371339
* @param {string} url HTML5 URL
372340
*/
373341
parse(url: string): void;
374-
#private;
375342
}
376343
export class LocationProvider {
377344
/** @type {string} */
@@ -383,8 +350,8 @@ export class LocationProvider {
383350
urlChangeInit: boolean;
384351
/** @type {History['state']} */
385352
cachedState: History["state"];
386-
/** @typeof {History.state} */
387-
lastHistoryState: any;
353+
/** @type {History['state']} */
354+
lastHistoryState: History["state"];
388355
/** @type {string} */
389356
lastBrowserUrl: string;
390357
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: $locationProvider
3+
description: >
4+
Configuration provider for `$location` service.
5+
---
6+
7+
### Description
8+
9+
Use the `$locationProvider` to configure how the application deep linking paths
10+
are stored.
11+
12+
### Properties
13+
14+
---
15+
16+
#### $locationProvider.html5ModeConf
17+
18+
- **Type:** Html5Mode
19+
- **Default:** `{ enabled: true, requireBase: false, rewriteLinks: true }`
20+
- **Example:**
21+
22+
```js
23+
angular.module('demo', []).config(($locationProvider) => {
24+
$locationProvider.enabled = false;
25+
});
26+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: $location
3+
description: >
4+
URL normalization for HTML5/hashbang modes
5+
---

docs/content/docs/service/url.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: $url
3+
description: >
4+
URL management for state transitions
5+
---

docs/static/typedoc/assets/highlight.css

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
:root {
2-
--light-hl-0: #000000;
3-
--dark-hl-0: #D4D4D4;
4-
--light-hl-1: #A31515;
5-
--dark-hl-1: #CE9178;
6-
--light-hl-2: #0000FF;
7-
--dark-hl-2: #569CD6;
2+
--light-hl-0: #008000;
3+
--dark-hl-0: #6A9955;
4+
--light-hl-1: #0000FF;
5+
--dark-hl-1: #569CD6;
6+
--light-hl-2: #000000;
7+
--dark-hl-2: #D4D4D4;
88
--light-hl-3: #001080;
99
--dark-hl-3: #9CDCFE;
10-
--light-hl-4: #800000;
11-
--dark-hl-4: #808080;
10+
--light-hl-4: #A31515;
11+
--dark-hl-4: #CE9178;
1212
--light-hl-5: #800000;
13-
--dark-hl-5: #569CD6;
14-
--light-hl-6: #E50000;
15-
--dark-hl-6: #9CDCFE;
16-
--light-hl-7: #0000FF;
17-
--dark-hl-7: #CE9178;
13+
--dark-hl-5: #808080;
14+
--light-hl-6: #800000;
15+
--dark-hl-6: #569CD6;
16+
--light-hl-7: #E50000;
17+
--dark-hl-7: #9CDCFE;
18+
--light-hl-8: #0000FF;
19+
--dark-hl-8: #CE9178;
20+
--light-hl-9: #795E26;
21+
--dark-hl-9: #DCDCAA;
22+
--light-hl-10: #098658;
23+
--dark-hl-10: #B5CEA8;
1824
--light-code-background: #FFFFFF;
1925
--dark-code-background: #1E1E1E;
2026
}
@@ -28,6 +34,9 @@
2834
--hl-5: var(--light-hl-5);
2935
--hl-6: var(--light-hl-6);
3036
--hl-7: var(--light-hl-7);
37+
--hl-8: var(--light-hl-8);
38+
--hl-9: var(--light-hl-9);
39+
--hl-10: var(--light-hl-10);
3140
--code-background: var(--light-code-background);
3241
} }
3342

@@ -40,6 +49,9 @@
4049
--hl-5: var(--dark-hl-5);
4150
--hl-6: var(--dark-hl-6);
4251
--hl-7: var(--dark-hl-7);
52+
--hl-8: var(--dark-hl-8);
53+
--hl-9: var(--dark-hl-9);
54+
--hl-10: var(--dark-hl-10);
4355
--code-background: var(--dark-code-background);
4456
} }
4557

@@ -52,6 +64,9 @@
5264
--hl-5: var(--light-hl-5);
5365
--hl-6: var(--light-hl-6);
5466
--hl-7: var(--light-hl-7);
67+
--hl-8: var(--light-hl-8);
68+
--hl-9: var(--light-hl-9);
69+
--hl-10: var(--light-hl-10);
5570
--code-background: var(--light-code-background);
5671
}
5772

@@ -64,6 +79,9 @@
6479
--hl-5: var(--dark-hl-5);
6580
--hl-6: var(--dark-hl-6);
6681
--hl-7: var(--dark-hl-7);
82+
--hl-8: var(--dark-hl-8);
83+
--hl-9: var(--dark-hl-9);
84+
--hl-10: var(--dark-hl-10);
6785
--code-background: var(--dark-code-background);
6886
}
6987

@@ -75,4 +93,7 @@
7593
.hl-5 { color: var(--hl-5); }
7694
.hl-6 { color: var(--hl-6); }
7795
.hl-7 { color: var(--hl-7); }
96+
.hl-8 { color: var(--hl-8); }
97+
.hl-9 { color: var(--hl-9); }
98+
.hl-10 { color: var(--hl-10); }
7899
pre, code { background: var(--code-background); }

docs/static/typedoc/assets/navigation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)