Skip to content

Commit 3da7fb2

Browse files
author
Ihor Khomiak
committed
refactor code
1 parent 6da111c commit 3da7fb2

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

app/common/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export class Cost {
88
quantity: number;
99
type: string;
1010
changesDate: string;
11-
isFavorite:boolean;
11+
isFavorite: boolean;
1212
}

app/components/calendar/calendar.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export class CalendarComponent {
1515
public filteredCosts: Cost[] = new Array<Cost>();
1616
public allCosts: Cost[] = new Array<Cost>();
1717

18-
constructor(private costService:CostService){}
18+
constructor(private costService: CostService){}
1919

2020
ngOnInit() {
21-
this.costService.costsListObservable.subscribe((costs) => {
21+
this.costService.costs.subscribe((costs) => {
2222
this.allCosts = costs;
2323
});
2424
}

app/components/calendar/date-range-cost-list/calendar-date-range-cost-list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Cost } from '../../../common/protocol';
1111
export class CalendarDateRangeCostListComponent {
1212

1313
@Output() stateChanged = new EventEmitter();
14-
@Input() filteredCosts:Array<Cost>;
14+
@Input() filteredCosts: Array<Cost>;
1515

1616
onTap(){
1717
this.stateChanged.next("");

app/components/calendar/date-range/calendar-date-range.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { DatePicker } from 'ui/date-picker';
99
styleUrls: ["./calendar-date-range.component.css"]
1010
})
1111
export class CalendarDateRangeComponent {
12-
private _startDate:string;
13-
private _endDate:string;
12+
private _startDate: string;
13+
private _endDate: string;
1414

1515
@Output() stateChanged = new EventEmitter();
1616
@Output() sendDateChange = new EventEmitter();

app/components/cost/cost.service.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { Cost } from '../../common/protocol';
55

66
@Injectable()
77
export class CostService {
8-
private costsListSource: Rx.BehaviorSubject<Cost[]>;
9-
private backing_costsListObservable: Rx.Observable<Cost[]>;
8+
private _costsSource: Rx.BehaviorSubject<Cost[]>;
9+
private _costs: Rx.Observable<Cost[]>;
1010

1111
constructor() {
12-
this.costsListSource = new Rx.BehaviorSubject<Cost[]>(this.costs);
13-
this.backing_costsListObservable = this.costsListSource.asObservable();
12+
this._costsSource = new Rx.BehaviorSubject<Cost[]>(this.costsCollection);
13+
this._costs = this._costsSource.asObservable();
1414
}
1515

16-
private costs = new Array<Cost>(
16+
private costsCollection = new Array<Cost>(
1717
{ id: 0, quantity: 310, type: "Products", changesDate: "Jul 01 2017", isFavorite: false },
1818
{ id: 1, quantity: 25, type: "Products", changesDate: "Aug 25 2017", isFavorite: false },
1919
{ id: 2, quantity: 127, type: "ForHome", changesDate: "Aug 30 2017", isFavorite: false },
@@ -29,25 +29,25 @@ export class CostService {
2929
{ id: 12, quantity: 78, type: "Products", changesDate: "April 04 2017", isFavorite: false }
3030
);
3131

32-
public get costsListObservable(): Rx.Observable<Cost[]> {
33-
return this.backing_costsListObservable;
32+
public get costs(): Rx.Observable<Cost[]> {
33+
return this._costs;
3434
}
3535

3636
getCost(id: number): Cost {
37-
return this.costsListSource.getValue().filter(cost => cost.id === id)[0];
37+
return this._costsSource.getValue().filter(cost => cost.id === id)[0];
3838
}
3939

4040
addCost(newCost: Cost) {
41-
let activeCosts = this.costsListSource.getValue();
41+
let activeCosts = this._costsSource.getValue();
4242
activeCosts.unshift(newCost);
43-
this.costsListSource.next(activeCosts);
43+
this._costsSource.next(activeCosts);
4444
}
4545

4646
deleteCost(costForDelete: Cost) {
47-
let activeCosts = this.costsListSource.getValue();
47+
let activeCosts = this._costsSource.getValue();
4848
var index = activeCosts.indexOf(costForDelete);
4949
activeCosts.splice(index, 1);
50-
this.costsListSource.next(activeCosts);
50+
this._costsSource.next(activeCosts);
5151

5252
alert(costForDelete.quantity + " removed!");
5353
}

app/components/cost/costs.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
(tap)="add()"
2525
class="list-header-button"></Label>
2626
</GridLayout>
27-
<list [items]="costService.costsListObservable | async"></list>
27+
<list [items]="costService.costs | async"></list>
2828
</StackLayout>

app/components/cost/costs.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CostsComponent implements OnInit {
1919
constructor(private router: RouterExtensions, private costService: CostService) { }
2020

2121
ngOnInit(): void {
22-
// this.costService.costsListObservable.subscribe((costs) => {
22+
// this.costService.costs.subscribe((costs) => {
2323
// if(costs) {
2424
// this.costs = costs;
2525
// }
@@ -35,7 +35,7 @@ export class CostsComponent implements OnInit {
3535
return;
3636
}
3737

38-
let cost:Cost = new Cost();
38+
let cost: Cost = new Cost();
3939
cost.id = Math.random();
4040
cost.quantity = Number(textField.text);
4141
cost.type = "TestType";

app/components/cost/edit/cost-edit.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class CostEditComponent implements OnInit {
4747
this.routerExtensions.back();
4848
}
4949

50-
private formatDateString(dateString:string):string {
50+
private formatDateString(dateString: string): string {
5151
return (new Date(dateString)).toDateString().slice(4);
5252
}
5353
}

app/components/tabs/tabs.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ import { SelectedIndexChangedEventData, TabView } from 'tns-core-modules/ui/tab-
88
templateUrl: "./tabs.component.html",
99
styleUrls: ["./tabs.component.css"]
1010
})
11-
export class TabsComponent implements OnInit {
11+
export class TabsComponent {
1212
private _title: string;
1313

14-
constructor() {}
15-
ngOnInit(): void {}
16-
1714
get title(): string {
1815
return this._title;
1916
}

0 commit comments

Comments
 (0)