Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure onSavedInsatnceState super called #180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#168](https://github.com/bumble-tech/appyx/pull/168) – **Updated**: Kotlin coroutines to 1.6.4.
- [#171](https://github.com/bumble-tech/appyx/pull/171) – **Updated**: RIBs to 0.36.1.
- [#174](https://github.com/bumble-tech/appyx/issues/174) – **Fixed**: IntegrationPointExample does not work with "do not keep activities"
- [#180](https://github.com/bumble-tech/appyx/pull/180) – **Added**: Ensure that super.onSaveInstanceState() was called to restore Node's state correctly

## 1.0-alpha09

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ abstract class Node(
private val lifecycleRegistry = LifecycleRegistry(this)
private var wasBuilt = false

val id = buildContext.savedStateMap?.get(NODE_ID_KEY) as String?
?: UUID.randomUUID().toString()
val id = getNodeId(buildContext)

override val requestCodeClientId: String = id

Expand All @@ -95,6 +94,14 @@ abstract class Node(
});
}

private fun getNodeId(buildContext: BuildContext): String {
val state = buildContext.savedStateMap ?: return UUID.randomUUID().toString()

return state[NODE_ID_KEY] as String? ?: error(
"super.onSaveInstanceState() was not called for the node: ${this::class.qualifiedName}"
)
}

protected suspend inline fun <reified T : Node> executeWorkflow(
crossinline action: () -> Unit
): T = withContext(lifecycleScope.coroutineContext) {
Expand Down