スキル一覧に戻る
shoheikawano

compose-state-generator

by shoheikawano

3🍴 0📅 2026年1月19日
GitHubで見るManusで実行

SKILL.md


name: compose-state-generator description: | Generate ViewModel, UiState, and state management code for Compose applications. Use when: (1) Creating ViewModel with StateFlow, (2) Designing UiState sealed classes, (3) Implementing state hoisting patterns, (4) Adding one-time events/effects, (5) Connecting ViewModel to Compose screens. Triggers: "viewmodel", "uistate", "stateflow", "state management", "mvi", "one-time event", "side effect", "compose state". context: fork agent: general-purpose user-invocable: true allowed-tools:

  • Read
  • Write
  • Edit
  • Glob
  • Grep
  • Bash

Compose State Generator

Generate idiomatic state management code for Compose following UDF (Unidirectional Data Flow).

Coding Standards

MANDATORY: This skill follows kotlin-compose-standards. All generated code MUST comply with these standards:

  • Trailing comma EXCEPT for Modifier arguments
  • Parameter order: required → Modifier → optional
  • Each Modifier method on its own line
  • New line at end of file

Quick Start

// UiState
sealed interface ProfileUiState {
    data object Loading : ProfileUiState
    data class Success(val user: User) : ProfileUiState
    data class Error(val message: String) : ProfileUiState
}

// ViewModel
class ProfileViewModel(
    private val userRepository: UserRepository,
) : ViewModel() {
    private val _uiState = MutableStateFlow<ProfileUiState>(ProfileUiState.Loading)
    val uiState: StateFlow<ProfileUiState> = _uiState.asStateFlow()
}

Decision Tree

What kind of state?
├─ Screen-level state → ViewModel + UiState
├─ Component-level state → State hoisting or remember
└─ Shared across screens → SharedFlow or StateHolder

Is there async loading?
├─ Yes → Sealed interface (Loading/Success/Error)
└─ No → Data class with fields

Need one-time events?
├─ Yes → Channel + Flow for events
└─ No → Just StateFlow for state

References

FileWhen to Read
viewmodel-patterns.mdViewModel structure, StateFlow setup
uistate-design.mdSealed vs data class, state modeling
multiplatform.mdKMP ViewModel alternatives

Standard ViewModel Template

class FeatureViewModel(
    private val repository: FeatureRepository,
    savedStateHandle: SavedStateHandle,  // Optional: for args
) : ViewModel() {

    private val _uiState = MutableStateFlow(FeatureUiState())
    val uiState: StateFlow<FeatureUiState> = _uiState.asStateFlow()

    private val _events = Channel<FeatureEvent>(Channel.BUFFERED)
    val events = _events.receiveAsFlow()

    init {
        loadData()
    }

    fun onAction(action: FeatureAction) {
        when (action) {
            is FeatureAction.Refresh -> loadData()
            is FeatureAction.ItemClick -> handleItemClick(action.id)
        }
    }

    private fun loadData() {
        viewModelScope.launch {
            _uiState.update { it.copy(isLoading = true) }
            repository.getData()
                .onSuccess { data ->
                    _uiState.update { it.copy(isLoading = false, items = data) }
                }
                .onFailure { error ->
                    _uiState.update { it.copy(isLoading = false, error = error.message) }
                }
        }
    }
}

Output Location

feature/
├── FeatureScreen.kt        # UI
├── FeatureViewModel.kt     # ViewModel
├── FeatureUiState.kt       # State model (or in ViewModel file if small)
└── FeatureAction.kt        # Actions/Events (optional, if complex)

スコア

総合スコア

40/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です