instacart / instacart/formula

Passing side-effects to rendering layer.

Open
#203 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
155
Forks
16
Avg merge
33m
Merged PRs (30d)
1

Description

## What
Currently, there isn't a well-defined mechanism for passing side-effects to the rendering layer.

### Using `SingleLiveEvent` concept
```kotlin
class SideEffect(val value: Type) {
private var performed: Boolean = false
inline fun performIfNeeded(crossinline action: () -> Unit) {
if (!performed) {
performed = true
action()
}
}
}

renderModel.scrollToTopSideEffect?.performIfNeeded {
recyclerView.scrollToTop()
}
```

The limitation is that there cannot be multiple things trying to handle the same side-effect. The side-effect should always be handled by a single `RenderModel` consumer.

### Using `Relay` concept

Side effect relay type passed through `RenderModel`
```kotlin
data class MyFeatureRenderModel(
val scrollSideEffects: SideEffect
)
```

Rendering layer
```kotlin
class MyFeatureRenderView(): RenderView {
private val recyclerView: RecyclerView = ...
private val scrollEffectHandler = SideEffect.Handler { effect: ScrollPosition ->
recyclerView.scrollTo(effect.position)
}

override fun render = Renderer { model: MyFeatureRenderModel ->
scrollEffectHandler.attach(model.scrollSideEffects)
}
}
```

Potential issues could be a missed side-effect event due to the subscription lifecycle. An effect could happen before the rendering layer is subscribed and can receive it.

Contributor guide

Open the contributing guide

Research direction

Start by locating the RenderModel and rendering-layer entry points, then compare the SingleLiveEvent and Relay concepts described in the issue. Define the subscription lifecycle and single-consumer behavior, including what should happen when an effect occurs before subscription; the issue provides no named files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.