Scoop API

scoop:scoop.ui:0.1.0

src/view/scene_cache.scoop

Selected production source · src/view/scene_cache.scoop

1package scoop.ui
3import scoop.graphics.Point
5private val sceneRevisionComparison = InputComparison<Long> { before, after -> before == after }
7/** Explicitly reuses stable scene operations; revision covers external, unobserved inputs. */
8public fun cachedScene(content: View, revision: Long = 0L, key: ViewKey = ViewKey.Position): View =
9 element(revision, ::SceneCacheElement, [content], key, Some(sceneRevisionComparison))
11private class SceneCacheElement(private val props: Props<Long>, scope: ComponentScope): Element<
12 Unit
13>(scope) {
14 private var revision = props.value
15 private var epoch = SceneEpoch()
16 public override fun update(): UiInvalidation {
17 if (revision == props.value)
18 return UiInvalidation.None
19 revision = props.value
20 epoch = SceneEpoch()
21 return UiInvalidation.Scene
22 }
23 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
24 Unit
25 > {
26 val child = context.measureChild(0L, constraints)
27 context.placeChild(0L, Point(0.0, 0.0))
28 return LayoutResult(child, Unit)
29 }
30 public override fun scene(context: SceneContext, layout: Unit) {
31 context.presentChildren(None, Some(epoch))
32 }