gpui-entity

Manage reactive component state with GPUI Entity read, update, and weak references.

12.5k|757|Updated Jun 13, 2024
One-click install
npx skills add https://github.com/longbridge/gpui-component --skill gpui-entity-longbridge
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gpui-entity
Source: https://github.com/longbridge/gpui-component/tree/main/.claude/skills/gpui-entity
Command: npx skills add https://github.com/longbridge/gpui-component --skill gpui-entity-longbridge

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Entity-based state management enables safe, reactive state across components, reducing boilerplate and preventing unsafe access patterns.

Core Features & Use Cases

  • Read: read(cx) for immutable access to state.
  • Read With: read_with(cx, |state, cx| ...) to access both state and context and return values.
  • Update: update(cx, |state, cx| ...) to mutate state and trigger cx.notify().
  • Weak References: downgrade() into WeakEntity<T> to avoid retain cycles in closures.
  • Lifecycle & Async: automatic disposal when strong references are dropped; support for spawning async tasks via cx.spawn; safe updates with weak references.
  • Use Cases: internal component state, shared state across components, parent-child coordination, and async state management.

Quick Start

Create an entity with cx.new and use the inner context in update closures for safe, reactive state management across components.

Frequently Asked Questions about gpui-entity

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

FAQPage Schema
How do I manage shared reactive state across GPUI components safely?

Manage shared reactive state across GPUI components by creating entities with cx.new and using read, read_with, and update closures. This coordinates synchronized updates and prevents unsafe access patterns in complex UIs.

How do I prevent memory leaks when passing GPUI entity state into async closures?

Prevent memory leaks in GPUI async closures by calling downgrade() to create a WeakEntity<T>. This avoids retain cycles, and you can safely upgrade it later to interact with the state during async tasks spawned via cx.spawn.

What is the best way to trigger UI updates when mutating GPUI entity state?

Trigger UI updates when mutating GPUI entity state by calling update(cx, |state, cx| ...) to modify the data, followed by cx.notify() inside the closure. This ensures the reactive system registers the changes and re-renders appropriately.

When should I use read_with instead of read for accessing GPUI state?

Use read_with(cx, |state, cx| ...) instead of read(cx) when you need to access both the immutable state and the context simultaneously to return a computed value. Use read for simple, direct immutable access to the state.

Does GPUI automatically dispose of entity state when components are removed?

GPUI automatically disposes of entity state when all strong references to that entity are dropped. This lifecycle management prevents stale state persistence and ensures resources are freed when components are unmounted.