@@ -5,15 +5,15 @@ import { Cost } from '../../common/protocol';
55
66@Injectable ( )
77export 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 }
0 commit comments