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

Remove FragmentFlowState activeKeys and visibleKeys. #312

Merged
merged 1 commit into from
Nov 28, 2023
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 @@ -4,6 +4,7 @@
- **Breaking**: Remove `Integration` and `FragmentContract`
- **Breaking**: Remove `Stream`, `StreamBuilder` and `StreamFormula`
- **Breaking**: Rewrite internals of formula action handling to enable inline re-evaluation. Lots of changes, can review them in https://github.com/instacart/formula/pull/301
- **Breaking**: Remove `FragmentFlowState.activeKeys` and `FragmentFlowState.visibleKeys`

## [0.7.1] - June 28, 2022
- **Breaking**: Rename `FragmentBindingBuilder` to `FragmentStoreBuilder`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.instacart.formula.android

/**
* Represents currently [activeKeys] and their [states].
* Represents currently [activeIds] and their [states].
*
* @param activeKeys Fragment contracts that are running their state management.
* @param visibleKeys Fragment contracts that are currently visible to the user.
* @param activeIds Fragment contracts that are running their state management.
* @param visibleIds Fragment contracts that are currently visible to the user.
* @param states Last emitted state of each active [FragmentKey].
*/
data class FragmentFlowState(
Expand All @@ -13,13 +13,5 @@ data class FragmentFlowState(
val features: Map<FragmentId, FeatureEvent> = emptyMap(),
val states: Map<FragmentId, FragmentState> = emptyMap()
) {
@Deprecated("use activeIds")
val activeKeys: List<FragmentKey>
get() = activeIds.map { it.key }

@Deprecated("use visibleIds")
val visibleKeys: List<FragmentKey>
get() = visibleIds.map { it.key }

fun visibleState() = visibleIds.lastOrNull()?.let { states[it] }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class FragmentFlowRenderView(
private val onLifecycleEvent: (FragmentLifecycleEvent) -> Unit,
private val onLifecycleState: (FragmentId, Lifecycle.State) -> Unit,
private val onFragmentViewStateChanged: (FragmentId, isVisible: Boolean) -> Unit
) : RenderView<FragmentFlowState> {
) {

private var fragmentState: FragmentFlowState? = null
private val visibleFragments: LinkedList<Fragment> = LinkedList()
Expand Down Expand Up @@ -119,9 +119,9 @@ internal class FragmentFlowRenderView(
activity.supportFragmentManager.registerFragmentLifecycleCallbacks(callback, false)
}

override val render: Renderer<FragmentFlowState> = Renderer {
Copy link
Collaborator Author

@Laimiux Laimiux Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing Renderer here as the equality check on FragmentFlowState is not necessary. It's also a bit expensive if the FragmentFlowState contains multiple large render models.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this have an effect downstream? Should be transparent, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Individual renderers do an equality check by default, so this extra check does nothing

fragmentState = it
updateVisibleFragments(it)
fun render(state: FragmentFlowState) {
fragmentState = state
updateVisibleFragments(state)
}

fun onBackPressed(): Boolean {
Expand Down
Loading