@@ -4,6 +4,8 @@ import { cache, performanceLog } from "../common/decorators";
44import { EventEmitter } from "events" ;
55
66export class RunController extends EventEmitter implements IRunController {
7+ private prepareReadyEventHandler : any = null ;
8+
79 constructor (
810 protected $analyticsService : IAnalyticsService ,
911 private $buildController : IBuildController ,
@@ -45,9 +47,10 @@ export class RunController extends EventEmitter implements IRunController {
4547 this . $hmrStatusService . attachToHmrStatusEvent ( ) ;
4648 }
4749
48- this . $prepareController . on ( PREPARE_READY_EVENT_NAME , async data => {
49- await this . syncChangedDataOnDevices ( data , projectData , liveSyncInfo , deviceDescriptors ) ;
50- } ) ;
50+ if ( ! this . prepareReadyEventHandler ) {
51+ this . prepareReadyEventHandler = async ( data : any ) => await this . syncChangedDataOnDevices ( data , projectData , liveSyncInfo ) ;
52+ this . $prepareController . on ( PREPARE_READY_EVENT_NAME , this . prepareReadyEventHandler . bind ( this ) ) ;
53+ }
5154
5255 await this . syncInitialDataOnDevices ( projectData , liveSyncInfo , deviceDescriptorsForInitialSync ) ;
5356
@@ -58,6 +61,11 @@ export class RunController extends EventEmitter implements IRunController {
5861 const { projectDir, deviceIdentifiers, stopOptions } = data ;
5962 const liveSyncProcessInfo = this . $liveSyncProcessDataService . getPersistedData ( projectDir ) ;
6063 if ( liveSyncProcessInfo && ! liveSyncProcessInfo . isStopped ) {
64+ if ( this . prepareReadyEventHandler ) {
65+ this . removeListener ( PREPARE_READY_EVENT_NAME , this . prepareReadyEventHandler ) ;
66+ this . prepareReadyEventHandler = null ;
67+ }
68+
6169 // In case we are coming from error during livesync, the current action is the one that erred (but we are still executing it),
6270 // so we cannot await it as this will cause infinite loop.
6371 const shouldAwaitPendingOperation = ! stopOptions || stopOptions . shouldAwaitAllActions ;
@@ -313,10 +321,11 @@ export class RunController extends EventEmitter implements IRunController {
313321 await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ) ;
314322 }
315323
316- private async syncChangedDataOnDevices ( data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceDescriptor [ ] ) : Promise < void > {
324+ private async syncChangedDataOnDevices ( data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo ) : Promise < void > {
317325 const rebuiltInformation : IDictionary < { packageFilePath : string , platform : string , isEmulator : boolean } > = { } ;
318326
319327 const deviceAction = async ( device : Mobile . IDevice ) => {
328+ const deviceDescriptors = this . $liveSyncProcessDataService . getDeviceDescriptors ( projectData . projectDir ) ;
320329 const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
321330 const platformData = this . $platformsDataService . getPlatformData ( data . platform , projectData ) ;
322331 const prepareData = this . $prepareDataService . getPrepareData ( liveSyncInfo . projectDir , device . deviceInfo . platform ,
0 commit comments