A focused demonstration of the full resource lifecycle in Intent — autoLoad, manual load, reload, invalidation, stale detection, failed state, action-driven invalidation, and the cache options introduced in alpha.8.
- Auto-loaded resource that reaches "ready" on screen start
autoLoad: falseresource that stays "idle" until explicitly loadedresource.reload()— transitions through "pending" back to "ready"resource.invalidate()— marks the resource stale without reloadingresource.load()— manual load forautoLoad: falseresources.invalidates(resource)on an action — marks resources stale on success- Resource "failed" status when a loader throws
- Route-driven resource load context
cache.staleTime— resource transitions to stale automatically after a timeout (alpha.8)cache.deduplicate— concurrent loads share the same in-flight promise (alpha.8)
pnpm install
pnpm dev:resource-lifecycleOpen the local URL printed by Vite. Use the browser console to inspect resource state.
pnpm testTests cover every resource status transition: autoLoad, idle, pending, ready, stale, failed, action-driven invalidation, and the alpha.8 cache options.
- Watch the console log for resource load events and load counts
- Each reload increments the team version counter
- The "Broken save" action demonstrates a failed invalidation
cache.staleTimeon thecachedTeamresource auto-transitions to stale after 50mscache.deduplicateon thededupeReportresource shares concurrent load promises- Test file (
src/ResourceDemo.test.ts) shows the full resource API surface via@intent-framework/testing
// staleTime — auto-stale after a timeout (ms)
const cachedTeam = $.resource("cachedTeam", {
load: async () => loadTeam(),
cache: { staleTime: 50 },
})
// deduplicate — share in-flight promise between concurrent calls
const dedupeReport = $.resource("dedupeReport", {
load: async () => loadReport(),
autoLoad: false,
cache: { deduplicate: true },
})When no cache object is set, existing behavior is preserved (no deduplication, no time-based staleness).