iii-reactive-backend
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReactive Backend
响应式后端
Comparable to: Convex, Firebase, Supabase, Appwrite
同类产品:Convex、Firebase、Supabase、Appwrite
Key Concepts
核心概念
Use the concepts below when they fit the task. Not every reactive backend needs every trigger or realtime surface shown here.
- State is the "database" — CRUD via
state::set/get/update/delete/list - State triggers fire automatically when any value in a scope changes
- Side effects (notifications, metrics, stream pushes) are wired reactively, not imperatively
- Streams deliver real-time updates to connected clients
当以下概念符合任务需求时使用。并非每个响应式后端都需要用到此处展示的所有触发器或实时交互面。
- State(状态)即“数据库”——通过 实现CRUD操作
state::set/get/update/delete/list - 状态触发器会在某个作用域内的任意值发生变化时自动触发
- 副作用(通知、指标统计、流推送)以响应式方式关联,而非命令式
- 流负责向已连接的客户端传递实时更新
Architecture
架构
text
HTTP CRUD endpoints
→ state::set/update/delete (writes to 'todos' scope)
↓ (automatic state triggers)
→ on-change → stream::send (push to clients)
→ update-metrics → state::update (aggregate counters)
HTTP GET /metrics → reads from 'todo-metrics' scope
WebSocket clients ← stream 'todos-live'text
HTTP CRUD endpoints
→ state::set/update/delete (writes to 'todos' scope)
↓ (automatic state triggers)
→ on-change → stream::send (push to clients)
→ update-metrics → state::update (aggregate counters)
HTTP GET /metrics → reads from 'todo-metrics' scope
WebSocket clients ← stream 'todos-live'iii Primitives Used
使用的iii原语
| Primitive | Purpose |
|---|---|
| Initialize the worker and connect to iii |
| CRUD handlers and reactive side effects |
| Database layer |
| React to any change in a scope |
| Fire-and-forget stream push to clients |
| REST endpoints |
| 原语 | 用途 |
|---|---|
| 初始化Worker并连接到iii引擎 |
| CRUD处理器和响应式副作用 |
| 数据库层 |
| 响应某个作用域内的任意变化 |
| 以“触发即遗忘”的方式向客户端推送流 |
| REST端点 |
Reference Implementation
参考实现
See ../references/reactive-backend.js for the full working example — a real-time todo app with
CRUD endpoints, automatic change broadcasting via streams, and reactive aggregate metrics.
查看 ../references/reactive-backend.js 获取完整可运行示例——一个具备CRUD端点、通过流自动广播变更、以及响应式聚合指标统计的实时待办事项应用。
Common Patterns
常见模式
Code using this pattern commonly includes, when relevant:
- — worker initialization
registerWorker(url, { workerName }) - — CRUD via state module
trigger({ function_id: 'state::set/get', payload: { scope, key, value } }) - — reactive side effects on state change
registerTrigger({ type: 'state', function_id, config: { scope } }) - Event argument destructuring in reactive handlers:
async (event) => { const { new_value, old_value, key } = event } - — push live updates to clients
trigger({ function_id: 'stream::send', payload, action: TriggerAction.Void() }) - — structured logging inside handlers
const logger = new Logger()
当相关时,使用此模式的代码通常包含以下内容:
- —— Worker初始化
registerWorker(url, { workerName }) - —— 通过state模块实现CRUD
trigger({ function_id: 'state::set/get', payload: { scope, key, value } }) - —— 状态变化时触发响应式副作用
registerTrigger({ type: 'state', function_id, config: { scope } }) - 响应式处理器中的事件参数解构:
async (event) => { const { new_value, old_value, key } = event } - —— 向客户端推送实时更新
trigger({ function_id: 'stream::send', payload, action: TriggerAction.Void() }) - —— 处理器内的结构化日志
const logger = new Logger()
Adapting This Pattern
模式适配
Use the adaptations below when they apply to the task.
- State triggers fire on any change in the scope — use the argument (
event,new_value,old_value) to determine what changedkey - Multiple functions can react to the same scope independently (on-change and update-metrics both watch )
todos - Stream clients connect via
ws://host:port/stream/{stream_name}/{group_id} - Keep reactive functions fast — offload heavy work to queues if needed
当以下适配方案适用于任务时使用:
- 状态触发器会在作用域内任意变化时触发——使用参数(
event、new_value、old_value)判断具体变更内容key - 多个函数可以独立响应同一作用域的变化(on-change和update-metrics都监听作用域)
todos - 流客户端通过 连接
ws://host:port/stream/{stream_name}/{group_id} - 保持响应式函数运行快速——若有需要,将繁重工作卸载到队列中
Pattern Boundaries
模式边界
- If the request focuses on registering external/legacy HTTP endpoints via (especially with endpoint lists like
registerFunctionplus iteration), prefer{ path, id }.iii-http-invoked-functions - Stay with when state scopes, state triggers, and live stream updates are the core requirement.
iii-reactive-backend
- 如果需求重点是通过注册外部/遗留HTTP端点(尤其是包含
registerFunction这类端点列表并涉及迭代的场景),请优先使用{ path, id }模式。iii-http-invoked-functions - 当状态作用域、状态触发器和实时流更新是核心需求时,使用模式。
iii-reactive-backend
When to Use
使用场景
- Use this skill when the task is primarily about in the iii engine.
iii-reactive-backend - Triggers when the request directly asks for this pattern or an equivalent implementation.
- 当任务主要围绕iii引擎中的展开时,使用此技能。
iii-reactive-backend - 当请求直接要求实现此模式或等效方案时触发。
Boundaries
边界限制
- Never use this skill as a generic fallback for unrelated tasks.
- You must not apply this skill when a more specific iii skill is a better fit.
- Always verify environment and safety constraints before applying examples from this skill.
- 切勿将此技能作为无关任务的通用 fallback 方案。
- 当有更特定的iii技能更适合时,不得应用此技能。
- 在应用此技能中的示例前,务必验证环境和安全约束。