Skip to content

Commit b09f359

Browse files
author
Nathan Walker
committed
chore(Typings): refactored typings to follow a similar pattern suggested by @gdi2290 here: auth0-blog#27 ... Fixed Http api to match latest change in alpha.31
closes auth0-blog#27
1 parent 6df7231 commit b09f359

19 files changed

+5671
-4694
lines changed

src/app/LoggedInOutlet.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Directive, Attribute, ElementRef, DynamicComponentLoader} from 'angular2/angular2';
1+
/// <reference path="../typings/custom.d.ts" />
2+
import {Directive, Attribute, ElementRef, DynamicComponentLoader, Injector} from 'angular2/angular2';
23
import {Router, RouterOutlet} from 'angular2/router';
3-
import {Injector} from 'angular2/di';
44
import {Login} from '../login/login';
55

66
@Directive({
@@ -19,11 +19,11 @@ export class LoggedInRouterOutlet extends RouterOutlet {
1919

2020
}
2121

22-
activate(instruction) {
22+
commit(instruction) {
2323
var url = this._parentRouter.lastNavigationAttempt;
2424
if (!this.publicRoutes[url] && !localStorage.getItem('jwt')) {
2525
instruction.component = Login;
2626
}
27-
return super.activate(instruction);
27+
return super.commit(instruction);
2828
}
2929
}

src/common/BrowserDomAdapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
33
BrowserDomAdapter.makeCurrent();

src/common/jitInjectables.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22
import {ChangeDetection, JitChangeDetection} from 'angular2/change_detection';
33
import {bind} from 'angular2/di';
44

src/home/home.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22

3-
import {Component, View} from 'angular2/angular2';
4-
import {coreDirectives} from 'angular2/directives';
3+
import {Component, View, coreDirectives, Http, Headers} from 'angular2/angular2';
54
import {status, text} from '../utils/fetch';
6-
import {Http} from 'angular2/http';
75
import { Router} from 'angular2/router';
86

97
let styles = require('./home.css');
@@ -44,13 +42,11 @@ export class Home {
4442
_callApi(type, url) {
4543
this.response = null;
4644
this.api = type;
47-
this.http.get(url, {
48-
headers: {
49-
'Accept': 'application/json',
50-
'Content-Type': 'application/json',
51-
'Authorization': 'bearer ' + this.jwt
52-
}
53-
})
45+
var headers = new Headers();
46+
headers.append('Accept', 'application/json');
47+
headers.append('Content-Type', 'application/json');
48+
headers.append('Authorization', 'bearer ' + this.jwt);
49+
this.http.get(url, {headers: headers})
5450
.toRx()
5551
.map(status)
5652
.map(text)

src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/// <reference path="../typings/tsd.d.ts" />
1+
/// <reference path="typings/custom.d.ts" />
22

3-
import { bootstrap } from 'angular2/angular2';
4-
import { bind } from 'angular2/di';
3+
import { bootstrap, bind, formInjectables, httpInjectables } from 'angular2/angular2';
54
import { routerInjectables } from 'angular2/router';
6-
import { formInjectables } from 'angular2/forms';
7-
import { httpInjectables } from 'angular2/http';
85

96
import { App } from './app/app';
107

src/login/login.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22

3-
import {Component, View} from 'angular2/angular2';
3+
import {Component, View, Http, Headers} from 'angular2/angular2';
44
import {status, json} from '../utils/fetch';
5-
import {Http} from 'angular2/http';
65
import { Router, RouterLink } from 'angular2/router';
76

87

@@ -24,15 +23,17 @@ export class Login {
2423

2524
login(event, username, password) {
2625
event.preventDefault();
27-
this.http.post('http://localhost:3001/sessions/create', {
28-
headers: {
29-
'Accept': 'application/json',
30-
'Content-Type': 'application/json'
31-
},
32-
body: JSON.stringify({
26+
var headers = new Headers();
27+
headers.append('Accept', 'application/json');
28+
headers.append('Content-Type', 'application/json');
29+
this.http.post('http://localhost:3001/sessions/create',
30+
JSON.stringify({
3331
username, password
34-
})
35-
})
32+
}),
33+
{
34+
headers: headers
35+
}
36+
)
3637
.toRx()
3738
.map(status)
3839
.map(json)

src/signup/signup.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22

3-
import {coreDirectives} from 'angular2/directives';
4-
import {Component, View} from 'angular2/angular2';
3+
import {Component, View, coreDirectives, Http, Headers} from 'angular2/angular2';
54
import {status, json} from '../utils/fetch';
6-
import {Http} from 'angular2/http';
75
import { Router, RouterLink } from 'angular2/router';
86

97
let styles = require('./signup.css');
@@ -23,15 +21,17 @@ export class Signup {
2321

2422
signup(event, username, password) {
2523
event.preventDefault();
26-
this.http.post('http://localhost:3001/users', {
27-
headers: {
28-
'Accept': 'application/json',
29-
'Content-Type': 'application/json'
30-
},
31-
body: JSON.stringify({
24+
var headers = new Headers();
25+
headers.append('Accept', 'application/json');
26+
headers.append('Content-Type', 'application/json');
27+
this.http.post('http://localhost:3001/users',
28+
JSON.stringify({
3229
username, password
33-
})
34-
})
30+
}),
31+
{
32+
headers: headers
33+
}
34+
)
3535
.toRx()
3636
.map(status)
3737
.map(json)

src/typings/browser.d.ts

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
interface ObjectConstructor {
2+
assign(target: any, ...sources: any[]): any;
3+
observe(target: any, callback: Function, acceptList?: Array<any>): void;
4+
}
5+
6+
declare module "angular2/src/dom/browser_adapter" {
7+
class BrowserDomAdapter {
8+
static makeCurrent(): void;
9+
logError(error: any): void;
10+
attrToPropMap: any;
11+
query(selector: string): any;
12+
querySelector(el: any, selector: string): Node;
13+
querySelectorAll(el: any, selector: string): List<any>;
14+
on(el: any, evt: any, listener: any): void;
15+
onAndCancel(el: any, evt: any, listener: any): Function;
16+
dispatchEvent(el: any, evt: any): void;
17+
createMouseEvent(eventType: string): MouseEvent;
18+
createEvent(eventType: any): Event;
19+
getInnerHTML(el: any): any;
20+
getOuterHTML(el: any): any;
21+
nodeName(node: Node): string;
22+
nodeValue(node: Node): string;
23+
type(node: HTMLInputElement): string;
24+
content(node: Node): Node;
25+
firstChild(el: any): Node;
26+
nextSibling(el: any): Node;
27+
parentElement(el: any): any;
28+
childNodes(el: any): List<Node>;
29+
childNodesAsList(el: any): List<any>;
30+
clearNodes(el: any): void;
31+
appendChild(el: any, node: any): void;
32+
removeChild(el: any, node: any): void;
33+
replaceChild(el: Node, newChild: any, oldChild: any): void;
34+
remove(el: any): any;
35+
insertBefore(el: any, node: any): void;
36+
insertAllBefore(el: any, nodes: any): void;
37+
insertAfter(el: any, node: any): void;
38+
setInnerHTML(el: any, value: any): void;
39+
getText(el: any): any;
40+
setText(el: any, value: string): void;
41+
getValue(el: any): any;
42+
setValue(el: any, value: string): void;
43+
getChecked(el: any): any;
44+
setChecked(el: any, value: boolean): void;
45+
createTemplate(html: any): HTMLElement;
46+
createElement(tagName: any, doc?: Document): HTMLElement;
47+
createTextNode(text: string, doc?: Document): Text;
48+
createScriptTag(attrName: string, attrValue: string, doc?: Document): HTMLScriptElement;
49+
createStyleElement(css: string, doc?: Document): HTMLStyleElement;
50+
createShadowRoot(el: HTMLElement): DocumentFragment;
51+
getShadowRoot(el: HTMLElement): DocumentFragment;
52+
getHost(el: HTMLElement): HTMLElement;
53+
clone(node: Node): Node;
54+
hasProperty(element: any, name: string): boolean;
55+
getElementsByClassName(element: any, name: string): any;
56+
getElementsByTagName(element: any, name: string): any;
57+
classList(element: any): List<any>;
58+
addClass(element: any, classname: string): void;
59+
removeClass(element: any, classname: string): void;
60+
hasClass(element: any, classname: string): any;
61+
setStyle(element: any, stylename: string, stylevalue: string): void;
62+
removeStyle(element: any, stylename: string): void;
63+
getStyle(element: any, stylename: string): any;
64+
tagName(element: any): string;
65+
attributeMap(element: any): any;
66+
hasAttribute(element: any, attribute: string): any;
67+
getAttribute(element: any, attribute: string): any;
68+
setAttribute(element: any, name: string, value: string): void;
69+
removeAttribute(element: any, attribute: string): any;
70+
templateAwareRoot(el: any): any;
71+
createHtmlDocument(): Document;
72+
defaultDoc(): Document;
73+
getBoundingClientRect(el: any): any;
74+
getTitle(): string;
75+
setTitle(newTitle: string): void;
76+
elementMatches(n: any, selector: string): boolean;
77+
isTemplateElement(el: any): boolean;
78+
isTextNode(node: Node): boolean;
79+
isCommentNode(node: Node): boolean;
80+
isElementNode(node: Node): boolean;
81+
hasShadowRoot(node: any): boolean;
82+
isShadowRoot(node: any): boolean;
83+
importIntoDoc(node: Node): Node;
84+
isPageRule(rule: any): boolean;
85+
isStyleRule(rule: any): boolean;
86+
isMediaRule(rule: any): boolean;
87+
isKeyframesRule(rule: any): boolean;
88+
getHref(el: Element): string;
89+
getEventKey(event: any): string;
90+
getGlobalEventTarget(target: string): EventTarget;
91+
getHistory(): History;
92+
getLocation(): Location;
93+
getBaseHref(): any;
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
/*
2+
* Our custom types
3+
*/
14
/// <reference path="browser.d.ts" />
2-
/// <reference path="ng2.d.ts" />
35
/// <reference path="webpack.d.ts" />
46
/// <reference path="jwt_decode.d.ts" />
7+
8+
/*
9+
* tsd generated types
10+
*/
11+
/// <reference path="../../typings/tsd.d.ts" />
File renamed without changes.
File renamed without changes.

src/utils/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../typings/custom.d.ts" />
22

33
export function status(response) {
44
if (response.status >= 200 && response.status < 300) {

tsd.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"bundle": "typings/tsd.d.ts",
77
"installed": {
88
"angular2/angular2.d.ts": {
9-
"commit": "2a5858c16563634453533009242b8e0b18521370"
9+
"commit": "212793c4be051977f73675fa9bb125d891df037a"
10+
},
11+
"angular2/router.d.ts": {
12+
"commit": "212793c4be051977f73675fa9bb125d891df037a"
1013
},
1114
"rx/rx.d.ts": {
1215
"commit": "8c7444882a2bc2ab87387f8f736a7d97e89b9c90"

typings/_custom/browser.d.ts

-4
This file was deleted.

0 commit comments

Comments
 (0)