Skip to content

Commit fc56f85

Browse files
committed
chore(start): updated ng2 0.44
1 parent 4d97d19 commit fc56f85

File tree

18 files changed

+79
-6534
lines changed

18 files changed

+79
-6534
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
},
3535
"devDependencies": {
3636
"css-loader": "0.20.1",
37-
"xtend": "4.0.0",
38-
"loader-utils": "0.2.11",
3937
"exports-loader": "0.6.2",
4038
"expose-loader": "0.7.0",
4139
"file-loader": "0.8.4",
4240
"html-webpack-plugin": "1.6.2",
4341
"imports-loader": "0.6.5",
4442
"json-loader": "0.5.3",
43+
"loader-utils": "0.2.11",
4544
"style-loader": "0.12.4",
45+
"ts-loader": "0.5.6",
4646
"typescript": "1.6.2",
47-
"typescript-simple-loader": "0.3.8",
4847
"url-loader": "0.5.6",
4948
"webpack": "1.12.2",
50-
"webpack-dev-server": "1.12.1"
49+
"webpack-dev-server": "1.12.1",
50+
"xtend": "4.0.0"
5151
}
5252
}

src/app/LoggedInOutlet.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import {Directive, Attribute, ElementRef, DynamicComponentLoader} from 'angular2/angular2';
2-
import {Router, RouterOutlet} from 'angular2/router';
3-
import {Injector} from 'angular2/di';
2+
import {Router, RouterOutlet, ComponentInstruction} from 'angular2/router';
43
import {Login} from '../login/login';
54

