UNPKG

3.11 kBTypeScriptView Raw
1/**
2 * This module is a stub for core services such as Dependency Injection or Browser Location.
3 * Core services may be implemented by a specific framework, such as ng1 or ng2, or be pure javascript.
4 *
5 * @packageDocumentation
6 */
7import { IInjectable, Obj } from './common';
8import { Disposable } from '../interface';
9import { UrlConfig, UrlService } from '../url';
10export declare const makeStub: <T>(service: string, methods: (keyof T)[]) => T;
11declare const services: CoreServices;
12export interface $QLikeDeferred {
13 resolve: (val?: any) => void;
14 reject: (reason?: any) => void;
15 promise: Promise<any>;
16}
17export interface $QLike {
18 when<T>(value?: T | PromiseLike<T>): Promise<T>;
19 reject<T>(reason: any): Promise<T>;
20 defer(): $QLikeDeferred;
21 all(promises: {
22 [key: string]: Promise<any>;
23 }): Promise<any>;
24 all(promises: Promise<any>[]): Promise<any[]>;
25}
26export interface $InjectorLike {
27 strictDi?: boolean;
28 get(token: any): any;
29 get<T>(token: any): T;
30 has(token: any): boolean;
31 invoke(fn: IInjectable, context?: any, locals?: Obj): any;
32 annotate(fn: IInjectable, strictDi?: boolean): any[];
33}
34export interface CoreServices {
35 $q: $QLike;
36 $injector: $InjectorLike;
37}
38/**
39 * Handles low level URL read/write
40 *
41 * This service handles low level reads and updates of the URL and listens for url changes.
42 * Implementors should pass these through to the underlying URL mechanism.
43 * The underlying URL mechanism might be browser APIs, framework APIs, or some 3rd party URL management library.
44 *
45 * UI-Router Core includes three basic implementations:
46 *
47 * - [[PushStateLocationService]]
48 * - [[HashLocationService]]
49 * - [[MemoryLocationService]]
50 */
51export interface LocationServices extends Disposable {
52 /** See: [[UrlService.url]] */ url: UrlService['url'];
53 /** See: [[UrlService.path]] */ path: UrlService['path'];
54 /** See: [[UrlService.search]] */ search: UrlService['search'];
55 /** See: [[UrlService.hash]] */ hash: UrlService['hash'];
56 /** See: [[UrlService.onChange]] */ onChange: UrlService['onChange'];
57}
58/**
59 * Returns low level URL configuration and metadata
60 *
61 * This service returns information about the location configuration.
62 * This service is primarily used when building URLs (e.g., for `hrefs`)
63 *
64 * Implementors should pass these through to the underlying URL APIs.
65 * The underlying URL mechanism might be browser APIs, framework APIs, or some 3rd party URL management library.
66 *
67 * UI-Router Core includes two basic implementations:
68 *
69 * - [[BrowserLocationConfig]]
70 * - [[MemoryLocationConfig]]
71 */
72export interface LocationConfig extends Disposable {
73 /** See: [[UrlConfig.port]] */ port: UrlConfig['port'];
74 /** See: [[UrlConfig.protocol]] */ protocol: UrlConfig['protocol'];
75 /** See: [[UrlConfig.host]] */ host: UrlConfig['host'];
76 /** See: [[UrlConfig.baseHref]] */ baseHref: UrlConfig['baseHref'];
77 /** See: [[UrlConfig.html5Mode]] */ html5Mode: UrlConfig['html5Mode'];
78 /** See: [[UrlConfig.hashPrefix]] */ hashPrefix: UrlConfig['hashPrefix'];
79}
80export { services };