forked from angular-ui/ui-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoreservices.ts
84 lines (70 loc) · 2.22 KB
/
coreservices.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* This module is a stub for core services such as Dependency Injection or Browser Location.
* Core services may be implemented by a specific framework, such as ng1 or ng2, or be pure javascript.
*
* @module common
*/
/** for typedoc */
import {IInjectable, Obj} from "./common";
let notImplemented = (fnname: string) => () => {
throw new Error(`${fnname}(): No coreservices implementation for UI-Router is loaded. You should include one of: ['angular1.js']`);
};
let services: CoreServices = {
$q: undefined,
$injector: undefined,
location: <any> {},
locationConfig: <any> {},
template: <any> {}
};
["setUrl", "path", "search", "hash", "onChange"]
.forEach(key => services.location[key] = notImplemented(key));
["port", "protocol", "host", "baseHref", "html5Mode", "hashPrefix" ]
.forEach(key => services.locationConfig[key] = notImplemented(key));
export interface $QLikeDeferred {
resolve: (val?: any) => void;
reject: (reason?: any) => void;
promise: Promise<any>;
}
export interface $QLike {
when<T>(val?: T): Promise<T>;
reject<T>(reason: any): Promise<T>;
defer(): $QLikeDeferred;
all(promises: { [key: string]: Promise<any> }): Promise<any>;
all(promises: Promise<any>[]): Promise<any[]>;
}
export interface $InjectorLike {
get(token: any): any;
has(token: any): boolean;
invoke(fn: IInjectable, context?: any, locals?: Obj): any;
annotate(fn: IInjectable, strictDi?: boolean): any[];
strictDi?: boolean;
}
export interface CoreServices {
$q: $QLike;
$injector: $InjectorLike;
/** Services related to getting or setting the browser location (url) */
location: LocationServices;
/** Retrieves configuration for how to construct a URL. */
locationConfig: LocationConfig;
template: TemplateServices;
}
export interface LocationServices {
setUrl(newurl: string, replace?: boolean): void;
path(): string;
search(): string;
hash(): string;
onChange(callback: Function): Function;
}
export interface LocationConfig {
port(): number;
protocol(): string;
host(): string;
baseHref(): string;
html5Mode(): boolean;
hashPrefix(): string;
hashPrefix(newprefix: string): string;
}
export interface TemplateServices {
get(url: string): Promise<string>;
}
export {services};