Skip to content

Commit 1d3f8b7

Browse files
Sfx build 2 (#75)
* refactor todolist delTodo * Finish implement SFX build * revert changedetector usage * call enableProdMode when bundling * update to new rc router * compile ts to tmp folder * refactor clean-ts to del tmp * refactor typescript task * update readme * fix test import * update typings 1.0 and fix breaking things
1 parent ea6b084 commit 1d3f8b7

21 files changed

Lines changed: 100 additions & 117 deletions

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
/build
44
/report
55
/typings
6+
/tmp
67
.DS_Store
7-
app/**/*.js
8-
app/**/*.js.map
9-
test/**/*.js
10-
test/**/*.js.map
118
assets/styles/*.css

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
> Angular 2 is still in **Release Candidate** stage, please **don't** use this in production
11-
> Follow it [here](https://splintercode.github.io/is-angular-2-ready/)
11+
> Follow Angular 2 Changelog [here](https://github.com/angular/angular/blob/master/CHANGELOG.md)
1212
1313
## Table of Content
1414
* [Introduction](#introduction)
@@ -92,7 +92,7 @@ You can create production build by running:
9292
```bash
9393
gulp build
9494
```
95-
or you can create production build and then serve it using `live-server` by running:
95+
or you can create production build and then serve it using Browsersync by running:
9696
```bash
9797
gulp serve-build
9898
```

app/app.component.spec.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,10 @@ import {
55
inject,
66
async,
77
describe,
8-
MockApplicationRef
98
} from '@angular/core/testing';
10-
import {
11-
TestComponentBuilder
12-
} from '@angular/compiler/testing';
13-
import {
14-
ROUTER_PRIMARY_COMPONENT,
15-
ROUTER_PROVIDERS
16-
} from '@angular/router-deprecated';
17-
import {
18-
APP_BASE_HREF,
19-
} from '@angular/common';
20-
import { Component, provide, ApplicationRef } from '@angular/core';
9+
import { TestComponentBuilder } from '@angular/compiler/testing';
10+
import { ROUTER_FAKE_PROVIDERS } from '@angular/router/testing';
11+
import { Component } from '@angular/core';
2112
import { AppComponent } from './app.component';
2213
import { LoggerService } from './blocks/logger.service';
2314

@@ -32,10 +23,7 @@ class TestComponent {
3223
describe('AppComponent', () => {
3324
beforeEachProviders(() => [
3425
LoggerService,
35-
ROUTER_PROVIDERS,
36-
provide(ROUTER_PRIMARY_COMPONENT, { useValue: AppComponent }),
37-
provide(ApplicationRef, { useClass: MockApplicationRef }),
38-
provide(APP_BASE_HREF, { useValue: '/' }),
26+
ROUTER_FAKE_PROVIDERS
3927
]);
4028

4129
it('should have brand Angular 2 Starter', async(inject([TestComponentBuilder],

app/app.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {Component} from '@angular/core';
2-
import {RouterOutlet, RouteConfig, RouteDefinition} from '@angular/router-deprecated';
2+
import {Routes, ROUTER_DIRECTIVES} from '@angular/router';
33
import {APP_ROUTES} from './app.routes';
44
import {NavbarComponent} from './navbar/navbar.component';
55
import {LoggerService} from './blocks/logger.service';
66

77
@Component({
88
selector: 'as-main-app',
99
templateUrl: 'app/app.html',
10-
directives: [RouterOutlet, NavbarComponent]
10+
directives: [NavbarComponent, ROUTER_DIRECTIVES]
1111
})
12-
@RouteConfig(APP_ROUTES)
12+
@Routes(APP_ROUTES)
1313
export class AppComponent {
14-
public appRoutes: RouteDefinition[];
14+
public appRoutes: any[];
1515
private logger: LoggerService;
1616

1717
constructor(logger: LoggerService) {

app/app.routes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {RouteDefinition} from '@angular/router-deprecated';
21
import {HomeComponent} from './home/home.component';
32
import {TodolistComponent} from './todolist/todolist.component';
43
import {SimplebindComponent} from './simplebind/simplebind.component';
54

6-
export var APP_ROUTES: RouteDefinition[] = [
7-
{ path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true },
5+
export var APP_ROUTES: any[] = [
6+
{ path: '/', name: 'Home', component: HomeComponent },
87
{ path: '/simplebind', name: 'Simplebind', component: SimplebindComponent },
98
{ path: '/todolist', name: 'Todolist', component: TodolistComponent }
109
];

app/bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// This file is for production only, please leave it blank

app/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {bootstrap} from '@angular/platform-browser-dynamic';
2-
import {ROUTER_PROVIDERS} from '@angular/router-deprecated';
2+
import {enableProdMode} from '@angular/core';
3+
import {ROUTER_PROVIDERS} from '@angular/router';
34
import {AppComponent} from './app.component';
45
import {LoggerService} from './blocks/logger.service';
56

7+
declare var ENV: string;
8+
9+
if (ENV === 'production') {
10+
enableProdMode();
11+
}
12+
613
bootstrap(AppComponent, [
714
LoggerService, ROUTER_PROVIDERS
815
]);

app/navbar/navbar.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {Component, Input, ChangeDetectionStrategy} from '@angular/core';
22
import {CORE_DIRECTIVES} from '@angular/common';
3-
import {RouterLink, RouteDefinition} from '@angular/router-deprecated';
3+
import {ROUTER_DIRECTIVES} from '@angular/router';
44

55
@Component({
66
selector: 'as-navbar',
77
templateUrl: 'app/navbar/navbar.html',
88
changeDetection: ChangeDetectionStrategy.OnPush,
9-
directives: [RouterLink, CORE_DIRECTIVES]
9+
directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES]
1010
})
1111
export class NavbarComponent {
1212
@Input() brand: string;
13-
@Input() routes: RouteDefinition[];
13+
@Input() routes: any[];
1414
}

app/navbar/navbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212
<div id="navbar" class="collapse navbar-collapse">
1313
<ul class="nav navbar-nav">
14-
<li *ngFor="let route of routes"><a [routerLink]="[route.name]">{{route.name}}</a></li>
14+
<li *ngFor="let route of routes"><a [routerLink]="[route.path]">{{route.name}}</a></li>
1515
</ul>
1616
</div>
1717
</div>

app/todolist/todolist.component.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Component,
3-
ChangeDetectorRef,
4-
ChangeDetectionStrategy
5-
} from '@angular/core';
1+
import {Component} from '@angular/core';
62
import {CORE_DIRECTIVES} from '@angular/common';
73
import {Todo} from './todo.model';
84
import {CompletedFilterPipe} from './completed-filter.pipe';
@@ -11,15 +7,14 @@ import {CompletedFilterPipe} from './completed-filter.pipe';
117
selector: 'as-todolist',
128
templateUrl: 'app/todolist/todolist.html',
139
directives: [CORE_DIRECTIVES],
14-
pipes: [CompletedFilterPipe],
15-
changeDetection: ChangeDetectionStrategy.OnPush
10+
pipes: [CompletedFilterPipe]
1611
})
1712
export class TodolistComponent {
1813
public todo: Todo;
1914
private list: Todo[];
2015
private showCompleted: Boolean;
2116

22-
constructor(private _ref: ChangeDetectorRef) {
17+
constructor() {
2318
this.showCompleted = true;
2419
this.todo = new Todo('Add me to list!', false);
2520
this.list = [
@@ -31,14 +26,10 @@ export class TodolistComponent {
3126
addTodo() {
3227
this.list = this.list.concat(Todo.clone(this.todo));
3328
this.todo.clear();
34-
this._ref.markForCheck();
3529
}
3630

37-
delTodo(index: number) {
38-
this.list = [].concat(
39-
this.list.slice(0, index),
40-
this.list.slice(index + 1, this.list.length)
41-
);
42-
this._ref.markForCheck();
31+
delTodo(todoIndex: number) {
32+
this.list = this.list.filter(
33+
(todo, index) => index !== todoIndex);
4334
}
4435
}

0 commit comments

Comments
 (0)