Skip to content

@augmentcode/ag-redux-toolkit

Redux + Saga state management for Svelte apps — designed for AI agents. Includes runtime TypeScript source, AI skills, and reference documentation for robust, observable, high-performance state management.

streaming/selector-lifecycle

sub-skill
59 linesSource

>-

Streaming selector lifecycle

Use this skill to decide when a Streaming selector can be invoked, observed, orbound to an alternate stream state source.

Use it only for apps that chose the Streaming Store family. Do not combine theseStreaming lifecycle/setup rules with Svelte-readable Store, Svelte readable, Sveltecomponent, or Svelte selector lifecycle/setup patterns in the same app.

Lifecycle map

Phase/contextCorrect actionWhy
Module setupDefine selectors with streamStore.createSelector(...)Creation stores the selector callback; it does not read stream state yet.
Before init()Avoid direct selector calls and getStreamState()They need the initialized Store-owned Kefir state stream.
After init()Call selectFoo(...args) for a Kefir observableThe Store state stream is available.
Tests/compositionUse selectFoo.select(state, ...args)Pure synchronous selector path, no Store lifecycle needed.
SagasUse yield* selectFoo.effect(...args)Keeps named selector ownership and typed-redux-saga style.
Alternate state streamUse selectFoo.withStore(streamSource)(...args)Binds to a StreamingStore-like source or Kefir state observable.
TeardownStop consumers and call streamStore.dispose() when the owner endsdispose() clears Store-owned stream state and shared runtime resources.

Operational guardrails

  • StreamingStore.getStreamState() intentionally throws before init() and afterdispose(); do not hide that error with fallback empty streams.
  • A direct selector call returns a Kefir observable. Manage observation/teardownusing the consuming app's Kefir subscription pattern.
  • .withStore(...) accepts either a source with getStreamState() or a Kefirobservable of Store state; use it for tests/integration adapters that own theirown state stream.
  • .select(...) and .effect(...) are not streaming subscriptions. They are thepure read and saga read escape hatches shared with the Svelte selector API.

Svelte-readable contrast

  • Streaming selectors do not call Svelte getContext() and do not return SvelteReadable values.
  • Do not apply Svelte component-init readable rules to streaming consumers.
  • If a task is about $selector template values, derived(...) readables, orlifecycle_outside_component, route that separate Svelte app/code path to../../svelte/selector-lifecycle/SKILL.md.
  • Do not make one app use both Streaming selector lifecycle and Svelte selectorlifecycle/setup rules.

Verification cues

  • Examples initialize the StreamingStore before direct selector invocation.
  • Pre-init or post-dispose behavior is either avoided or explicitly tested as thedocumented getStreamState() error.
  • Streaming guidance does not instruct agents to call selectFoo() as a Sveltereadable or to use Svelte $ template auto-subscription.