Skip to content

Commit

Permalink
[expo-updates] Remove useUpdateEvents deprecated API (#27882)
Browse files Browse the repository at this point in the history
# Why

The events are deprecated, and are not as reliable as the state machine
events sent to the new JS API.

# How

- Removed deprecated code
- SImplified and rewrote `UpdatesEmitter.ts`

# Test Plan

- E2E should pass
- Unit tests should pass

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [x] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [x] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
  • Loading branch information
douglowder committed Mar 27, 2024
1 parent a7165e1 commit bbaa412
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 544 deletions.
2 changes: 1 addition & 1 deletion docs/public/static/data/unversioned/expo-updates.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/expo-updates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### 🛠 Breaking changes

- Deprecated `UpdatesController.initialize(Context, Map)` and replaced with `UpdatesController.overrideConfiguration()` method to prevent ANR when overriding the `UpdatesConfiguration` on Android. [#26093](https://github.com/expo/expo/pull/26093) by [@kudo](https://github.com/kudo))
- Remove deprecated APIs: useUpdateEvents(), addListener(), and UpdateEvent type. ([#27882](https://github.com/expo/expo/pull/27882) by [@douglowder](https://github.com/douglowder))

### 🎉 New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Bundle
import android.util.Log
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import expo.modules.kotlin.AppContext
Expand Down Expand Up @@ -95,24 +94,6 @@ class EnabledUpdatesController(
onStartupProcedureFinished()
}

override fun onLegacyJSEvent(event: StartupProcedure.StartupProcedureCallback.LegacyJSEvent) {
when (event) {
is StartupProcedure.StartupProcedureCallback.LegacyJSEvent.Error -> sendLegacyUpdateEventToJS(
UPDATE_ERROR_EVENT,
Arguments.createMap().apply {
putString("message", event.exception.message)
}
)
is StartupProcedure.StartupProcedureCallback.LegacyJSEvent.NoUpdateAvailable -> sendLegacyUpdateEventToJS(UPDATE_NO_UPDATE_AVAILABLE_EVENT, null)
is StartupProcedure.StartupProcedureCallback.LegacyJSEvent.UpdateAvailable -> sendLegacyUpdateEventToJS(
UPDATE_AVAILABLE_EVENT,
Arguments.createMap().apply {
putString("manifestString", event.manifest.toString())
}
)
}
}

override fun onRequestRelaunch(shouldRunReaper: Boolean, callback: LauncherCallback) {
relaunchReactApplication(shouldRunReaper, callback)
}
Expand Down Expand Up @@ -181,10 +162,6 @@ class EnabledUpdatesController(
sendEventToJS(UPDATES_STATE_CHANGE_EVENT_NAME, eventType.type, context.writableMap)
}

private fun sendLegacyUpdateEventToJS(eventType: String, params: WritableMap?) {
sendEventToJS(UPDATES_EVENT_NAME, eventType, params)
}

private fun sendEventToJS(eventName: String, eventType: String, params: WritableMap?) {
UpdatesUtils.sendEventToAppContext(shouldEmitJsEvents, appContext, logger, eventName, eventType, params)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

package expo.modules.updates

internal const val UPDATE_AVAILABLE_EVENT = "updateAvailable"
internal const val UPDATE_NO_UPDATE_AVAILABLE_EVENT = "noUpdateAvailable"
internal const val UPDATE_ERROR_EVENT = "error"

internal const val UPDATES_EVENT_NAME = "Expo.nativeUpdatesEvent"
internal const val UPDATES_STATE_CHANGE_EVENT_NAME = "Expo.nativeUpdatesStateChangeEvent"
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ class UpdatesModule : Module() {
Name("ExpoUpdates")

Events(
UPDATES_EVENT_NAME,
UPDATES_STATE_CHANGE_EVENT_NAME,
UPDATE_AVAILABLE_EVENT,
UPDATE_NO_UPDATE_AVAILABLE_EVENT,
UPDATE_ERROR_EVENT
UPDATES_STATE_CHANGE_EVENT_NAME
)

Constants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import expo.modules.updates.manifest.Update
import expo.modules.updates.selectionpolicy.SelectionPolicy
import expo.modules.updates.statemachine.UpdatesStateEvent
import expo.modules.updates.statemachine.UpdatesStateValue
import org.json.JSONObject
import java.io.File

class StartupProcedure(
Expand All @@ -41,20 +40,6 @@ class StartupProcedure(

interface StartupProcedureCallback {
fun onFinished()

sealed class LegacyJSEvent(private val type: Type) {
private enum class Type {
ERROR,
UPDATE_AVAILABLE,
NO_UPDATE_AVAILABLE
}

class NoUpdateAvailable : LegacyJSEvent(Type.NO_UPDATE_AVAILABLE)
class UpdateAvailable(val manifest: JSONObject) : LegacyJSEvent(Type.UPDATE_AVAILABLE)
class Error(val exception: Exception) : LegacyJSEvent(Type.ERROR)
}
fun onLegacyJSEvent(event: LegacyJSEvent)

fun onRequestRelaunch(shouldRunReaper: Boolean, callback: Launcher.LauncherCallback)
}

Expand Down Expand Up @@ -172,7 +157,6 @@ class StartupProcedure(
}
logger.error("UpdatesController onBackgroundUpdateFinished: Error: ${exception.localizedMessage}", UpdatesErrorCode.Unknown, exception)
remoteLoadStatus = ErrorRecoveryDelegate.RemoteLoadStatus.IDLE
callback.onLegacyJSEvent(StartupProcedureCallback.LegacyJSEvent.Error(exception))

// Since errors can happen through a number of paths, we do these checks
// to make sure the state machine is valid
Expand Down Expand Up @@ -202,15 +186,13 @@ class StartupProcedure(
}
remoteLoadStatus = ErrorRecoveryDelegate.RemoteLoadStatus.NEW_UPDATE_LOADED
logger.info("UpdatesController onBackgroundUpdateFinished: Update available", UpdatesErrorCode.None)
callback.onLegacyJSEvent(StartupProcedureCallback.LegacyJSEvent.UpdateAvailable(update.manifest))
procedureContext.processStateEvent(
UpdatesStateEvent.DownloadCompleteWithUpdate(update.manifest)
)
}
LoaderTask.RemoteUpdateStatus.NO_UPDATE_AVAILABLE -> {
remoteLoadStatus = ErrorRecoveryDelegate.RemoteLoadStatus.IDLE
logger.error("UpdatesController onBackgroundUpdateFinished: No update available", UpdatesErrorCode.NoUpdatesAvailable)
callback.onLegacyJSEvent(StartupProcedureCallback.LegacyJSEvent.NoUpdateAvailable())
// TODO: handle rollbacks properly, but this works for now
if (procedureContext.getCurrentState() == UpdatesStateValue.Downloading) {
procedureContext.processStateEvent(UpdatesStateEvent.DownloadComplete())
Expand Down
39 changes: 0 additions & 39 deletions packages/expo-updates/build/Updates.types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-updates/build/Updates.types.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions packages/expo-updates/build/Updates.types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbaa412

Please sign in to comment.