Skip to content

Commit 6fa2a41

Browse files
vakrilovsis0k0
vakrilov
authored andcommitted
chore: Update ng-sample to ng6 + rxjs6
1 parent 83c1a2e commit 6fa2a41

12 files changed

+67
-63
lines changed

Diff for: ng-sample/app/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class MyErrorHandler implements ErrorHandler {
139139
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(Benchmark));
140140
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTest));
141141
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTemplateSelectorTest));
142-
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
142+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
143143
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ImageTest));
144144
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));
145145
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(HttpTest));
@@ -187,4 +187,4 @@ onAfterLivesync.subscribe(({ moduleRef, error }) => {
187187

188188
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(LivesyncApp));
189189
// console.log("APP RESTART!!!! !!!");
190-
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));
190+
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));

Diff for: ng-sample/app/examples/http-client/http-client-test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import {
33
HttpClient, HTTP_INTERCEPTORS, HttpEventType, HttpErrorResponse,
44
HttpEvent, HttpInterceptor, HttpHandler, HttpRequest
55
} from "@angular/common/http";
6-
import { Observable } from "rxjs/Observable";
7-
import "rxjs/add/operator/do";
6+
import { Observable } from "rxjs";
7+
import { tap } from "rxjs/operators";
88

99
@Injectable()
1010
export class CustomInterceptor implements HttpInterceptor {
1111
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
1212
console.log(`[CustomInterceptor] intercept url: ${req.url}`);
1313

14-
return next.handle(req)
15-
.do(event => {
14+
return next.handle(req).pipe(
15+
tap(event => {
1616
console.log(`[CustomInterceptor] handled type: ${HttpEventType[event.type]} url: ${req.url}`);
17-
});
17+
})
18+
);
1819
}
1920
}
2021

Diff for: ng-sample/app/examples/http/http-test.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Component} from "@angular/core";
2-
import {Http} from "@angular/http";
3-
import "rxjs/add/operator/map";
1+
import { Component } from "@angular/core";
2+
import { Http } from "@angular/http";
3+
import { map } from "rxjs/operators";
44

55
/* IMPORTANT
66
In order to test out the full image example,
@@ -11,20 +11,20 @@ https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativ
1111
*/
1212