65
@Directive({
76
selector: 'router-outlet'
87
})
98
export class LoggedInRouterOutlet extends RouterOutlet {
10-
publicRoutes: any
11-
constructor(public _elementRef: ElementRef, public _loader: DynamicComponentLoader,
12-
public _parentRouter: Router, @Attribute('name') nameAttr: string) {
13-
super(_elementRef, _loader, _parentRouter, nameAttr);
9+
publicRoutes:any;
10+
private parentRouter:Router;
1411

15-
this.publicRoutes = {
16-
'/login': true,
17-
'/signup': true
18-
};
12+
constructor(_elementRef:ElementRef, _loader:DynamicComponentLoader,
13+
_parentRouter:Router, @Attribute('name') nameAttr:string) {
14+
super(_elementRef, _loader, _parentRouter, nameAttr);
1915

16+
this.parentRouter = _parentRouter;
17+
this.publicRoutes = {
18+
'/login': true,
19+
'/signup': true
20+
};
2021
}
2122

22-
activate(instruction) {
23-
var url = this._parentRouter.lastNavigationAttempt;
23+
activate(instruction: ComponentInstruction) {
24+
var url = this.parentRouter.lastNavigationAttempt;
2425
if (!this.publicRoutes[url] && !localStorage.getItem('jwt')) {
25-
instruction.component = Login;
26+
// todo: redirect to Login
27+
//instruction.component = Login;
2628
}
2729
return super.activate(instruction);
2830
}

src/app/app.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
2-
31
import {View, Component} from 'angular2/angular2';
42
import {Location, RouteConfig, RouterLink, Router} from 'angular2/router';
3+
54
import {LoggedInRouterOutlet} from './LoggedInOutlet';
65
import {Home} from '../home/home';
76
import {Login} from '../login/login';
@@ -19,9 +18,9 @@ let template = require('./app.html');
1918
})
2019
@RouteConfig([
2120
{ path: '/', redirectTo: '/home' },
22-
{ path: '/home', as: 'home', component: Home },
23-
{ path: '/login', as: 'login', component: Login },
24-
{ path: '/signup', as: 'signup', component: Signup }
21+
{ path: '/home', as: 'Home', component: Home },
22+
{ path: '/login', as: 'Login', component: Login },
23+
{ path: '/signup', as: 'Signup', component: Signup }
2524
])
2625
export class App {
2726
constructor(public router: Router) {

src/home/home.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
import {Component, View, CORE_DIRECTIVES} from 'angular2/angular2';
2+
import { Router } from 'angular2/router';
23

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

8-
let styles = require('./home.css');
6+
let styles = require('./home.css');
97
let template = require('./home.html');
108

119

1210
@Component({
1311
selector: 'home'
1412
})
1513
@View({
16-
styles: [ styles ],
14+
directives: [CORE_DIRECTIVES],
1715
template: template,
18-
directives: [ coreDirectives ]
16+
styles: [styles]
1917
})
2018
export class Home {
21-
jwt: string;
22-
decodedJwt: string;
23-
response: string;
24-
api: string;
19+
jwt:string;
20+
decodedJwt:string;
21+
response:string;
22+
api:string;
2523

26-
constructor(public router: Router) {
24+
constructor(public router:Router) {
2725
this.jwt = localStorage.getItem('jwt');
2826
this.decodedJwt = this.jwt && window.jwt_decode(this.jwt);
2927
}
3028

3129
logout() {
3230
localStorage.removeItem('jwt');
33-
this.router.parent.navigate('/login');
31+
this.router.parent.navigate(['/login']);
3432
}
3533

3634
callAnonymousApi() {
@@ -40,25 +38,25 @@ export class Home {
4038
callSecuredApi() {
4139
this._callApi('Secured', 'http://localhost:3001/api/protected/random-quote');
4240
}
41+
4342
_callApi(type, url) {
4443
this.response = null;
4544
this.api = type;
4645
window.fetch(url, {
47-
method: 'GET',
48-
headers: {
49-
'Accept': 'application/json',
50-
'Content-Type': 'application/json',
51-
'Authorization': 'bearer ' + this.jwt
52-
}
53-
})
54-
.then(status)
55-
.then(text)
56-
.then((response) => {
57-
this.response = response;
58-
})
59-
.catch((error) => {
60-
this.response = error.message;
61-
});
46+
method: 'GET',
47+
headers: {
48+
'Accept': 'application/json',
49+
'Content-Type': 'application/json',
50+
'Authorization': 'bearer ' + this.jwt
51+
}
52+
})
53+
.then(status)
54+
.then(text)
55+
.then((response) => {
56+
this.response = response;
57+
})
58+
.catch((error) => {
59+
this.response = error.message;
60+
});
6261
}
63-
6462
}

src/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
/// <reference path="../typings/tsd.d.ts" />
2-
3-
import { bootstrap } from 'angular2/angular2';
4-
import { bind } from 'angular2/di';
5-
import { routerInjectables } from 'angular2/router';
6-
import { formInjectables } from 'angular2/forms';
7-
import { httpInjectables } from 'angular2/http';
1+
import { bootstrap, FORM_PROVIDERS } from 'angular2/angular2';
2+
import { ROUTER_PROVIDERS } from 'angular2/router';
3+
import { HTTP_PROVIDERS } from 'angular2/http';
84

95
import { App } from './app/app';
106

117
bootstrap(
128
App,
139
[
14-
formInjectables,
15-
routerInjectables,
16-
httpInjectables
10+
FORM_PROVIDERS,
11+
ROUTER_PROVIDERS,
12+
HTTP_PROVIDERS
1713
]
1814
);

src/login/login.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
2-
31
import {Component, View} from 'angular2/angular2';
4-
import {status, json} from '../utils/fetch'
52
import { Router, RouterLink } from 'angular2/router';
6-
3+
import {status, json} from '../utils/fetch'
74

85
let styles = require('./login.css');
96
let template = require('./login.html');
107

11-
128
@Component({
139
selector: 'login'
1410
})
1511
@View({
16-
styles: [ styles ],
12+
directives: [RouterLink],
1713
template: template,
18-
directives: [RouterLink]
14+
styles: [ styles ]
1915
})
2016
export class Login {
2117
constructor(public router: Router) {
@@ -37,7 +33,7 @@ export class Login {
3733
.then(json)
3834
.then((response) => {
3935
localStorage.setItem('jwt', response.id_token);
40-
this.router.parent.navigate('/home');
36+
this.router.parent.navigate(['/home']);
4137
})
4238
.catch((error) => {
4339
alert(error.message);
@@ -47,6 +43,6 @@ export class Login {
4743

4844
signup(event) {
4945
event.preventDefault();
50-
this.router.parent.navigate('/signup');
46+
this.router.parent.navigate(['/signup']);
5147
}
5248
}

src/signup/signup.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
2-
3-
import {coreDirectives} from 'angular2/directives';
4-
import {Component, View} from 'angular2/angular2';
1+
import {CORE_DIRECTIVES, Component, View} from 'angular2/angular2';
52
import {status, json} from '../utils/fetch';
63
import { Router, RouterLink } from 'angular2/router';
74

@@ -12,9 +9,9 @@ let template = require('./signup.html');
129
selector: 'signup'
1310
})
1411
@View({
15-
directives: [ RouterLink, coreDirectives ],
16-
styles: [ styles ],
17-
template: template
12+
directives: [ RouterLink, CORE_DIRECTIVES ],
13+
template: template,
14+
styles: [ styles ]
1815
})
1916
export class Signup {
2017
constructor(public router: Router) {
@@ -36,7 +33,7 @@ export class Signup {
3633
.then(json)
3734
.then((response) => {
3835
localStorage.setItem('jwt', response.id_token);
39-
this.router.navigate('/home');
36+
this.router.navigate(['/home']);
4037
})
4138
.catch((error) => {
4239
alert(error.message);
@@ -46,7 +43,7 @@ export class Signup {
4643

4744
login(event) {
4845
event.preventDefault();
49-
this.router.parent.navigate('/login');
46+
this.router.parent.navigate(['/login']);
5047
}
5148

5249
}

tsconfig.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
"compilerOptions": {
44
"target": "es5",
55
"module": "commonjs",
6-
"declaration": false,
6+
"declaration": true,
77
"noImplicitAny": false,
8-
"removeComments": true,
8+
"removeComments": false,
99
"noLib": false,
1010
"emitDecoratorMetadata": true,
11+
"experimentalDecorators": true,
1112
"sourceMap": true,
1213
"listFiles": true,
1314
"outDir": "dist"
1415
},
16+
"exclude": [
17+
"node_modules"
18+
],
1519
"files": [
16-
"node_modules/typescript/bin/dom.d.ts",
17-
"src/custom_typings/ng2.d.ts",
18-
"typings/tsd.d.ts",
19-
"src/components/app.ts",
20-
"src/bootstrap.ts"
20+
"src/index.ts"
2121
]
2222
}

tsd.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

typings/_custom/custom.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/// <reference path="browser.d.ts" />
2-
/// <reference path="ng2.d.ts" />
32
/// <reference path="webpack.d.ts" />
43
/// <reference path="jwt_decode.d.ts" />

0 commit comments

Comments
 (0)