Skip to content

Commit 70a6e17

Browse files
authoredJul 13, 2017
Fix LiveSync calls cosecutive times (#2973)
When CLI is used as a library, the LiveSync method can be called consecutive times for the same projects, but with different device identifiers. For example we may want to start LiveSync on devices with identifiers [ A, B, C ] and later we would like to add devices with identifiers [ D, E ]. In the second call, CLI should detect that LiveSync is already running and execute initial sync only for newly added devices. However the current check for unique device identifiers is not correct and it always returns empty array as we first add the new devices to the old ones and then compare the new array with the already modified old array of devices. Check the difference before adding new device identifiers to the old ones.
1 parent 00776b0 commit 70a6e17

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

‎lib/services/livesync/livesync-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
120120
liveSyncData: ILiveSyncInfo, projectData: IProjectData): Promise<void> {
121121
// In case liveSync is called for a second time for the same projectDir.
122122
const isAlreadyLiveSyncing = this.liveSyncProcessesInfo[projectData.projectDir] && !this.liveSyncProcessesInfo[projectData.projectDir].isStopped;
123-
this.setLiveSyncProcessInfo(liveSyncData.projectDir, deviceDescriptors);
124123

124+
// Prevent cases where liveSync is called consecutive times with the same device, for example [ A, B, C ] and then [ A, B, D ] - we want to execute initialSync only for D.
125125
const deviceDescriptorsForInitialSync = isAlreadyLiveSyncing ? _.differenceBy(deviceDescriptors, this.liveSyncProcessesInfo[projectData.projectDir].deviceDescriptors, deviceDescriptorPrimaryKey) : deviceDescriptors;
126+
this.setLiveSyncProcessInfo(liveSyncData.projectDir, deviceDescriptors);
126127

127128
await this.initialSync(projectData, deviceDescriptorsForInitialSync, liveSyncData);
128129

@@ -140,7 +141,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
140141
this.liveSyncProcessesInfo[projectDir].isStopped = false;
141142

142143
const currentDeviceDescriptors = this.liveSyncProcessesInfo[projectDir].deviceDescriptors || [];
143-
// Prevent cases where liveSync is called consecutive times with the same device, for example [ A, B, C ] and then [ A, B, D ] - we want to execute initialSync only for D.
144144
this.liveSyncProcessesInfo[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), deviceDescriptorPrimaryKey);
145145
}
146146

0 commit comments

Comments
 (0)
Please sign in to comment.