1
- import { Component , VERSION } from '@angular/core' ;
2
- // import { AfterViewChecked} from '@angular/core';
3
- import { ɵmarkDirty } from '@angular/core' ;
4
- // import { ɵdetectChanges } from '@angular/core';
1
+ import { Component , VERSION , ɵmarkDirty } from '@angular/core' ;
2
+ import { getData } from "@data" ;
3
+
5
4
6
5
interface Data {
7
6
id : number ;
@@ -19,22 +18,33 @@ interface Data {
19
18
</div>
20
19
<div class="col-md-6">
21
20
<div class="col-sm-6 smallpad">
22
- <button type="button" class="btn btn-primary btn-block" id="run" (click)="run()" ref="text">Create 1,000 rows</button>
21
+ <button type="button" class="btn btn-primary btn-block" id="run" (click)="run()" ref="text">
22
+ Create 1,000 rows
23
+ </button>
23
24
</div>
24
25
<div class="col-sm-6 smallpad">
25
- <button type="button" class="btn btn-primary btn-block" id="runlots" (click)="runLots()">Create 10,000 rows</button>
26
+ <button type="button" class="btn btn-primary btn-block" id="runlots" (click)="runLots()">
27
+ Create 10,000 rows
28
+ </button>
26
29
</div>
27
30
<div class="col-sm-6 smallpad">
28
- <button type="button" class="btn btn-primary btn-block" id="add" (click)="add()" ref="text">Append 1,000 rows</button>
31
+ <button type="button" class="btn btn-primary btn-block" id="add" (click)="add()" ref="text">
32
+ Append 1,000 rows
33
+ </button>
29
34
</div>
30
35
<div class="col-sm-6 smallpad">
31
- <button type="button" class="btn btn-primary btn-block" id="update" (click)="update()">Update every 10th row</button>
36
+ <button type="button" class="btn btn-primary btn-block" id="update" (click)="update()">
37
+ Update every 10th row
38
+ </button>
32
39
</div>
33
40
<div class="col-sm-6 smallpad">
34
- <button type="button" class="btn btn-primary btn-block" id="clear" (click)="clear()">Clear</button>
41
+ <button type="button" class="btn btn-primary btn-block" id="clear" (click)="clear()">Clear
42
+ </button>
35
43
</div>
36
44
<div class="col-sm-6 smallpad">
37
- <button type="button" class="btn btn-primary btn-block" id="swaprows" (click)="swapRows()">Swap Rows</button>
45
+ <button type="button" class="btn btn-primary btn-block" id="swaprows" (click)="swapRows()">
46
+ Swap Rows
47
+ </button>
38
48
</div>
39
49
</div>
40
50
</div>
@@ -46,7 +56,8 @@ interface Data {
46
56
<td class="col-md-4">
47
57
<a href="#" (click)="select(item, $event)">{{item.label}}</a>
48
58
</td>
49
- <td class="col-md-1"><a href="#" (click)="delete(item, $event)"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
59
+ <td class="col-md-1"><a href="#" (click)="delete(item, $event)"><span
60
+ class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
50
61
<td class="col-md-6"></td>
51
62
</tr>
52
63
</tbody>
@@ -57,7 +68,12 @@ interface Data {
57
68
styles : [ ]
58
69
} )
59
70
export class AppComponent {
60
- data : Array < Data > = [ ] ;
71
+ model = getData ( ) ;
72
+
73
+ get data ( ) : Array < Data > {
74
+ return this . model . data ( ) ;
75
+ }
76
+
61
77
selected : number = undefined ;
62
78
id : number = 1 ;
63
79
backup : Array < Data > = undefined ;
@@ -67,25 +83,7 @@ export class AppComponent {
67
83
this . version = VERSION . full ;
68
84
}
69
85
70
- buildData ( count : number = 1000 ) : Array < Data > {
71
- var adjectives = [ "pretty" , "large" , "big" , "small" , "tall" , "short" , "long" , "handsome" , "plain" , "quaint" , "clean" , "elegant" , "easy" , "angry" , "crazy" , "helpful" , "mushy" , "odd" , "unsightly" , "adorable" , "important" , "inexpensive" , "cheap" , "expensive" , "fancy" ] ;
72
- var colours = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ;
73
- var nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ;
74
- var data : Array < Data > = [ ] ;
75
- for ( var i = 0 ; i < count ; i ++ ) {
76
- data . push ( { id : this . id , label : adjectives [ this . _random ( adjectives . length ) ] + " " + colours [ this . _random ( colours . length ) ] + " " + nouns [ this . _random ( nouns . length ) ] } ) ;
77
- this . id ++ ;
78
- }
79
- return data ;
80
- }
81
-
82
- _random ( max : number ) {
83
- return Math . round ( Math . random ( ) * 1000 ) % max ;
84
- }
85
-
86
- itemById ( index : number , item : Data ) {
87
- return item . id ;
88
- }
86
+ itemById = this . model . itemById ;
89
87
90
88
select ( item : Data , event : Event ) {
91
89
event . preventDefault ( ) ;
@@ -94,51 +92,40 @@ export class AppComponent {
94
92
}
95
93
96
94
delete ( item : Data , event : Event ) {
97
- event . preventDefault ( ) ;
98
- for ( let i = 0 , l = this . data . length ; i < l ; i ++ ) {
99
- if ( this . data [ i ] . id === item . id ) {
100
- this . data . splice ( i , 1 ) ;
101
- break ;
102
- }
103
- }
95
+ this . model . deleteItem ( item , event ) ;
104
96
ɵmarkDirty ( this ) ;
105
97
}
106
98
107
99
run ( ) {
108
- this . data = this . buildData ( ) ;
100
+ this . model . run ( ) ;
101
+ console . log ( this . model . data . length , this . data . length ) ;
109
102
ɵmarkDirty ( this ) ;
110
103
}
111
104
112
105
add ( ) {
113
- this . data = this . data . concat ( this . buildData ( 1000 ) ) ;
106
+ this . model . add ( ) ;
114
107
ɵmarkDirty ( this ) ;
115
108
}
116
109
117
110
update ( ) {
118
- for ( let i = 0 ; i < this . data . length ; i += 10 ) {
119
- this . data [ i ] . label += ' !!!' ;
120
- }
111
+ this . model . update ( ) ;
121
112
ɵmarkDirty ( this ) ;
122
113
}
123
114
124
115
runLots ( ) {
125
- this . data = this . buildData ( 10000 ) ;
116
+ this . model . runLots ( ) ;
126
117
this . selected = undefined ;
127
118
ɵmarkDirty ( this ) ;
128
119
}
129
120
130
121
clear ( ) {
131
- this . data = [ ] ;
122
+ this . model . clear ( ) ;
132
123
this . selected = undefined ;
133
124
ɵmarkDirty ( this ) ;
134
125
}
135
126
136
127
swapRows ( ) {
137
- if ( this . data . length > 998 ) {
138
- var a = this . data [ 1 ] ;
139
- this . data [ 1 ] = this . data [ 998 ] ;
140
- this . data [ 998 ] = a ;
141
- }
128
+ this . model . swapRows ( ) ;
142
129
ɵmarkDirty ( this ) ;
143
130
}
144
131
0 commit comments