Documentation
¶
Overview ¶
Package effects is the compiled source for docs/guide/effects-and-server-push.md.
It is a counter shared by every session: a click returns an effect, the store applies it, and a per-session pump emits the result back into every subscribed session.
Index ¶
Constants ¶
const ( EventInc = "count.inc" EventSync = "count.sync" FieldValue = "value" FieldVersion = "version" // SourceApply and SourceWatch are what EffectSource returns. They reach // the wire as the origin source "effect:<name>" on every patch the effect // causes, and they are the value the failure event carries in // live.EffectFailedSourceField. SourceApply = "count.apply" SourceWatch = "count.watch" )
Variables ¶
This section is empty.
Functions ¶
func Reducer ¶
Reducer never changes Value. It returns an effect and learns the result the same way every other session does, which is what "server-authoritative" means concretely and why two tabs cannot disagree.
It is a constructor over the store because an effect carries its own Run, so a reducer that schedules one has to be able to build it. The transition still touches the store not at all.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the shared counter. It is the application's, not the library's.
func (*Store) ApplyEffect ¶
ApplyEffect asks the store to change the shared counter by delta.
cause is the event that asked. It is carried through so the emission the store produces can name it — see Pump.
func (*Store) Pump ¶
Pump delivers snapshots to one session until its context is cancelled.
It runs for the session's whole life, on a goroutine the library owns and waits for at shutdown, which is why it returns on cancellation rather than on a store signal it might never get.
func (*Store) SyncEventFor ¶
SyncEventFor is syncEvent with a contributing claim attached.
Contributing is the one causal field an application sets rather than reads, and it exists because a fan-out through shared state splits the knowledge in two: the library knows the subscription was scheduled at mount, and only this application knows the value came from somebody's click. Naming that click here is what lets an operator holding the patch that changed the number reach the interaction that changed it.
At most 64 identifiers, and they must be events of this session. The Emitter rejects a longer list with an error rather than truncating, so the effect learns about it and the reducer sees a deterministic failure.
func (*Store) WatchEffect ¶
func (s *Store) WatchEffect() live.Effect[live.AnonymousIdentity]
WatchEffect subscribes this session to the store for as long as it lives.
The live.Session[live.AnonymousIdentity] is a parameter of Run and not something to fish out of the context: an effect's identity is an input to what the effect does, and a signature that omitted it would invite the effect to carry addressing information the library already has.