Skill站外收录 @skilllib/skill-2014279385820377090
solidjs-patterns
通过细粒度信号与作用域隔离管理 UI 状态,避免全局忙状态导致的交互死锁。采用派生计算与快照机制确保异步逻辑的稳定性,规范列表更新与事件处理模式,提升 SolidJS 应用响应式的准确性与可维护性。
软件开发 AI 技能
Skills.MD
## Why this skill exists
OpenWork’s UI is SolidJS: it updates via **signals**, not React-style rerenders.
Most “UI stuck” bugs are actually **state coupling** bugs (e.g. one global `busy()` disabling an unrelated action), not rerender issues.
This skill captures the patterns we want to consistently use in OpenWork.
## Core rules
- Prefer **fine-grained signals** over shared global flags.
- Keep async actions **scoped** (each action gets its own `pending` state).
- Derive UI state via `createMemo()` instead of duplicating booleans.
- Avoid mutating arrays/objects stored in signals; always create new values.
## Scoped async actions (recommended)
When an operation can overlap with others (permissions, installs, background refresh), don’t reuse a global `busy()`.
Use a dedicated signal per action:
```ts
const [replying, setReplying] = createSignal(false);
async function respond() {
if (replying()) return;
setReplying(true);
try {
await doTheThing();
} finally {
setReplying(false);
}
}
```
### Why
A single `busy()` boolean creates deadlocks:
- Long-running task sets `busy(true)`
- A permission prompt appears and its buttons are disabled by `busy()`
- The task can’t continue until permission is answered
- The user can’t answer because buttons are disabled
Fix: permission UI must be disabled only by a **permission-specific** pending state.
## Signal snapshots in async handlers
If you read signals inside an async function and you need stable values, snapshot early:
```ts
const request = activePermission();
if (!request) return;
const requestID = request.id;
await respondPermission(requestID, "always");
```
## Derived UI state
Prefer `createMemo()` for computed disabled states:
```ts
const canSend = createMemo(() => prompt().trim().length > 0 && !busy());
```
## Lists
- Use setter callbacks for derived updates:
```ts
setItems((current) => current.filter((x) => x.id !== id));
```
- Don’t mutate `current` in-place.
## Practical checklist (SolidJS UI changes)
- Does any button depend on a global flag that could be true during long-running work?
- Could two async actions overlap and fight over one boolean?
- Is any UI state duplicated (can be derived instead)?
- Do event handlers read signals after an `await` where values might have changed?
## References
- SolidJS: https://www.solidjs.com/docs/latest
- SolidJS signals: https://www.solidjs.com/docs/latest/api#createsignal
- SolidJS memos: https://www.solidjs.com/docs/latest/api#creatememo
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「solidjs-patterns」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次