@@ -12,6 +12,41 @@ interface IProjectFileInfo {
12
12
shouldIncludeFile : boolean ;
13
13
}
14
14
15
+ class SyncBatch {
16
+ private timer : NodeJS . Timer = null ;
17
+ private syncQueue : string [ ] = [ ] ;
18
+
19
+ constructor (
20
+ private $logger : ILogger ,
21
+ private $dispatcher : IFutureDispatcher ,
22
+ private done : ( filesToSync : Array < string > ) => void ) {
23
+ }
24
+
25
+ public addFile ( filePath : string ) : void {
26
+ if ( this . timer ) {
27
+ clearTimeout ( this . timer ) ;
28
+ }
29
+
30
+ this . syncQueue . push ( filePath ) ;
31
+
32
+ this . timer = setTimeout ( ( ) => {
33
+ let filesToSync = this . syncQueue ;
34
+ if ( filesToSync . length > 0 ) {
35
+ this . syncQueue = [ ] ;
36
+ this . $logger . trace ( "Syncing %s" , filesToSync . join ( ", " ) ) ;
37
+ this . $dispatcher . dispatch ( ( ) => {
38
+ return ( ( ) => this . done ( filesToSync ) ) . future < void > ( ) ( ) ;
39
+ } ) ;
40
+ }
41
+ this . timer = null ;
42
+ } , 500 ) ;
43
+ }
44
+
45
+ public get syncPending ( ) {
46
+ return this . syncQueue . length > 0 ;
47
+ }
48
+ }
49
+
15
50
export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
16
51
private _initialized = false ;
17
52
@@ -68,17 +103,31 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
68
103
69
104
if ( this . $options . watch ) {
70
105
let that = this ;
71
-
72
106
gaze ( "**/*" , { cwd : watchGlob } , function ( err : any , watcher : any ) {
73
107
this . on ( 'all' , ( event : string , filePath : string ) => {
74
108
if ( event === "added" || event === "changed" ) {
75
109
if ( ! _ . contains ( excludedProjectDirsAndFiles , filePath ) ) {
76
110
if ( synciOSSimulator ) {
77
- that . $dispatcher . dispatch ( ( ) => that . $iOSEmulatorServices . syncFiles ( appIdentifier , projectFilesPath , [ filePath ] , notRunningiOSSimulatorAction , iOSSimulatorRelativeToProjectBasePathAction ) ) ;
111
+ that . batchSimulatorLiveSync (
112
+ appIdentifier ,
113
+ projectFilesPath ,
114
+ filePath ,
115
+ notRunningiOSSimulatorAction ,
116
+ iOSSimulatorRelativeToProjectBasePathAction
117
+ ) ;
78
118
}
79
119
80
120
if ( ! that . $options . emulator || platform . toLowerCase ( ) === "android" ) {
81
- that . batchLiveSync ( platform , filePath , appIdentifier , localProjectRootPath || projectFilesPath , platformSpecificLiveSyncServices , notInstalledAppOnDeviceAction , beforeLiveSyncAction , beforeBatchLiveSyncAction ) ;
121
+ that . batchLiveSync (
122
+ platform ,
123
+ filePath ,
124
+ appIdentifier ,
125
+ localProjectRootPath || projectFilesPath ,
126
+ platformSpecificLiveSyncServices ,
127
+ notInstalledAppOnDeviceAction ,
128
+ beforeLiveSyncAction ,
129
+ beforeBatchLiveSyncAction
130
+ ) ;
82
131
}
83
132
}
84
133
}
@@ -134,38 +183,56 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
134
183
} ) . future < void > ( ) ( ) ;
135
184
}
136
185
137
- private timer : NodeJS . Timer = null ;
138
- private syncQueue : string [ ] = [ ] ;
186
+ private batch : SyncBatch = null ;
187
+
139
188
private batchLiveSync ( platform : string , filePath : string , appIdentifier : string , projectFilesPath : string ,
140
189
platformSpecificLiveSyncServices : IDictionary < any > ,
141
190
notInstalledAppOnDeviceAction : ( _device : Mobile . IDevice ) => IFuture < void > ,
142
191
beforeLiveSyncAction ?: ( _device1 : Mobile . IDevice , _deviceAppData : Mobile . IDeviceAppData ) => IFuture < void > ,
143
192
beforeBatchLiveSyncAction ?: ( _filePath : string ) => IFuture < string > ) : void {
144
-
145
- if ( ! this . timer ) {
146
- this . timer = setInterval ( ( ) => {
147
- let filesToSync = this . syncQueue ;
148
- if ( filesToSync . length > 0 ) {
149
- this . syncQueue = [ ] ;
150
- this . $logger . trace ( "Syncing %s" , filesToSync . join ( ", " ) ) ;
151
- this . $dispatcher . dispatch ( ( ) => {
152
- return ( ( ) => {
153
- this . preparePlatformForSync ( platform ) ;
154
- this . syncCore ( platform , filesToSync , appIdentifier , projectFilesPath , platformSpecificLiveSyncServices , notInstalledAppOnDeviceAction , beforeLiveSyncAction ) . wait ( ) ;
155
- } ) . future < void > ( ) ( ) ;
156
- } ) ;
157
- }
158
- } , 500 ) ;
159
- }
193
+ if ( ! this . batch || ! this . batch . syncPending ) {
194
+ this . batch = new SyncBatch (
195
+ this . $logger , this . $dispatcher , ( filesToSync ) => {
196
+ this . preparePlatformForSync ( platform ) ;
197
+ this . syncCore (
198
+ platform ,
199
+ filesToSync ,
200
+ appIdentifier ,
201
+ projectFilesPath ,
202
+ platformSpecificLiveSyncServices ,
203
+ notInstalledAppOnDeviceAction ,
204
+ beforeLiveSyncAction
205
+ ) . wait ( ) ;
206
+ }
207
+ ) ;
208
+ }
160
209
161
210
this . $dispatcher . dispatch ( ( ) => ( ( ) => {
162
- this . syncQueue . push ( beforeBatchLiveSyncAction ? beforeBatchLiveSyncAction ( filePath ) . wait ( ) : filePath ) ;
211
+ let fileToSync = beforeBatchLiveSyncAction ? beforeBatchLiveSyncAction ( filePath ) . wait ( ) : filePath ;
212
+ this . batch . addFile ( fileToSync ) ;
163
213
} ) . future < void > ( ) ( ) ) ;
164
214
}
165
215
166
- protected preparePlatformForSync ( platform : string ) {
167
- //Overridden in platform-specific services.
168
- }
216
+ private batchSimulatorLiveSync (
217
+ appIdentifier : string ,
218
+ projectFilesPath : string ,
219
+ filePath : string ,
220
+ notRunningiOSSimulatorAction : ( ) => IFuture < void > ,
221
+ iOSSimulatorRelativeToProjectBasePathAction :( projectFile : string ) => string ) : void {
222
+ if ( ! this . batch || ! this . batch . syncPending ) {
223
+ this . batch = new SyncBatch (
224
+ this . $logger , this . $dispatcher , ( filesToSync ) => {
225
+ this . $iOSEmulatorServices . syncFiles ( appIdentifier , projectFilesPath , filesToSync , notRunningiOSSimulatorAction , iOSSimulatorRelativeToProjectBasePathAction ) ;
226
+ }
227
+ ) ;
228
+ }
229
+
230
+ this . batch . addFile ( filePath ) ;
231
+ }
232
+
233
+ protected preparePlatformForSync ( platform : string ) {
234
+ //Overridden in platform-specific services.
235
+ }
169
236
170
237
private isFileExcluded ( path : string , exclusionList : string [ ] , projectDir : string ) : boolean {
171
238
return ! ! _ . find ( exclusionList , ( pattern ) => minimatch ( path , pattern , { nocase : true } ) ) ;
0 commit comments