data-state-pattern

Standardize Android repository and UI state handling with DataState/UiState workflows.

51|6|Updated Mar 10, 2019
One-click install
npx skills add https://github.com/AniTrend/anitrend-v2 --skill data-state-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-state-pattern
Source: https://github.com/AniTrend/anitrend-v2/tree/main/.agents/skills/data-state-pattern
Command: npx skills add https://github.com/AniTrend/anitrend-v2 --skill data-state-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves inconsistent and fragile data-flow behavior by providing a clear pattern for how repositories, data sources, interactors, and UI should coordinate loading, error, refresh, and retry using DataState and UiState contracts.

Core Features & Use Cases

  • Defines a DataState/UiState workflow: pairs model streams with loading/error status and standardizes refresh/retry behavior across layers.
  • Guides repository and layering contracts: keeps contracts in the domain layer and concrete implementations in the data layer, including how to structure Types.kt and use-case bridges.
  • Provides offline-first read patterns: explains Room-first non-paged reads and Room-backed paged reads (including relationship collection variants) so UI stays responsive while network refreshes opportunistically.
  • Establishes mutation-specific rules: separates mutation-only flows (toggle/save/delete/rate) from offline-first read guidance to avoid conflating responsibilities.
  • Lists practical implementation red flags and dispatching rules: helps prevent common anti-patterns like raw repository returns, incorrect threading, and improper cache merging.

Quick Start

Implement or review your repository and data-source orchestration using DataState to wrap model Flow(s) with loading/error state, and apply the offline-first non-paged or paged read pattern appropriate to your screen.

Frequently Asked Questions about data-state-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize UiState flows for Android Kotlin repositories?

Standardize UiState flows by wrapping model streams with loading and error status using DataState contracts. This workflow pairs repository returns with UI state handling to coordinate refresh and retry behavior consistently across all architecture layers.

What is the best way to handle offline-first reads with Room and Flow in Android?

Handle offline-first reads using Room-first flow construction for non-paged and paged reads. This keeps the UI responsive with local data while network refreshes happen opportunistically, applying explicit dispatching and mapper persistence rules.

How do I separate mutation flows from offline-first read patterns in Kotlin?

Separate mutation-only flows like toggle, save, delete, and rate from offline-first read guidance to avoid conflating responsibilities. This ensures mutation terminal-state handling remains distinct from query read patterns in your repository orchestration.

Does the DataState pattern work with paged reads and relationship collections in Room?

The DataState pattern supports Room-backed paged reads including relationship collection variants. It pairs model flows with loading and error status, ensuring UI state remains synchronized while applying explicit dispatching and mapper persistence rules.

Why does my Android Kotlin repository return raw Flow instead of DataState?

Returning raw repository flows is a common anti-pattern that breaks UI state coordination. The DataState pattern prevents this by wrapping model flows with loading and error status, establishing clear contracts between domain and data layers.