Agent Skillschrisbanes/skills › compose-state-and-effects

compose-state-and-effects

GitHub

指导Jetpack Compose中状态所有权管理、状态提升及副作用(如LaunchedEffect)的生命周期处理,确保UI可预览和测试。

skills/compose-state-and-effects/SKILL.md chrisbanes/skills

Trigger Scenarios

编写或审查Compose组件的状态管理逻辑 处理LaunchedEffect等副作用与状态流收集 进行状态提升或屏幕状态持有者设计

Install

npx skills add chrisbanes/skills --skill compose-state-and-effects -g -y
More Options

Use without installing

npx skills use chrisbanes/skills@compose-state-and-effects

指定 Agent (Claude Code)

npx skills add chrisbanes/skills --skill compose-state-and-effects -a claude-code -g -y

安装 repo 全部 skill

npx skills add chrisbanes/skills --all -g -y

预览 repo 内 skill

npx skills add chrisbanes/skills --list

SKILL.md

Frontmatter
{
    "name": "compose-state-and-effects",
    "description": "Use when writing or reviewing Jetpack Compose state ownership, remember state, state hoisting, screen state holders, LaunchedEffect, DisposableEffect, SideEffect, Flow collection, navigation, snackbar, analytics, or focus requests."
}

Compose state and effects

Core principle

Give every piece of UI state one lowest responsible owner, then run imperative work through the effect whose lifecycle follows that owner. Composition renders; state and effects make rendering change safely.

Procedure

  1. Inventory mutable UI state, app state, event streams, app dependencies, and imperative work in the affected screen or component.
  2. Place each state value at its lowest necessary owner: local UI state, hoisted state, a plain UI state holder, or a screen state holder.
  3. Keep app wiring and business state at the screen boundary; expose plain UI state and explicit callbacks to previewable rendering.
  4. Choose an effect API whose lifecycle matches the work, and key it by the semantic input that should restart or dispose it.
  5. Load the focused reference for every material concern below. Do not use a reference merely because its topic is adjacent.
  6. Route frame-rate reads, cross-phase back-writing, and @ReadOnlyComposable contracts to Compose performance.
  7. Finish when every state value has one owner, every effect has a justified lifecycle and key, and the UI can be previewed and tested without app dependencies.

Topic router

Signal Read
Bare local var, remember { mutableStateOf(...) }, state lists/maps, or reset state Local state
State shared by siblings, UI state holders, ViewModel/component wiring, or previewable screen boundaries State hoisting
LaunchedEffect, DisposableEffect, SideEffect, snapshotFlow, rememberCoroutineScope, rememberUpdatedState, produceState, imperative requestFocus, callbacks, event Flow collection, snackbar, navigation, or analytics Side effects
Focus ownership and keyboard/TV/D-pad behavior Compose focus navigation
Tests or previews for the resulting UI contract Compose UI testing patterns

RED/GREEN agent scenarios

  1. RED keeps a component, collected StateFlow, navigation event, and screen layout in one composable. GREEN leaves wiring and effects at the screen boundary and gives plain rendering immutable state plus callbacks.
  2. Novel case: a query drives repository suggestions while a list state and focus requester coordinate UI behavior. GREEN puts query and suggestions in the screen state holder, but keeps Compose runtime objects in plain UI state.
  3. Counterexample: a one-off expandable badge has one private Boolean. GREEN keeps it local and does not introduce a state holder or an effect.

Version History

  • 2026.8.5 Current 2026-08-16 02:44

Same Skill Collection

skills/compose-animations/SKILL.md
skills/compose-component-design/SKILL.md
skills/compose-focus-navigation/SKILL.md
skills/compose-modifier-and-layout-style/SKILL.md
skills/compose-performance/SKILL.md
skills/compose-recomposition-performance/SKILL.md
skills/compose-side-effects/SKILL.md
skills/compose-slot-api-pattern/SKILL.md
skills/compose-stability-diagnostics/SKILL.md
skills/compose-state-authoring/SKILL.md
skills/compose-state-deferred-reads/SKILL.md
skills/compose-state-hoisting/SKILL.md
skills/compose-state-holder-ui-split/SKILL.md
skills/compose-ui-testing-patterns/SKILL.md
skills/implement-issue/SKILL.md
skills/kotlin-api-design/SKILL.md
skills/kotlin-concurrency-and-flow/SKILL.md
skills/kotlin-control-flow/SKILL.md
skills/kotlin-coroutines-structured-concurrency/SKILL.md
skills/kotlin-flow-state-event-modeling/SKILL.md
skills/kotlin-functions/SKILL.md
skills/kotlin-multiplatform-expect-actual/SKILL.md
skills/kotlin-types-value-class/SKILL.md
skills/run-github-project/SKILL.md
skills/shepherd/SKILL.md
skills/to-plan/SKILL.md
skills/using-chrisbanes-skills/SKILL.md

Metadata

Files
0
Version
2026.8.5
Hash
70a1f6f9
Indexed
2026-08-16 02:44

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 21:56
浙ICP备14020137号-1 $mapa de visitantes$