Documentation
¶
Overview ¶
Package observable is the framework primitive that lets backing stores (task list, subagent panel, future "notes" / "todos" / ...) publish state changes through a single uniform stream.
A store gains pub/sub by embedding Observable and satisfying Store. The owning container (toolset.ToolState) registers the store once, then any number of subscribers (the agent's event sink, persistence, tests) consume every store's changes through one Subscribe call.
Payload is intentionally untyped at this layer. Each store publishes a domain-typed snapshot ([]todo.Todo, meta.SubagentSnapshot, ...) in Change.Payload; consumers switch on Domain and type-assert. This trades a small amount of compile-time safety at the boundary for the ability to add a new domain without touching the event or agent packages at all.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
Change is a single state-change notification a Store emits to its observers.
Domain identifies the emitting store ("task", "subagent", ...). Op names the verb ("created", "updated", "removed", "phase", ...). ID is the affected entity. Payload carries a domain-typed snapshot the consumer type-asserts on.
type Observable ¶
type Observable struct {
// contains filtered or unexported fields
}
Observable(被觀察者) is the embeddable pub/sub primitive. Zero value is ready to use; safe for concurrent Subscribe and Notify from any goroutine.
func (*Observable) Notify ¶
func (o *Observable) Notify(c Change)
Notify fans c out to every subscriber. Time is filled in when zero. The observer slice is snapshotted under read-lock so a Subscribe racing with Notify is safe and observers receive a stable view.
func (*Observable) Subscribe ¶
func (o *Observable) Subscribe(fn Observer)
Subscribe appends fn to the observer list. nil fns are ignored. (被訂閱)