-
Notifications
You must be signed in to change notification settings - Fork 61
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
Do not create permanentNavModel inside ParentNode. Provide it via constructor to ParentNode #606
Do not create permanentNavModel inside ParentNode. Provide it via constructor to ParentNode #606
Conversation
…structor to ParentNode.
libraries/core/src/main/kotlin/com/bumble/appyx/core/composable/PermanentChild.kt
Outdated
Show resolved
Hide resolved
.value | ||
.find { it.key.navTarget == navTarget } | ||
?.let { childOrCreate(it.key) } | ||
?: throw IllegalStateException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this break the code within StatefulNode1.kt
?
Just so I understand, it's now mandatory to pass in a NavTarget
to the PermanentNavModel
constructor?
Perhaps we should update PermanentNavModel
to throw an IllegalStateException
if there are no NavTarget
's provided? Could we also consider removing the vararg then, as this will definitely lead to issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just ignore if there is no child of the specific type. Otherwise we break functionality where you add a child later. Or maybe provide some optional renderer function.
Just so I understand, it's now mandatory to pass in a NavTarget to the PermanentNavModel constructor?
Why it should be so? We still have add
/addUnique
operations to add nodes later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like if you have a logic of adding a child later at some point it shouldn't be a part of PermanentNavModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps leave it as is for now, and consider changing this behaviour in 2.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CherryPerry my usecase is that I have a PermanentChild that is added immediately (via the constructor) and is only shown once the data is loaded (unfortunately in my usecase the ParentNode is responsible for when to show the PermanentChild based on Output of whether the state is loaded or not)
Without this change, the PermanentChild would not correctly start the business logic when added via the PermanentChild constructor (well actually it can, but it renders the wrong one at the moment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, we are breaking existing use case without providing alternative, when you want to add your permanent child later after some flag is triggered. Now you can via if (myCheck) PermanentChild(NavKey.AddMe)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted it back so we can add keys later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can observe permanentNavModel
in composition to render permanent children
val isAddMeExists = permanentNavModel
.elements.
.mapState(scope, SharingStarted.WhileSubscribed()) { navElements ->
navElements
.find { it.key.navTarget == navTarget } ?: false
}
.collectAsState()
if (isAddMeExists) { PermanentChild() }
otherwise it's difficult to track issues where you forgot to add a key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, can be added to an overloaded PermanentChild while default one fails
Description
Fixes: #604
Using
PermanentChild
composable function, we're delaying adding a child to theParentNode
untilPermanentChild
is invoked. This can lead to many problems as the appropriateNode
will be created only when composable is invoked. Additionally, there's a lot of complexity associated with making sure that we're using only the same instance ofPermanentNavModel
in the cases when one is provided to the constructor.This PR removes internally created
PermanentNavModel
and forces users to provide it from outsideCheck list
CHANGELOG.md
if required.