@@ -238,19 +238,31 @@ AmplitudeClient.prototype._migrateUnsentEvents = function _migrateUnsentEvents(c
238238 if ( this . options . saveEvents ) {
239239 var unsentEventsString = values [ 0 ] ;
240240 var unsentIdentifyKey = values [ 1 ] ;
241- Promise . all ( [
242- AsyncStorage . setItem ( this . options . unsentKey + this . _storageSuffix , unsentEventsString ) ,
243- AsyncStorage . setItem ( this . options . unsentIdentifyKey + this . _storageSuffix , unsentIdentifyKey ) ,
244- ] ) . then ( ( ) => {
245- Promise . all ( [
246- AsyncStorage . removeItem ( this . options . unsentKey ) ,
247- AsyncStorage . removeItem ( this . options . unsentIdentifyKey ) ,
248- ] ) . then ( cb ) ;
249- } ) . catch ( ( err ) => {
250- this . options . onError ( err ) ;
251- } ) ;
241+
242+ var itemsToSet = [ ] ;
243+ var itemsToRemove = [ ] ;
244+
245+ if ( ! ! unsentEventsString ) {
246+ itemsToSet . push ( AsyncStorage . setItem ( this . options . unsentKey + this . _storageSuffix , JSON . stringify ( unsentEventsString ) ) ) ;
247+ itemsToRemove . push ( AsyncStorage . removeItem ( this . options . unsentKey ) ) ;
248+ }
249+
250+ if ( ! ! unsentIdentifyKey ) {
251+ itemsToSet . push ( AsyncStorage . setItem ( this . options . unsentIdentifyKey + this . _storageSuffix , JSON . stringify ( unsentIdentifyKey ) ) ) ;
252+ itemsToRemove . push ( AsyncStorage . removeItem ( this . options . unsentIdentifyKey ) ) ;
253+ }
254+
255+ if ( itemsToSet . length > 0 ) {
256+ Promise . all ( itemsToSet ) . then ( ( ) => {
257+ Promise . all ( itemsToRemove ) ;
258+ } ) . catch ( ( err ) => {
259+ this . options . onError ( err ) ;
260+ } ) ;
261+ }
252262 }
253- } ) . catch ( ( err ) => {
263+ } )
264+ . then ( cb )
265+ . catch ( ( err ) => {
254266 this . options . onError ( err ) ;
255267 } ) ;
256268} ;
0 commit comments