Skip to content

Commit

Permalink
[expo-updates] Support discriminated unions for JS API method result …
Browse files Browse the repository at this point in the history
…types (expo#23173)
  • Loading branch information
wschurman authored Jun 28, 2023
1 parent ff095da commit b1418cb
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class UpdatesModule(
if (updateDirective != null) {
if (updateDirective is UpdateDirective.RollBackToEmbeddedUpdateDirective) {
updateInfo.putBoolean("isRollBackToEmbedded", true)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
UpdatesStateEvent.CheckCompleteWithRollback()
Expand All @@ -182,6 +183,7 @@ class UpdatesModule(
}

if (updateManifest == null) {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
Expand All @@ -194,6 +196,7 @@ class UpdatesModule(
if (launchedUpdate == null) {
// this shouldn't ever happen, but if we don't have anything to compare
// the new manifest to, let the user know an update is available
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", true)
updateInfo.putString("manifestString", updateManifest.manifest.toString())
promise.resolve(updateInfo)
Expand All @@ -211,6 +214,7 @@ class UpdatesModule(
updateResponse.responseHeaderData?.manifestFilters
)
) {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", true)
updateInfo.putString("manifestString", updateManifest.manifest.toString())
promise.resolve(updateInfo)
Expand All @@ -220,6 +224,7 @@ class UpdatesModule(
)
)
} else {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
Expand Down Expand Up @@ -306,10 +311,14 @@ class UpdatesModule(

if (loaderResult.updateDirective is UpdateDirective.RollBackToEmbeddedUpdateDirective) {
updateInfo.putBoolean("isRollBackToEmbedded", true)
updateInfo.putBoolean("isNew", false)

updatesServiceLocal.stateMachine?.processEvent(
UpdatesStateEvent.DownloadCompleteWithRollback()
)
} else {
updateInfo.putBoolean("isRollBackToEmbedded", false)

if (loaderResult.updateEntity == null) {
updateInfo.putBoolean("isNew", false)
updatesServiceLocal.stateMachine?.processEvent(
Expand Down
5 changes: 3 additions & 2 deletions ios/versioned/sdk49/EXUpdates/EXUpdates/UpdatesModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public final class UpdatesModule: Module {
if result["manifest"] != nil {
promise.resolve([
"isAvailable": true,
"manifest": result["manifest"]
"manifest": result["manifest"],
"isRollBackToEmbedded": false
])
return
}
Expand All @@ -112,7 +113,7 @@ public final class UpdatesModule: Module {
])
return
}
promise.resolve(["isAvailable": false])
promise.resolve(["isAvailable": false, "isRollBackToEmbedded": false])
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/expo-updates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- Support discriminated unions for JS API method result types. ([#23173](https://github.com/expo/expo/pull/23173) by [@wschurman](https://github.com/wschurman))

### 💡 Others

## 0.18.5 — 2023-06-28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class UpdatesModule(
if (updateDirective != null) {
if (updateDirective is UpdateDirective.RollBackToEmbeddedUpdateDirective) {
updateInfo.putBoolean("isRollBackToEmbedded", true)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
UpdatesStateEvent.CheckCompleteWithRollback()
Expand All @@ -182,6 +183,7 @@ class UpdatesModule(
}

if (updateManifest == null) {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
Expand All @@ -194,6 +196,7 @@ class UpdatesModule(
if (launchedUpdate == null) {
// this shouldn't ever happen, but if we don't have anything to compare
// the new manifest to, let the user know an update is available
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", true)
updateInfo.putString("manifestString", updateManifest.manifest.toString())
promise.resolve(updateInfo)
Expand All @@ -211,6 +214,7 @@ class UpdatesModule(
updateResponse.responseHeaderData?.manifestFilters
)
) {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", true)
updateInfo.putString("manifestString", updateManifest.manifest.toString())
promise.resolve(updateInfo)
Expand All @@ -220,6 +224,7 @@ class UpdatesModule(
)
)
} else {
updateInfo.putBoolean("isRollBackToEmbedded", false)
updateInfo.putBoolean("isAvailable", false)
promise.resolve(updateInfo)
updatesServiceLocal.stateMachine?.processEvent(
Expand Down Expand Up @@ -306,10 +311,14 @@ class UpdatesModule(

if (loaderResult.updateDirective is UpdateDirective.RollBackToEmbeddedUpdateDirective) {
updateInfo.putBoolean("isRollBackToEmbedded", true)
updateInfo.putBoolean("isNew", false)

updatesServiceLocal.stateMachine?.processEvent(
UpdatesStateEvent.DownloadCompleteWithRollback()
)
} else {
updateInfo.putBoolean("isRollBackToEmbedded", false)

if (loaderResult.updateEntity == null) {
updateInfo.putBoolean("isNew", false)
updatesServiceLocal.stateMachine?.processEvent(
Expand Down
54 changes: 36 additions & 18 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.

Loading

0 comments on commit b1418cb

Please sign in to comment.