1313
@Component({
14-
selector: "http-test",
15-
template: `
14+
selector: "http-test",
15+
template: `
1616
<StackLayout horizontalAlignment="center">
1717
<Button text="Load Local File with Http" (tap)='loadLocal()' cssClass="btn-primary"></Button>
1818
<Button text="Load Remote File with Http" (tap)='loadRemote()' cssClass="btn-primary"></Button>
1919
<Label [text]="title" textWrap="true"></Label>
2020
<Label [text]="description" textWrap="true"></Label>
2121
</StackLayout>
2222
`,
23-
styles: [
24-
`Button {
23+
styles: [
24+
`Button {
2525
margin-bottom:20;
2626
}`
27-
],
27+
],
2828
})
2929
export class HttpTest {
3030
public title: string;
@@ -35,18 +35,22 @@ export class HttpTest {
3535
}
3636

3737
public loadLocal() {
38-
this.http.get("~/examples/http/data.json").map(res => res.json()).subscribe((response: any) => {
38+
this.http.get("~/examples/http/data.json").pipe(
39+
map(res => res.json())
40+
).subscribe((response: any) => {
3941
let user = response.results[0];
4042
this.title = user.title;
4143
this.description = user.description;
4244
});
4345
}
4446

4547
public loadRemote() {
46-
this.http.get(`https://randomuser.me/api/?results=1&nat=us`).map(res => res.json()).subscribe((response: any) => {
47-
let user = response.results[0];
48-
this.title = user.name.first;
49-
this.description = user.email;
50-
});
48+
this.http.get(`https://randomuser.me/api/?results=1&nat=us`)
49+
.pipe(map(res => res.json()))
50+
.subscribe((response: any) => {
51+
let user = response.results[0];
52+
this.title = user.name.first;
53+
this.description = user.email;
54+
});
5155
}
5256
}

Diff for: ng-sample/app/examples/list/data.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from "@angular/core";
2-
import { BehaviorSubject } from "rxjs/BehaviorSubject";
2+
import { BehaviorSubject } from "rxjs";
33

44
export class DataItem {
55
constructor(public id: number, public name: string) { }

Diff for: ng-sample/app/examples/list/list-test-async.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Component, ChangeDetectionStrategy } from "@angular/core";
22
import { DataItem, DataService } from "./data.service";
3-
import { Observable } from "rxjs/Observable";
4-
import { BehaviorSubject } from "rxjs/BehaviorSubject";
5-
import "rxjs/add/operator/combineLatest";
3+
import { Observable, BehaviorSubject } from "rxjs";
4+
import { combineLatest } from "rxjs/operators";
65

76
@Component({
87
selector: "list-test-async",
@@ -95,9 +94,10 @@ export class ListTestFilterAsync {
9594
private filter$ = new BehaviorSubject(false);
9695

9796
constructor(private service: DataService) {
98-
this.filteredItems$ = this.service.items$.combineLatest(this.filter$, (data, filter) => {
99-
return filter ? data.filter(v => v.id % 2 === 0) : data;
100-
});
97+
this.filteredItems$ = this.service.items$.pipe(
98+
combineLatest(this.filter$, (data, filter) => {
99+
return filter ? data.filter(v => v.id % 2 === 0) : data;
100+
}));
101101
}
102102

103103
public onItemTap(args) {

Diff for: ng-sample/app/examples/modal/modal-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ViewContainerRef } from "@angular/core";
2-
import * as dialogs from "ui/dialogs";
2+
import * as dialogs from "tns-core-modules/ui/dialogs";
33
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
44
import { ModalContent } from "./modal-content";
55

Diff for: ng-sample/app/examples/router/clear-history-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy, Injectable } from "@angular/core";
22
import { Router } from "@angular/router";
33
import { RouterExtensions } from "nativescript-angular/router";
44
import { NSLocationStrategy } from "nativescript-angular/router/ns-location-strategy";
5-
import { BehaviorSubject } from "rxjs/BehaviorSubject";
5+
import { BehaviorSubject } from "rxjs";
66

77
@Injectable()
88
class LocationLogService {

Diff for: ng-sample/app/examples/router/login-test.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { Component, Injectable } from "@angular/core";
22
import { CanActivate, Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/router";
33
import { RouterExtensions, PageRoute } from "nativescript-angular/router";
44
import * as appSettings from "application-settings";
5-
import { Observable } from "rxjs/Observable";
6-
import "rxjs/add/operator/map";
7-
import "rxjs/add/operator/switchMap";
5+
import { Observable } from "rxjs";
6+
import { map, switchMap } from "rxjs/operators";
87

98
const USER_KEY = "user";
109

@@ -88,16 +87,16 @@ export interface ResolvedData {
8887
class MainComponent {
8988
private data$: Observable<ResolvedData>;
9089
constructor(private nav: RouterExtensions, private loginService: LoginService, private pageRoute: PageRoute) {
91-
this.data$ = this.pageRoute.activatedRoute
92-
.switchMap(activatedRoute => activatedRoute.data)
93-
.map(data => data[0]);
90+
this.data$ = this.pageRoute.activatedRoute.pipe(
91+
switchMap(activatedRoute => activatedRoute.data),
92+
map(data => data[0])
93+
);
9494
}
9595

9696
logout() {
9797
this.loginService.logout().then((result) => {
98-
if (result) {
98+
if (result)
9999
this.nav.navigate(["/login"], { clearHistory: true });
100-
}
101100
});
102101
}
103102

@@ -157,7 +156,7 @@ class AuthGuard implements CanActivate {
157156
class ResolveGuard implements Resolve<ResolvedData> {
158157
static counter = 0;
159158
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
160-
Observable<ResolvedData> | Promise<ResolvedData> | ResolvedData {
159+
Observable<ResolvedData> | Promise<ResolvedData> | ResolvedData {
161160
const result: ResolvedData = { id: ResolveGuard.counter++ };
162161
console.log(`ResolveGuard: Fetching new data. Result: ${JSON.stringify(result)} `);
163162
return result;

Diff for: ng-sample/app/examples/router/page-router-outlet-nested-test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { ActivatedRoute, Router, Route } from "@angular/router";
33
import { Location } from "@angular/common";
44
import { Page } from "ui/page";
5-
import { Observable } from "rxjs/Observable";
6-
import "rxjs/add/operator/map";
5+
import { Observable } from "rxjs";
6+
import { map } from "rxjs/operators";
77

88
@Component({
99
selector: "first",
@@ -68,7 +68,7 @@ class DetailComponent {
6868
public id$: Observable<string>;
6969
constructor(private router: Router, private route: ActivatedRoute) {
7070
console.log("DetailComponent.constructor()");
71-
this.id$ = route.params.map(r => r["id"]);
71+
this.id$ = route.params.pipe(map(r => r["id"]));
7272
}
7373

7474
ngOnInit() {
@@ -106,8 +106,8 @@ class SecondComponent implements OnInit, OnDestroy {
106106
public nextDepth$: Observable<number>;
107107
constructor(private location: Location, route: ActivatedRoute, page: Page) {
108108
console.log("SecondComponent.constructor() page: " + page);
109-
this.depth$ = route.params.map(r => r["depth"]);
110-
this.nextDepth$ = route.params.map(r => +r["depth"] + 1);
109+
this.depth$ = route.params.pipe(map(r => r["depth"]));
110+
this.nextDepth$ = route.params.pipe(map(r => +r["depth"] + 1));
111111
}
112112

113113
ngOnInit() {

Diff for: ng-sample/app/examples/router/page-router-outlet-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { ActivatedRoute, Router } from "@angular/router";
33
import { Location } from "@angular/common";
44
import { Page } from "ui/page";
5-
import { Observable } from "rxjs/Observable";
6-
import "rxjs/add/operator/map";
5+
import { Observable } from "rxjs";
6+
import { map } from "rxjs/operators";
77

88

99
@Component({
@@ -51,7 +51,7 @@ class SecondComponent implements OnInit, OnDestroy {
5151
public id: Observable<string>;
5252
constructor(private location: Location, route: ActivatedRoute, page: Page) {
5353
console.log("SecondComponent.constructor() page: " + page);
54-
this.id = route.params.map(r => r["id"]);
54+
this.id = route.params.pipe(map(r => r["id"]));
5555
}
5656

5757
ngOnInit() {
@@ -85,7 +85,7 @@ class ThirdComponent implements OnInit, OnDestroy {
8585
public id: Observable<string>;
8686
constructor(private location: Location, route: ActivatedRoute, page: Page) {
8787
console.log("ThirdComponent.constructor() page: " + page);
88-
this.id = route.params.map(r => r["id"]);
88+
this.id = route.params.pipe(map(r => r["id"]));
8989
}
9090

9191
ngOnInit() {

Diff for: ng-sample/app/examples/router/router-outlet-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { ActivatedRoute } from "@angular/router";
3-
import "rxjs/add/operator/map";
3+
import { map } from "rxjs/operators";
44

55
@Component({
66
selector: "first",
@@ -31,7 +31,7 @@ class FirstComponent implements OnInit, OnDestroy {
3131
class SecondComponent implements OnInit, OnDestroy {
3232
id;
3333
constructor(route: ActivatedRoute) {
34-
this.id = route.params.map(r => r["id"]);
34+
this.id = route.params.pipe(map(r => r["id"]));
3535
}
3636

3737
ngOnInit() {

Diff for: ng-sample/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"nativescript": {
33
"id": "org.nativescript.ngsample",
44
"tns-android": {
5-
"version": "next"
5+
"version": "4.1.0-2018.4.16.8"
66
},
77
"tns-ios": {
8-
"version": "next"
8+
"version": "4.0.2-2018-04-13-01"
99
}
1010
},
1111
"name": "tns-template-hello-world",
@@ -32,17 +32,17 @@
3232
},
3333
"homepage": "https://github.com/NativeScript/template-hello-world",
3434
"dependencies": {
35-
"@angular/animations": "~5.2.0",
36-
"@angular/common": "~5.2.0",
37-
"@angular/compiler": "~5.2.0",
38-
"@angular/core": "~5.2.0",
39-
"@angular/forms": "~5.2.0",
40-
"@angular/http": "~5.2.0",
41-
"@angular/platform-browser": "~5.2.0",
42-
"@angular/platform-browser-dynamic": "~5.2.0",
43-
"@angular/router": "~5.2.0",
35+
"@angular/animations": "~6.0.0-rc.3",
36+
"@angular/common": "~6.0.0-rc.3",
37+
"@angular/compiler": "~6.0.0-rc.3",
38+
"@angular/core": "~6.0.0-rc.3",
39+
"@angular/forms": "~6.0.0-rc.3",
40+
"@angular/http": "~6.0.0-rc.3",
41+
"@angular/platform-browser": "~6.0.0-rc.3",
42+
"@angular/platform-browser-dynamic": "~6.0.0-rc.3",
43+
"@angular/router": "~6.0.0-rc.3",
4444
"nativescript-angular": "file:../nativescript-angular",
45-
"rxjs": "^5.5.0",
45+
"rxjs": "~6.0.0-rc.1",
4646
"tns-core-modules": "next",
4747
"tns-platform-declarations": "^3.4.0",
4848
"zone.js": "^0.8.4"
@@ -56,7 +56,7 @@
5656
"nativescript-dev-typescript": "next",
5757
"shelljs": "^0.7.0",
5858
"tslint": "^4.5.1",
59-
"typescript": "~2.6.2"
59+
"typescript": "~2.7.2"
6060
},
6161
"scripts": {
6262
"tslint": "tslint --project tsconfig.json --config tslint.json",

0 commit comments

Comments
 (0)