|
2 | 2 | * This module is a stub for core services such as Dependency Injection or Browser Location. |
3 | 3 | * Core services may be implemented by a specific framework, such as ng1 or ng2, or be pure javascript. |
4 | 4 | * |
5 | | - * @module common |
6 | | - */ |
7 | | -/** for typedoc */ |
| 5 | + * @publicapi @module common |
| 6 | + */ /** */ |
8 | 7 | import { IInjectable, Obj } from './common'; |
9 | 8 | import { Disposable } from '../interface'; |
| 9 | +import { UrlConfig, UrlService } from '../url'; |
10 | 10 |
|
11 | 11 | const noImpl = (fnname: string) => () => { |
12 | 12 | throw new Error(`No implementation for ${fnname}. The framework specific code did not implement this method.`); |
@@ -48,154 +48,48 @@ export interface CoreServices { |
48 | 48 | $injector: $InjectorLike; |
49 | 49 | } |
50 | 50 |
|
| 51 | +/** |
| 52 | + * Handles low level URL read/write |
| 53 | + * |
| 54 | + * This service handles low level reads and updates of the URL and listens for url changes. |
| 55 | + * Implementors should pass these through to the underlying URL mechanism. |
| 56 | + * The underlying URL mechanism might be browser APIs, framework APIs, or some 3rd party URL management library. |
| 57 | + * |
| 58 | + * UI-Router Core includes three basic implementations: |
| 59 | + * |
| 60 | + * - [[PushStateLocationService]] |
| 61 | + * - [[HashLocationService]] |
| 62 | + * - [[MemoryLocationService]] |
| 63 | + */ |
51 | 64 | export interface LocationServices extends Disposable { |
52 | | - /** |
53 | | - * Gets the current url string |
54 | | - * |
55 | | - * The URL is normalized using the internal [[path]]/[[search]]/[[hash]] values. |
56 | | - * |
57 | | - * For example, the URL may be stored in the hash ([[HashLocationServices]]) or |
58 | | - * have a base HREF prepended ([[PushStateLocationServices]]). |
59 | | - * |
60 | | - * The raw URL in the browser might be: |
61 | | - * |
62 | | - * ``` |
63 | | - * http://mysite.com/somepath/index.html#/internal/path/123?param1=foo#anchor |
64 | | - * ``` |
65 | | - * |
66 | | - * or |
67 | | - * |
68 | | - * ``` |
69 | | - * http://mysite.com/basepath/internal/path/123?param1=foo#anchor |
70 | | - * ``` |
71 | | - * |
72 | | - * then this method returns: |
73 | | - * |
74 | | - * ``` |
75 | | - * /internal/path/123?param1=foo#anchor |
76 | | - * ``` |
77 | | - * |
78 | | - * |
79 | | - * #### Example: |
80 | | - * ```js |
81 | | - * locationServices.url(); // "/some/path?query=value#anchor" |
82 | | - * ``` |
83 | | - * |
84 | | - * @returns the current value of the url, as a string. |
85 | | - */ |
86 | | - url(): string; |
87 | | - |
88 | | - /** |
89 | | - * Updates the url, or gets the current url |
90 | | - * |
91 | | - * Updates the url, changing it to the value in `newurl` |
92 | | - * |
93 | | - * #### Example: |
94 | | - * ```js |
95 | | - * locationServices.url("/some/path?query=value#anchor", true); |
96 | | - * ``` |
97 | | - * |
98 | | - * @param newurl The new value for the URL. |
99 | | - * This url should reflect only the new internal [[path]], [[search]], and [[hash]] values. |
100 | | - * It should not include the protocol, site, port, or base path of an absolute HREF. |
101 | | - * @param replace When true, replaces the current history entry (instead of appending it) with this new url |
102 | | - * @param state The history's state object, i.e., pushState (if the LocationServices implementation supports it) |
103 | | - * @return the url (after potentially being processed) |
104 | | - */ |
105 | | - url(newurl: string, replace?: boolean, state?: any): string; |
106 | | - |
107 | | - /** |
108 | | - * Gets the path part of the current url |
109 | | - * |
110 | | - * If the current URL is `/some/path?query=value#anchor`, this returns `/some/path` |
111 | | - * |
112 | | - * @return the path portion of the url |
113 | | - */ |
114 | | - path(): string; |
115 | | - |
116 | | - /** |
117 | | - * Gets the search part of the current url as an object |
118 | | - * |
119 | | - * If the current URL is `/some/path?query=value#anchor`, this returns `{ query: 'value' }` |
120 | | - * |
121 | | - * @return the search (querystring) portion of the url, as an object |
122 | | - */ |
123 | | - search(): { [key: string]: any }; |
124 | | - |
125 | | - /** |
126 | | - * Gets the hash part of the current url |
127 | | - * |
128 | | - * If the current URL is `/some/path?query=value#anchor`, this returns `anchor` |
129 | | - * |
130 | | - * @return the hash (anchor) portion of the url |
131 | | - */ |
132 | | - hash(): string; |
133 | | - |
134 | | - /** |
135 | | - * Registers a url change handler |
136 | | - * |
137 | | - * #### Example: |
138 | | - * ```js |
139 | | - * let deregisterFn = locationServices.onChange((evt) => console.log("url change", evt)); |
140 | | - * ``` |
141 | | - * |
142 | | - * @param callback a function that will be called when the url is changing |
143 | | - * @return a function that de-registers the callback |
144 | | - */ |
145 | | - onChange(callback: Function): Function; |
| 65 | + /** See: [[UrlService.url]] */ url: UrlService['url']; |
| 66 | + /** See: [[UrlService.path]] */ path: UrlService['path']; |
| 67 | + /** See: [[UrlService.search]] */ search: UrlService['search']; |
| 68 | + /** See: [[UrlService.hash]] */ hash: UrlService['hash']; |
| 69 | + /** See: [[UrlService.onChange]] */ onChange: UrlService['onChange']; |
146 | 70 | } |
147 | 71 |
|
148 | 72 | /** |
149 | | - * This service returns the location configuration |
| 73 | + * Returns low level URL configuration and metadata |
150 | 74 | * |
151 | 75 | * This service returns information about the location configuration. |
152 | 76 | * This service is primarily used when building URLs (e.g., for `hrefs`) |
| 77 | + * |
| 78 | + * Implementors should pass these through to the underlying URL APIs. |
| 79 | + * The underlying URL mechanism might be browser APIs, framework APIs, or some 3rd party URL management library. |
| 80 | + * |
| 81 | + * UI-Router Core includes two basic implementations: |
| 82 | + * |
| 83 | + * - [[BrowserLocationConfig]] |
| 84 | + * - [[MemoryLocationConfig]] |
153 | 85 | */ |
154 | 86 | export interface LocationConfig extends Disposable { |
155 | | - /** |
156 | | - * Gets the port, e.g., `80` |
157 | | - * |
158 | | - * @return the port number |
159 | | - */ |
160 | | - port(): number; |
161 | | - /** |
162 | | - * Gets the protocol, e.g., `http` |
163 | | - * |
164 | | - * @return the protocol |
165 | | - */ |
166 | | - protocol(): string; |
167 | | - /** |
168 | | - * Gets the host, e.g., `localhost` |
169 | | - * |
170 | | - * @return the protocol |
171 | | - */ |
172 | | - host(): string; |
173 | | - /** |
174 | | - * Gets the base Href, e.g., `http://localhost/approot/` |
175 | | - * |
176 | | - * @return the application's base href |
177 | | - */ |
178 | | - baseHref(): string; |
179 | | - /** |
180 | | - * Returns true when running in pushstate mode |
181 | | - * |
182 | | - * @return true when running in pushstate mode |
183 | | - */ |
184 | | - html5Mode(): boolean; |
185 | | - /** |
186 | | - * Gets the hashPrefix (when not running in pushstate mode) |
187 | | - * |
188 | | - * If the current url is `http://localhost/app#!/uirouter/path/#anchor`, it returns `!` which is the prefix for the "hashbang" portion. |
189 | | - * |
190 | | - * @return the hash prefix |
191 | | - */ |
192 | | - hashPrefix(): string; |
193 | | - /** |
194 | | - * Sets the hashPrefix (when not running in pushstate mode) |
195 | | - * |
196 | | - * @return the new hash prefix |
197 | | - */ |
198 | | - hashPrefix(newprefix: string): string; |
| 87 | + /** See: [[UrlConfig.port]] */ port: UrlConfig['port']; |
| 88 | + /** See: [[UrlConfig.protocol]] */ protocol: UrlConfig['protocol']; |
| 89 | + /** See: [[UrlConfig.host]] */ host: UrlConfig['host']; |
| 90 | + /** See: [[UrlConfig.baseHref]] */ baseHref: UrlConfig['baseHref']; |
| 91 | + /** See: [[UrlConfig.html5Mode]] */ html5Mode: UrlConfig['html5Mode']; |
| 92 | + /** See: [[UrlConfig.hashPrefix]] */ hashPrefix: UrlConfig['hashPrefix']; |
199 | 93 | } |
200 | 94 |
|
201 | 95 | export { services }; |
0 commit comments